Skip to content

Commit

Permalink
fix termcs1 special case kluge, add MWTF_CMAP_DEFAULT/0/1 to GdSetFon…
Browse files Browse the repository at this point in the history
…tAttr for freetype
  • Loading branch information
ghaerr committed Nov 15, 2011
1 parent ef5a266 commit 9ffcd17
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 12 deletions.
2 changes: 2 additions & 0 deletions src/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
15 Nov 2011
* fix termcs1 freetype kluge, add MWTF_CMAP_DEFAULT/0/1 charmap select to GdSetFontAttr
26 Sep 2011
* added MWTF_BOLD flag to GrSetFontAttr to simulate bold fonts using FT2, nonrotated only
* deprecate demos/nanox/move.c demo
Expand Down
1 change: 0 additions & 1 deletion src/FIXME
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ GdBlit Frame->Pixmap fails, needs src rotate (and test)
GdStretchBlit Frame->Frame and Frame->Pixmap fails, needs src/dst rotate (and test)
convblits could be updated with rotation macros, move macros to convblit.h
compression flipy in mwin/winresbmp.c::resDecodeBitmap, remove duplicate bmp support
fix special case of termcs*.ttf symbol fonts
investigate why link with /usr/local/lib/libfreetype.so doesn't work!
remove printf/fprinf from all demo programs, add methods to nano-X.h
check optimization for gcc, will -O0 allow static inlines to be optimized?
Expand Down
6 changes: 5 additions & 1 deletion src/demos/nanox/ftdemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
#define FONTNAME "fonts/type1/bchr.pfb"
#elif HAVE_FREETYPE_2_SUPPORT
#define FONTNAME "lt1-r-omega-serif"
//#define FONTNAME "termcs1"
//#define FONTNAME "lucon"
//#define FONTNAME "cour"
#elif HAVE_PCF_SUPPORT
//#define FONTNAME "jiskan24.pcf.gz"
Expand Down Expand Up @@ -149,6 +151,8 @@ void Render(GR_WINDOW_ID window)
if (bold)
flags |= GR_TFBOLD;

// flags |= MWTF_CMAP_0; /* termcs1 only*/

GrGetScreenInfo(&info);
GrSetGCBackground(gid, WHITE);
GrSetGCForeground (gid, WHITE);
Expand All @@ -162,7 +166,7 @@ void Render(GR_WINDOW_ID window)

/* Draw menu */
GrSetGCFont(gid, fontid);
GrSetFontAttr(fontid, flags&(GR_TFANTIALIAS|GR_TFKERNING|GR_TFBOLD), -1);
GrSetFontAttr(fontid, flags & ~GR_TFUNDERLINE, -1);
GrText(window, gid, 5, 20, "+ Rotate string clockwise", 25, GR_TFASCII);
GrText(window, gid, 5, 40, "- Rotate string counter-clockwise", 34, GR_TFASCII);
GrText(window, gid, 5, 60, "a Toggle anti-aliasing", 22, GR_TFASCII);
Expand Down
37 changes: 28 additions & 9 deletions src/engine/font_freetype2.c
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ typedef struct {
FT_Face face;
#endif
FT_Matrix matrix;
int charmap; /* -1 for default (currently UNICODE), >= 0 for specific charset */

} MWFREETYPE2FONT, *PMWFREETYPE2FONT;

