diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/cd.def | 13 | ||||
-rw-r--r-- | src/cd_util.c | 95 | ||||
-rw-r--r-- | src/cdgdk.def | 45 | ||||
-rw-r--r-- | src/cdgl.mak | 14 | ||||
-rw-r--r-- | src/drv/cdgl.c | 192 | ||||
-rw-r--r-- | src/ftgl/FTContour.cpp | 3 | ||||
-rw-r--r-- | src/sim/cd_truetype.c | 77 |
7 files changed, 282 insertions, 157 deletions
@@ -192,11 +192,6 @@ EXPORTS wdVectorText wdMultiLineVectorText wdGetVectorTextBounds - - cdwCreateCanvas - cdwInitTable - cdwKillCanvas - cdwRestoreDC cdLineStyleDashes cdRegionBox @@ -226,6 +221,8 @@ EXPORTS cdCanvasGetArcBox cdCanvasGetArcStartEnd cdfCanvasGetArcStartEnd + cdStrEqualNoCasePartial + cdGetFontFileName wdCanvasLineWidth wdCanvasMarkSize @@ -409,4 +406,8 @@ EXPORTS cdfSimSector cdfSimChord cdSimChord -
\ No newline at end of file + + cdwCreateCanvas + cdwInitTable + cdwKillCanvas + cdwRestoreDC diff --git a/src/cd_util.c b/src/cd_util.c index b278dfc..20e9a46 100644 --- a/src/cd_util.c +++ b/src/cd_util.c @@ -308,6 +308,8 @@ void cdRotatePointY(cdCanvas* canvas, int x, int y, int cx, int cy, int *ry, dou *ry = *ry + cy; } +/* Copied from IUP3 */ + int cdStrEqualNoCase(const char* str1, const char* str2) { int i = 0; @@ -321,6 +323,20 @@ int cdStrEqualNoCase(const char* str1, const char* str2) return 0; } +int cdStrEqualNoCasePartial(const char* str1, const char* str2) +{ + int i = 0; + if (str1 == str2) return 1; + if (!str1 || !str2 || tolower(*str1) != tolower(*str2)) return 0; + + while (str1[i] && str2[i] && tolower(str1[i])==tolower(str2[i])) + i++; + if (str1[i] == str2[i]) return 1; + if (str2[i] == 0) return 1; + + return 0; +} + /* Copied from IUP3, simply ignore line breaks other than '\n' for CD */ int cdStrLineCount(const char* str) @@ -398,3 +414,82 @@ void cdSetPaperSize(int size, double *w_pt, double *h_pt) *h_pt = (double)paper[size].h_pt; } +#ifdef WIN32 +#include <windows.h> +static int sReadStringKey(HKEY base_key, char* key_name, char* value_name, char* value) +{ + HKEY key; + DWORD max_size = 512; + + if (RegOpenKeyEx(base_key, key_name, 0, KEY_READ, &key) != ERROR_SUCCESS) + return 0; + + if (RegQueryValueEx(key, value_name, NULL, NULL, (LPBYTE)value, &max_size) != ERROR_SUCCESS) + { + RegCloseKey(key); + return 0; + } + + RegCloseKey(key); + return 1; +} + +static char* sGetFontDir(void) +{ + static char font_dir[512]; + if (!sReadStringKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Fonts", font_dir)) + return ""; + else + { + int i, size = (int)strlen(font_dir); + for(i = 0; i < size; i++) + { + if (font_dir[i] == '\\') + font_dir[i] = '/'; + } + return font_dir; + } +} +#endif + +int cdGetFontFileName(const char* font, char* filename) +{ + FILE *file; + + /* current directory */ + sprintf(filename, "%s.ttf", font); + file = fopen(filename, "r"); + + if (file) + fclose(file); + else + { + /* CD environment */ + char* env = getenv("CDDIR"); + if (env) + { + sprintf(filename, "%s/%s.ttf", env, font); + file = fopen(filename, "r"); + } + + if (file) + fclose(file); + else + { +#ifdef WIN32 + /* Windows Font folder */ + sprintf(filename, "%s/%s.ttf", sGetFontDir(), font); + file = fopen(filename, "r"); + + if (file) + fclose(file); + else + return 0; +#else + return 0; +#endif + } + } + + return 1; +} diff --git a/src/cdgdk.def b/src/cdgdk.def index c240a3d..dba219a 100644 --- a/src/cdgdk.def +++ b/src/cdgdk.def @@ -17,15 +17,6 @@ EXPORTS cdContextDebug cdContextSVG - cdContextCairoImage - cdContextCairoImageRGB - cdContextCairoPS - cdContextCairoNativeWindow - cdContextCairoDBuffer - cdContextCairoSVG - cdContextCairoPDF - cdInitContextPlus - cdRedImage cdGreenImage cdBlueImage @@ -201,7 +192,7 @@ EXPORTS wdVectorText wdMultiLineVectorText wdGetVectorTextBounds - + cdLineStyleDashes cdRegionBox wdRegionBox @@ -223,6 +214,15 @@ EXPORTS cdGetFontSizePixels cdGetFontSizePoints cdStrEqualNoCase + cdSetPaperSize + cdCanvasGetArcPath + cdfCanvasGetArcPath + cdCanvasGetArcPathF + cdCanvasGetArcBox + cdCanvasGetArcStartEnd + cdfCanvasGetArcStartEnd + cdStrEqualNoCasePartial + cdGetFontFileName wdCanvasLineWidth wdCanvasMarkSize @@ -364,6 +364,7 @@ EXPORTS cdCanvasVectorTextDirection cdCanvasVectorTextSize cdCanvasVertex + cdCanvasPathSet cdfCanvasGetClipArea cdfCanvasArc @@ -390,6 +391,28 @@ EXPORTS cdCanvasSetBackground cdCanvasTransformPoint cdfCanvasTransformPoint - + cdRound + cdStrDup + cdInitContextPlusList cdGetContextPlus + + cdfSimPolyPath + cdSimArc + cdSimPolyPath + cdfRotatePoint + cdSimSector + cdfSimArc + cdfSimSector + cdfSimChord + cdSimChord + + cdContextCairoImage + cdContextCairoImageRGB + cdContextCairoPS + cdContextCairoNativeWindow + cdContextCairoDBuffer + cdContextCairoSVG + cdContextCairoPDF + cdInitContextPlus + diff --git a/src/cdgl.mak b/src/cdgl.mak index 21a9b88..7b5f8e6 100644 --- a/src/cdgl.mak +++ b/src/cdgl.mak @@ -8,13 +8,25 @@ SRC = drv/cdgl.c INCLUDES = . sim ftgl freetype2 LIBS = ftgl ifeq ($(findstring Win, $(TEC_SYSNAME)), ) - LIBS += iconv +# LIBS += iconv endif USE_OPENGL = YES USE_CD = YES CD = .. +ifneq ($(findstring AIX, $(TEC_UNAME)), ) + NO_FONTCONFIG = Yes +endif + +ifneq ($(findstring IRIX, $(TEC_UNAME)), ) + NO_FONTCONFIG = Yes +endif + +ifneq ($(findstring SunOS, $(TEC_UNAME)), ) + NO_FONTCONFIG = Yes +endif + ifneq ($(findstring MacOS, $(TEC_UNAME)), ) ifeq ($(TEC_SYSMINOR), 5) #Darwin9 Only - OpenGL bug fix for Fink, when the message bellow appears diff --git a/src/drv/cdgl.c b/src/drv/cdgl.c index 94b1367..4357e5a 100644 --- a/src/drv/cdgl.c +++ b/src/drv/cdgl.c @@ -57,7 +57,6 @@ struct _cdCtxCanvas cdCanvas* canvas; FTGLfont *font; - char fontfilename[10240]; char* glLastConvertUTF8; @@ -71,7 +70,7 @@ struct _cdCtxCanvas /******************************************************/ -static char* cdglStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, unsigned int len) +static char* cdglStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, int len) { if (ctxcanvas->glLastConvertUTF8) free(ctxcanvas->glLastConvertUTF8); @@ -102,7 +101,8 @@ static char* cdglStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, unsig /* Based on http://www.lemoda.net/c/iconv-example/iconv-example.html Last access: June 15th, 2010. */ iconv_t cd; - unsigned int utf8len = len*2; + size_t ulen = (size_t)len; + size_t utf8len = ulen*2; char* utf8 = calloc(utf8len, 1); cd = iconv_open("UTF-8", "ISO-8859-1"); @@ -110,7 +110,7 @@ static char* cdglStrConvertToUTF8(cdCtxCanvas *ctxcanvas, const char* str, unsig return (char*)str; ctxcanvas->glLastConvertUTF8 = utf8; - iconv(cd, (char**)&str, &len, &utf8, &utf8len); + iconv(cd, (char**)&str, &ulen, &utf8, &utf8len); iconv_close(cd); } @@ -347,6 +347,7 @@ static LONG cdglWGetNextNameValue(HKEY key, LPCTSTR subkey, LPTSTR szName, LPTST RegCloseKey(hkey); hkey = NULL; + dwIndex = 0; return ERROR_SUCCESS; } @@ -382,43 +383,78 @@ static LONG cdglWGetNextNameValue(HKEY key, LPCTSTR subkey, LPTSTR szName, LPTST return retval; } -static int cdglWGetFontFileName(LPCTSTR lpszFontName, int bold, int italic, char* fileName) +static int sReadStringKey(HKEY base_key, char* key_name, char* value_name, char* value) +{ + HKEY key; + DWORD max_size = 512; + + if (RegOpenKeyEx(base_key, key_name, 0, KEY_READ, &key) != ERROR_SUCCESS) + return 0; + + if (RegQueryValueEx(key, value_name, NULL, NULL, (LPBYTE)value, &max_size) != ERROR_SUCCESS) + { + RegCloseKey(key); + return 0; + } + + RegCloseKey(key); + return 1; +} + +static char* sGetFontDir(void) +{ + static char font_dir[1024]; + if (!sReadStringKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Fonts", font_dir)) + return ""; + else + return font_dir; +} + +static int sGetFontFileName(const char *font_name, int bold, int italic, char* fileName) { TCHAR szName[2 * MAX_PATH]; TCHAR szData[2 * MAX_PATH]; - TCHAR displayName[2 * MAX_PATH]; LPCTSTR strFont = "Software\\Microsoft\\Windows NT\\CurrentVersion\\Fonts"; char localFontName[256]; int bResult = 0; - sprintf(localFontName, "%s", lpszFontName); + if (cdStrEqualNoCase(font_name, "Courier") || cdStrEqualNoCase(font_name, "Monospace")) + font_name = "Courier New"; + else if (cdStrEqualNoCase(font_name, "Times") || cdStrEqualNoCase(font_name, "Serif")) + font_name = "Times New Roman"; + else if (cdStrEqualNoCase(font_name, "Helvetica") || cdStrEqualNoCase(font_name, "Sans")) + font_name = "Arial"; + + strcpy(localFontName, font_name); - if( bold ) + if (bold) strcat(localFontName, " Bold"); - if( italic ) + if (italic) strcat(localFontName, " Italic"); while (cdglWGetNextNameValue(HKEY_LOCAL_MACHINE, strFont, szName, szData) == ERROR_SUCCESS) { - if (_strnicmp(localFontName, szName, strlen(localFontName)) == 0) + if (cdStrEqualNoCasePartial(szName, localFontName)) { - sprintf(displayName, "%s", szName); - sprintf(fileName, "%s", szData); + //"%s/%s.ttf" + sprintf(fileName, "%s\\%s", sGetFontDir(), szData); bResult = 1; break; } - strFont = ""; + strFont = NULL; } + /* close the registry key */ cdglWGetNextNameValue(HKEY_LOCAL_MACHINE, NULL, NULL, NULL); return bResult; } #else +#ifndef NO_FONTCONFIG #include <fontconfig/fontconfig.h> -static int cdglXGetFontFileName(const char *font_name, int bold, int italic, char* fileName) +static int sGetFontFileName(const char *font_name, int bold, int italic, char* fileName) { char styles[4][20]; int style_size; @@ -427,30 +463,37 @@ static int cdglXGetFontFileName(const char *font_name, int bold, int italic, cha FcPattern *pat; int bResult = 0; + if (cdStrEqualNoCase(font_name, "Courier") || cdStrEqualNoCase(font_name, "Courier New") || cdStrEqualNoCase(font_name, "Monospace")) + font_name = "freemono"; + else if (cdStrEqualNoCase(font_name, "Times") || cdStrEqualNoCase(font_name, "Times New Roman")|| cdStrEqualNoCase(font_name, "Serif")) + font_name = "freeserif"; + else if (cdStrEqualNoCase(font_name, "Helvetica") || cdStrEqualNoCase(font_name, "Arial") || cdStrEqualNoCase(font_name, "Sans")) + font_name = "freesans"; + if( bold && italic ) { - sprintf(styles[0], "%s", "BoldItalic"); - sprintf(styles[1], "%s", "Bold Italic"); - sprintf(styles[2], "%s", "Bold Oblique"); - sprintf(styles[3], "%s", "BoldOblique"); + strcpy(styles[0], "BoldItalic"); + strcpy(styles[1], "Bold Italic"); + strcpy(styles[2], "Bold Oblique"); + strcpy(styles[3], "BoldOblique"); style_size = 4; } else if( bold ) { - sprintf(styles[0], "%s", "Bold"); + strcpy(styles[0], "Bold"); style_size = 1; } else if( italic ) { - sprintf(styles[0], "%s", "Italic"); - sprintf(styles[1], "%s", "Oblique"); + strcpy(styles[0], "Italic"); + strcpy(styles[1], "Oblique"); style_size = 2; } else { - sprintf(styles[0], "%s", "Regular"); - sprintf(styles[1], "%s", "Normal"); - sprintf(styles[2], "%s", "Medium"); + strcpy(styles[0], "Regular"); + strcpy(styles[1], "Normal"); + strcpy(styles[2], "Medium"); style_size = 3; } @@ -474,22 +517,21 @@ static int cdglXGetFontFileName(const char *font_name, int bold, int italic, cha FcPatternGetString(fs->fonts[j], FC_STYLE, 0, &style ); FcPatternGetString(fs->fonts[j], FC_FAMILY, 0, &family ); - if (strncasecmp(font_name, (char*)family, strlen(font_name)) == 0) + if (cdStrEqualNoCasePartial((char*)family, font_name)) { /* check if the font is of the correct type. */ for(s = 0; s < style_size; s++ ) { - if (strcasecmp(styles[s], (char*)style ) == 0) + if (cdStrEqualNoCase(styles[s], (char*)style)) { - sprintf(fileName, "%s", (char*)file); + strcpy(fileName, (char*)file); bResult = 1; FcFontSetDestroy (fs); - return bResult; } /* set value to use if no more correct font of same family is found. */ - sprintf(fileName, "%s", (char*)file); + strcpy(fileName, (char*)file); bResult = 1; } } @@ -499,12 +541,22 @@ static int cdglXGetFontFileName(const char *font_name, int bold, int italic, cha return bResult; } +#else +static int sGetFontFileName(const char *font_name, int bold, int italic, char* fileName) +{ + (void)font_name; + (void)bold; + (void)italic; + (void)fileName; + return 0; +} +#endif #endif static int cdfont(cdCtxCanvas *ctxcanvas, const char *typeface, int style, int size) { int is_italic = 0, is_bold = 0; /* default is CD_PLAIN */ - char strFontFileName[256]; + char strFontFileName[10240]; if (style & CD_BOLD) is_bold = 1; @@ -512,34 +564,44 @@ static int cdfont(cdCtxCanvas *ctxcanvas, const char *typeface, int style, int s if (style & CD_ITALIC) is_italic = 1; -#ifdef WIN32 - if (cdStrEqualNoCase(typeface, "Courier") || cdStrEqualNoCase(typeface, "Monospace")) - typeface = "Courier New"; - else if (cdStrEqualNoCase(typeface, "Times") || cdStrEqualNoCase(typeface, "Serif")) - typeface = "Times New Roman"; - else if (cdStrEqualNoCase(typeface, "Helvetica") || cdStrEqualNoCase(typeface, "Sans")) - typeface = "Arial"; - - if(!cdglWGetFontFileName(typeface, is_bold, is_italic, strFontFileName)) - return 0; - - sprintf(ctxcanvas->fontfilename, "%s\\fonts\\%s", getenv("windir"), strFontFileName); -#else - if (cdStrEqualNoCase(typeface, "Courier") || cdStrEqualNoCase(typeface, "Courier New") || cdStrEqualNoCase(typeface, "Monospace")) - typeface = "freemono"; - else if (cdStrEqualNoCase(typeface, "Times") || cdStrEqualNoCase(typeface, "Times New Roman")|| cdStrEqualNoCase(typeface, "Serif")) - typeface = "freeserif"; - else if (cdStrEqualNoCase(typeface, "Helvetica") || cdStrEqualNoCase(typeface, "Arial") || cdStrEqualNoCase(typeface, "Sans")) - typeface = "freesans"; - - if(!cdglXGetFontFileName(typeface, is_bold, is_italic, strFontFileName)) - return 0; - - sprintf(ctxcanvas->fontfilename, "%s", strFontFileName); -#endif + /* search for the font in the system */ + if (!sGetFontFileName(typeface, is_bold, is_italic, strFontFileName)) + { + /* try typeface as a file title, compose to get a filename */ + if (!cdGetFontFileName(typeface, strFontFileName)) + { + /* try the same configuration of the simulation driver */ + static char * cd_ttf_font_style[4] = { + "", + "bd", + "i", + "bi"}; + char* face = NULL; + + /* check for the pre-defined names */ + if (cdStrEqualNoCase(typeface, "System")) + face = "cour"; + else if (cdStrEqualNoCase(typeface, "Courier")) + face = "cour"; + else if (cdStrEqualNoCase(typeface, "Times")) + face = "times"; + else if (cdStrEqualNoCase(typeface, "Helvetica")) + face = "arial"; + + if (face) + { + /* create a shortname for the file title */ + char shorname[100]; + sprintf(shorname, "%s%s", face, cd_ttf_font_style[style&3]); + if (!cdGetFontFileName(shorname, strFontFileName)) + strcpy(strFontFileName, typeface); /* try the typeface as file name */ + } + else + strcpy(strFontFileName, typeface); /* try the typeface as file name */ + } + } - ctxcanvas->font = ftglCreateBufferFont(ctxcanvas->fontfilename); - + ctxcanvas->font = ftglCreateBufferFont(strFontFileName); if (!ctxcanvas->font) return 0; @@ -650,9 +712,9 @@ static void cdbox(cdCtxCanvas *ctxcanvas, int xmin, int xmax, int ymin, int ymax static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, int len) { - int dir = -1, stipple = 0; + int stipple = 0; float bounds[6]; - int w, h, desc; + int w, h, descent, baseline; double x_origin = x; double y_origin = y; @@ -662,9 +724,10 @@ static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, i s = cdglStrConvertToUTF8(ctxcanvas, s, len); ftglGetFontBBox(ctxcanvas->font, s, len, bounds); - desc = (int)ftglGetFontDescender(ctxcanvas->font); + descent = (int)ftglGetFontDescender(ctxcanvas->font); w = (int)ceil(bounds[3] - bounds[0]); h = (int)ceil(bounds[4] - bounds[1]); + baseline = (int)ftglGetFontLineHeight(ctxcanvas->font) - (int)ftglGetFontAscender(ctxcanvas->font); switch (ctxcanvas->canvas->text_alignment) { @@ -688,9 +751,6 @@ static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, i break; } - if (ctxcanvas->canvas->invert_yaxis) - dir = 1; - switch (ctxcanvas->canvas->text_alignment) { case CD_BASE_LEFT: @@ -701,17 +761,17 @@ static void cdftext(cdCtxCanvas *ctxcanvas, double x, double y, const char *s, i case CD_SOUTH_EAST: case CD_SOUTH_WEST: case CD_SOUTH: - y = y + dir * desc; + y = y - descent; break; case CD_NORTH_EAST: case CD_NORTH: case CD_NORTH_WEST: - y = y + dir * (h + desc); + y = y - h/2 - baseline; break; case CD_CENTER: case CD_EAST: case CD_WEST: - y = y + dir * (h / 2); + y = y - baseline; break; } diff --git a/src/ftgl/FTContour.cpp b/src/ftgl/FTContour.cpp index cef1f3b..6b92812 100644 --- a/src/ftgl/FTContour.cpp +++ b/src/ftgl/FTContour.cpp @@ -33,6 +33,9 @@ static const unsigned int BEZIER_STEPS = 5; +#ifndef M_PI +#define M_PI 3.14159265358979323846 +#endif void FTContour::AddPoint(FTPoint point) { diff --git a/src/sim/cd_truetype.c b/src/sim/cd_truetype.c index e7dad41..9fda0e3 100644 --- a/src/sim/cd_truetype.c +++ b/src/sim/cd_truetype.c @@ -9,91 +9,22 @@ #include <memory.h> #include <stdio.h> +#include "cd.h" +#include "cd_private.h" #include "cd_truetype.h" /******************************************* Inicializa o Rasterizador ********************************************/ -#ifdef WIN32 -#include <windows.h> -static int ReadStringKey(HKEY base_key, char* key_name, char* value_name, char* value) -{ - HKEY key; - DWORD max_size = 512; - - if (RegOpenKeyEx(base_key, key_name, 0, KEY_READ, &key) != ERROR_SUCCESS) - return 0; - - if (RegQueryValueEx(key, value_name, NULL, NULL, (LPBYTE)value, &max_size) != ERROR_SUCCESS) - { - RegCloseKey(key); - return 0; - } - - RegCloseKey(key); - return 1; -} - -char* GetFontDir(void) -{ - static char font_dir[512]; - if (!ReadStringKey(HKEY_CURRENT_USER, "Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders", "Fonts", font_dir)) - return ""; - else - { - int i, size = (int)strlen(font_dir); - for(i = 0; i < size; i++) - { - if (font_dir[i] == '\\') - font_dir[i] = '/'; - } - return font_dir; - } -} -#endif - int cdTT_load(cdTT_Text * tt_text, const char *font, int size, double xres, double yres) { char filename[10240]; - FILE *file; /* usado apenas para procurar pelo arquivo */ FT_Error error; FT_Face face; - /* abre arq. no dir. corrente */ - sprintf(filename, "%s.ttf", font); - file = fopen(filename, "r"); - - if (file) - fclose(file); - else - { - /* se nao conseguiu, abre arq. no dir. do cd, */ - char* env = getenv("CDDIR"); - if (env) - { - sprintf(filename, "%s/%s.ttf", env, font); - file = fopen(filename, "r"); - } - - if (file) - fclose(file); - else - { -#ifdef WIN32 - /* no caso do Windows procura no seu diretorio de fontes. */ - sprintf(filename, "%s/%s.ttf", GetFontDir(), font); - file = fopen(filename, "r"); - - if (file) - fclose(file); - else - return 0; -#else - return 0; -#endif - } - } + if (!cdGetFontFileName(font, filename)) + return 0; error = FT_New_Face(tt_text->library, filename, 0, &face ); if (error) |