Ticket #36: noX11.patch

File noX11.patch, 6.2 KB (added by pulkomandy, 8 years ago)
  • io.c

     
    2424// Fonctions de lecture/ecriture file, gèrent les systèmes big-endian et
    2525// little-endian.
    2626
     27#define _XOPEN_SOURCE 500
     28
    2729#include <SDL_endian.h>
    2830#include <string.h>
    2931#include <sys/stat.h>
     
    5153#include "io.h"
    5254#include "realpath.h"
    5355
     56#include "text.h"
     57
    5458// Lit un octet
    5559// Renvoie -1 si OK, 0 en cas d'erreur
    5660int Read_byte(FILE *file, byte *dest)
     
    389393  closedir(current_directory);
    390394}
    391395
     396void For_each_font_in_tree(const char * directory_name)
     397{
     398  // Pour scan de répertoire
     399  DIR*  current_directory; //Répertoire courant
     400  struct dirent* entry; // Structure de lecture des éléments
     401  char full_filename[MAX_PATH_CHARACTERS];
     402  int filename_position;
     403  strcpy(full_filename, directory_name);
     404  current_directory=opendir(directory_name);
     405  if(current_directory == NULL) return;        // Répertoire invalide ...
     406  filename_position = strlen(full_filename);
     407#if defined(__AROS__)
     408  if (filename_position==0 || (strcmp(full_filename+filename_position-1,PATH_SEPARATOR) && strcmp(full_filename+filename_position-1,":")))
     409#else
     410  if (filename_position==0 || strcmp(full_filename+filename_position-1,PATH_SEPARATOR))
     411#endif
     412  {
     413    strcat(full_filename, PATH_SEPARATOR);
     414    filename_position = strlen(full_filename);
     415  }
     416  while ((entry=readdir(current_directory)))
     417  {
     418    struct stat Infos_enreg;
     419    strcpy(&full_filename[filename_position], entry->d_name);
     420    stat(full_filename,&Infos_enreg);
     421    if (S_ISREG(Infos_enreg.st_mode))
     422    {
     423      Add_font(full_filename);
     424    }else if (S_ISDIR(Infos_enreg.st_mode))
     425    {
     426      if (strcmp(entry->d_name,".") != 0 && strcmp(entry->d_name,"..") != 0)
     427        For_each_font_in_tree(full_filename);
     428    }
     429  }
     430  closedir(current_directory);
     431}
     432
    392433/// Scans a directory, calls Callback for each file or directory in it,
    393434void For_each_directory_entry(const char * directory_name, void Callback(const char *, byte is_file, byte is_directory, byte is_hidden))
    394435{
     
    453494
    454495byte Create_lock_file(const char *file_directory)
    455496{
    456   #if defined (__amigaos__)||(__AROS__)||(__ANDROID__)
     497  #if defined (__amigaos__)||(__AROS__)
    457498    #warning "Missing code for your platform, please check and correct!"
    458499  #else
    459500  char lock_filename[MAX_PATH_CHARACTERS];
    460501 
    461 #ifdef GCWZERO
    462   strcpy(lock_filename,"/media/home/.grafx2/");
    463 #else
    464502  strcpy(lock_filename,file_directory);
    465 #endif
    466503  strcat(lock_filename,"gfx2.lck");
    467504 
    468505  #ifdef __WIN32__
  • text.c

     
    22*/
    33/*  Grafx2 - The Ultimate 256-color bitmap paint program
    44
    5     Copyright 2014 Sergii Pylypenko
    65    Copyright 2011 Pawel Góralski
    76    Copyright 2008 Yves Rizoud
    87    Copyright 2008 Franck Charlet
     
    3938#endif
    4039
    4140#if defined(__CAANOO__) || defined(__WIZ__) || defined(__GP2X__)
    42 // No fontconfig
     41// No X11
    4342#elif defined(__linux__)
    44   #include <fontconfig/fontconfig.h>
     43  #include <X11/Xlib.h>
    4544#endif
    4645#endif
    4746
     
    327326    #endif
    328327
    329328  #elif defined(__CAANOO__) || defined(__WIZ__) || defined(__GP2X__)
    330   // No fontconfig : Only use fonts from Grafx2
     329  // No X11 : Only use fonts from Grafx2
    331330  #elif defined(__linux__)
    332331    #ifndef NOTTF
    333        #define USE_FC
     332//       #define USE_XLIB
    334333   
    335        #ifdef USE_FC
     334       #ifdef USE_XLIB
     335/*
     336        the following X calls lock Grafx2 into X Windows.
     337        Grafx2 will not run in console mode outside X.
     338        Also this does not find the newer "built-ins".
     339*/
    336340       {
    337         FcStrList* dirs;
    338         dirs = FcConfigGetFontDirs(NULL);
    339         char* fdir = FcStrListNext(dirs);
    340         while(fdir != NULL)
    341         {
    342             For_each_file(fdir,Add_font);
    343             fdir = FcStrListNext(dirs);
    344         }
     341        int i,number;
     342        Display* dpy = XOpenDisplay(NULL);
     343        char** font_path_list = XGetFontPath(dpy,&number);
     344        XCloseDisplay(dpy);
    345345
    346         FcStrListDone(dirs);
     346        for(i=0;i<number;i++)
     347            For_each_file(*(font_path_list+i),Add_font);
     348
     349        XFreeFontPath(font_path_list);
    347350       }
     351       #else
     352/*
     353        on Linux SDL does NOT need X Windows to use TTF,
     354        but there are so many places usable fonts can be
     355        we need to search by hand "one step up" of known
     356        possibilities.
     357*/
     358       {
     359        int i,number;
     360        char *font_path_list[7] = {
     361           "/usr/share/fonts",                  // mostly under here
     362           "/usr/local/share/fonts",            // maybe here too
     363           "/usr/local/share/lib/X11/fonts",    // we check the following on other/older systems
     364           "/usr/openwin/lib/X11/fonts",
     365           "/usr/dt/config/xfonts"
     366        };
     367        number = 7;
     368
     369        font_path_list[5] = getenv("HOME");
     370        strcat(font_path_list[5], "/.fonts");     // traditionally, current users can also have fonts
     371
     372        font_path_list[6] = getenv("HOME");
     373        strcat(font_path_list[6], "/.local/share/fonts"); // new systems are beginning to use this
     374
     375        for(i=0;i<number;i++)
     376            For_each_font_in_tree(*(font_path_list+i));
     377
     378       }
     379
    348380       #endif
     381
    349382    #endif
    350383  #elif defined(__amigaos4__) || defined(__amigaos__)
    351384    #ifndef NOTTF
     
    419452  bg_color.unused=fg_color.unused=255;
    420453 
    421454  // Text rendering: creates a 8bit surface with its dedicated palette
    422   #ifdef __ANDROID__
    423455  if (antialias)
    424     text_surface=TTF_RenderUTF8_Shaded(font, str, fg_color, bg_color );
    425   else
    426     text_surface=TTF_RenderUTF8_Solid(font, str, fg_color);
    427   #else
    428   if (antialias)
    429456    text_surface=TTF_RenderText_Shaded(font, str, fg_color, bg_color );
    430457  else
    431458    text_surface=TTF_RenderText_Solid(font, str, fg_color);
    432   #endif
    433459  if (!text_surface)
    434460  {
    435461    TTF_CloseFont(font);
     
    534560  font_surface=IMG_Load(Font_name(font_number));
    535561  if (!font_surface)
    536562  {
    537         char buffer[256];
    538         strcpy(buffer, "Error loading font.\n");
    539         strcat(buffer,IMG_GetError());
    540     Verbose_message("Warning",buffer);
    541         // TODO this leaves a non-erased cursor when the window closes.
     563    Verbose_message("Warning","Error loading font.\nThe file may be corrupt.");
    542564    return NULL;
    543565  }
    544566  // Font is 24bit: Perform a color reduction