Expand Down Expand Up @@ -313,7 +314,6 @@ freetype2_face_requester(FTC_FaceID face_id, FT_Library library,
{
freetype2_fontdata *fontdata = (freetype2_fontdata *) face_id; // simple typecast
FT_Error rr;
char *p;

assert(fontdata);

Expand All @@ -330,11 +330,6 @@ freetype2_face_requester(FTC_FaceID face_id, FT_Library library,
assert(filename);
rr = FT_New_Face(library, filename, 0, aface);

/* FIXME special case termcs*.ttf*/
if ((p = strrchr(filename, '.')) != NULL && strcasecmp(p, ".ttf") == 0) {
if (&p[-7] >= filename && isprefix(&p[-7], "termcs"))
FT_Set_Charmap(*aface, (*aface)->charmaps[1]);
}
}

return rr;
Expand All @@ -354,7 +349,7 @@ freetype2_face_requester(FTC_FaceID face_id, FT_Library library,
*/
#if HAVE_FREETYPE_VERSION_AFTER_OR_EQUAL(2,3,9)
#define LOOKUP_CHAR(pf_,face_,ch_) \
(FTC_CMapCache_Lookup(freetype2_cache_cmap, (pf_)->imagedesc.face_id, -1, (ch_)))
(FTC_CMapCache_Lookup(freetype2_cache_cmap, (pf_)->imagedesc.face_id, (pf_)->charmap, (ch_)))
#else
#define LOOKUP_CHAR(pf_,face_,ch_) \
(FTC_CMapCache_Lookup(freetype2_cache_cmap, &((pf_)->cmapdesc), (ch_)))
Expand Down Expand Up @@ -614,6 +609,7 @@ freetype2_createfont_internal(freetype2_fontdata * faceid, char *filename, MWCOO
pf->fontprocs = &freetype2_fontprocs;
pf->faceid = faceid;
pf->filename = filename;
pf->charmap = -1;
#if HAVE_FREETYPE_2_CACHE
#if HAVE_FREETYPE_VERSION_AFTER_OR_EQUAL(2,3,9)
pf->imagedesc.face_id = faceid;
Expand Down Expand Up @@ -658,9 +654,10 @@ freetype2_createfont_internal(freetype2_fontdata * faceid, char *filename, MWCOO
}

error = FT_Select_Charmap(pf->face, FT_ENCODING_UNICODE);
//error = FT_Set_Charmap(pf->face, pf->face->charmaps[1]);
pf->charmap = -1;

if (error != FT_Err_Ok) {
EPRINTF("freetype2_createfont_internal: No unicode map table, error 0x%x\n", error);
EPRINTF("freetype2_createfont_internal: Can't set default UNICODE encoding 0x%x\n", error);
goto out;
}
#endif
Expand Down Expand Up @@ -897,12 +894,34 @@ freetype2_setfontattr(PMWFONT pfont, int setflags, int clrflags)
{
PMWFREETYPE2FONT pf = (PMWFREETYPE2FONT)pfont;
int oldattr = pf->fontattr;
int error = FT_Err_Ok;

assert(pfont);

pfont->fontattr &= ~clrflags;
pfont->fontattr |= setflags;

if(pfont->fontattr & MWTF_CMAP_0) {
#if !HAVE_FREETYPE_2_CMAP_CACHE
error = FT_Set_Charmap(pf->face, pf->face->charmaps[0]);
#endif
pf->charmap = 0;
} else if(pfont->fontattr & MWTF_CMAP_1) {
#if !HAVE_FREETYPE_2_CMAP_CACHE
error = FT_Set_Charmap(pf->face, pf->face->charmaps[1]);
#endif
pf->charmap = 1;
} else {
#if !HAVE_FREETYPE_2_CMAP_CACHE
error = FT_Select_Charmap(pf->face, FT_ENCODING_UNICODE);
#endif
pf->charmap = -1;
}

if (error != FT_Err_Ok) {
EPRINTF("freetype2_setfontattr: Cannot load charmap %d 0x%x\n", pf->charmap, error);
}

#if HAVE_FREETYPE_2_CACHE
#if HAVE_FREETYPE_VERSION_AFTER_OR_EQUAL(2,1,3)
pf->imagedesc.flags = FT_LOAD_DEFAULT;
Expand Down
6 changes: 5 additions & 1 deletion src/include/mwtypes.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _MWTYPES_H
#define _MWTYPES_H
/*
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2005, 2010 Greg Haerr <[email protected]>
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2005, 2010, 2011 Greg Haerr <[email protected]>
* Portions Copyright (c) 2002 by Koninklijke Philips Electronics N.V.
*
* Exported Microwindows engine typedefs and defines
Expand Down Expand Up @@ -79,6 +79,10 @@
#define MWTF_UNDERLINE 0x0004 /* draw underline*/
#define MWTF_BOLD 0x0008 /* draw bold glyph (not present on all renderers)*/

#define MWTF_CMAP_DEFAULT 0x0010 /* use default (unicode) charset in truetype font (not required)*/
#define MWTF_CMAP_0 0x0020 /* use charmap 0 in truetype font*/
#define MWTF_CMAP_1 0x0040 /* use charmap 1 in truetype font*/

#define MWTF_FREETYPE 0x1000 /* FIXME: remove*/
#define MWTF_SCALEHEIGHT 0x2000 /* font can scale height seperately*/
#define MWTF_SCALEWIDTH 0x4000 /* font can scale width seperately*/
Expand Down

0 comments on commit 9ffcd17

Please sign in to comment.