Back to index

Classes | Functions | Variables
cg_renderer.cpp File Reference
#include "cg_renderer.hpp"
#include "analyze.hpp"
#include "image_files.hpp"
#include "file.hpp"
#include "iterator.hpp"
#include "gui.hpp"
#include "font.hpp"
#include "Freetype/tt_file.hpp"
#include "mac_images.h"

Go to the source code of this file.


struct  cg_image_rep
class  cg_image
struct  cg_cache_image_rep


void cg_set_color (CGContextRef cxt, color col)
int posixStringToFSSpec (FSSpec *fss, CFStringRef posixPath, bool isDirectory)
CGContextRef MyCreateBitmapContext (int pixelsWide, int pixelsHigh)
static CGImageRef xpm_init (url file_name)
cg_renderer_repthe_cg_renderer ()


static hashmap
< basic_character, cg_image
static hashmap< string, cg_imageimages
static hashmap< string, pointernative_fonts
static hashset< stringnative_loaded
int char_clip
static cg_renderer_repthe_renderer = NULL

Function Documentation

void cg_set_color ( CGContextRef  cxt,
color  col 

Definition at line 62 of file cg_renderer.cpp.

  int r, g, b, a;
  get_rgb_color (col, r, g, b, a);
  CGContextSetRGBFillColor(cxt, r/255.0, g/255.0, b/255.0, a/255.0);
  CGContextSetRGBStrokeColor(cxt, r/255.0, g/255.0, b/255.0, a/255.0);

Here is the call graph for this function:

Here is the caller graph for this function:

CGContextRef MyCreateBitmapContext ( int  pixelsWide,
int  pixelsHigh 

Definition at line 430 of file cg_renderer.cpp.

    int bitmapBytesPerRow   = (pixelsWide * 4);
    int bitmapByteCount     = (bitmapBytesPerRow * pixelsHigh);       
    CGColorSpaceRef colorSpace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
    void *bitmapData = malloc( bitmapByteCount );
    if (bitmapData == NULL) {
        //fprintf (stderr, "Memory not allocated!");
        return NULL;
    CGContextRef context = CGBitmapContextCreate (bitmapData, pixelsWide,    pixelsHigh,   8,
                                                  bitmapBytesPerRow, colorSpace, kCGImageAlphaPremultipliedLast);
    if (context == NULL) {
        free (bitmapData);
       // fprintf (stderr, "Context not created!");
        return NULL;
    CGColorSpaceRelease (colorSpace);
    return context;

Here is the caller graph for this function:

int posixStringToFSSpec ( FSSpec *  fss,
CFStringRef  posixPath,
bool  isDirectory 

Definition at line 321 of file cg_renderer.cpp.

       FSRef fsRef;
       FSSpec fileSpec;
       // create a URL from the posix path:
       CFURLRef url = CFURLCreateWithFileSystemPath(kCFAllocatorDefault,posixPath,kCFURLPOSIXPathStyle,isDirectory);
       // check to be sure the URL was created properly:
       if (url == 0) {
              //fprintf(stderr,"Can't get URL");
       // use the CF function to extract an FSRef from the URL:
       if (CFURLGetFSRef(url, &fsRef) == 0){
              //fprintf(stderr,"Can't get FSRef.\n");
       // use Carbon call to get the FSSpec from the FSRef
       if (FSGetCatalogInfo (&fsRef, kFSCatInfoNone, 0, 0, &fileSpec, 0) != noErr) {              
              //fprintf(stderr,"Can't get FSSpec.\n");
       // We have a valid FSSpec! Clean up and return it:
       *fss = fileSpec;
       return 0;

Here is the caller graph for this function:

Definition at line 615 of file cg_renderer.cpp.

       if (!the_renderer) the_renderer= tm_new <cg_renderer_rep> ();
       return the_renderer;
static CGImageRef xpm_init ( url  file_name) [static]

Definition at line 509 of file cg_renderer.cpp.

       tree t= xpm_load (file_name);
       // get main info
       int ok, i=0, j, k, w, h, c, b, x, y;
       string s= as_string (t[0]);
       skip_spaces (s, i);
       ok= read_int (s, i, w);
       skip_spaces (s, i);
       ok= read_int (s, i, h) && ok;
       skip_spaces (s, i);
       ok= read_int (s, i, c) && ok;
       skip_spaces (s, i);
       ok= read_int (s, i, b) && ok;
       if ((!ok) || (N(t)<(c+1)) || (c<=0)) {
         cerr << "File name= " << file_name << "\n";
         FAILED ("invalid xpm");
       // setup colors
       string first_name;
       hashmap<string,color> pmcs;
       for (k=0; k<c; k++) {
              string s   = as_string (t[k+1]);
              string name= "";
              string def = "none";
              if (N(s)<b) i=N(s);
              else { name= s(0,b); i=b; }
              if (k==0) first_name= name;
              skip_spaces (s, i);
              if ((i<N(s)) && (s[i]=='s')) {
                     skip_spaces (s, i);
                     while ((i<N(s)) && (s[i]!=' ') && (s[i]!='\t')) i++;
                     skip_spaces (s, i);
              if ((i<N(s)) && (s[i]=='c')) {
                     skip_spaces (s, i);
                     while ((i<N(s)) && (s[i]!=' ') && (s[i]!='\t')) i++;
                     def= locase_all (s (j, i));
              pmcs(name)= xpm_to_color(def);
       CGContextRef ic = MyCreateBitmapContext(w,h);
       // setup pixmap
       for (y=0; y<h; y++) {
              if (N(t)< (y+c+1)) s= "";
              else s= as_string (t[y+c+1]);
              for (x=0; x<w; x++) {
                     string name;
                     if (N(s)<(b*(x+1))) name= first_name;
                     else name= s (b*x, b*(x+1));
                     color col = pmcs[(pmcs->contains (name) ? name : first_name)];
      cg_set_color (ic, col);
                     CGContextFillRect (ic,CGRectMake(x,y,1,1));
       CGImageRef im = CGBitmapContextCreateImage (ic);
       CGContextRelease (ic);
       return im;

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

int char_clip

Definition at line 483 of file

Definition at line 52 of file cg_renderer.cpp.

Definition at line 53 of file cg_renderer.cpp.

Definition at line 317 of file cg_renderer.cpp.

Definition at line 318 of file cg_renderer.cpp.

cg_renderer_rep* the_renderer = NULL [static]

Definition at line 612 of file cg_renderer.cpp.