From 8ba346eec549f4fc59a180626b47264b2211f9c8 Mon Sep 17 00:00:00 2001 From: Vincent Wei Date: Tue, 19 Mar 2019 18:43:04 +0800 Subject: [PATCH] use logfont name for CreateTextRunsInfo instead of logfont object --- include/gdi.h | 42 +++++++++++++------------ src/font/fontname.c | 32 ++++++++++++++++++++ src/font/logfont.c | 22 +++++++++++++- src/include/fontname.h | 7 +++++ src/newgdi/textrunsinfo.c | 64 ++++++++++++++++++++------------------- src/newgdi/textrunsinfo.h | 46 ++++++++++++++-------------- src/sysres/resmgr.c | 18 +++++------ src/sysres/resource.c | 24 ++++++++++----- 8 files changed, 165 insertions(+), 90 deletions(-) diff --git a/include/gdi.h b/include/gdi.h index b84875ba..a8aaeaba 100644 --- a/include/gdi.h +++ b/include/gdi.h @@ -5526,12 +5526,12 @@ MG_EXPORT int GUIAPI SubtractRect (RECT* rc, const RECT* psrc1, const RECT* psrc #define FONT_OTHER_TTFNOCACHEKERN 'r' #define FONT_OTHER_NIL FONT_OTHER_NONE -#define FS_OTHER_MASK 0x00FF0000 +#define FS_OTHER_MASK 0x00F00000 #define FS_OTHER_NONE 0x00000000 -#define FS_OTHER_AUTOSCALE 0x00010000 -#define FS_OTHER_TTFNOCACHE 0x00020000 -#define FS_OTHER_TTFKERN 0x00040000 -#define FS_OTHER_TTFNOCACHEKERN 0x00060000 /* KERN | NOCACHE */ +#define FS_OTHER_AUTOSCALE 0x00100000 +#define FS_OTHER_TTFNOCACHE 0x00200000 +#define FS_OTHER_TTFKERN 0x00400000 +#define FS_OTHER_TTFNOCACHEKERN 0x00600000 /* KERN | NOCACHE */ #define FONT_DECORATE_NIL '\0' #define FONT_DECORATE_NONE 'n' @@ -5782,14 +5782,16 @@ typedef struct _LOGFONT { * \var typedef LOGFONT* PLOGFONT * \brief Data type of pointer to a LOGFONT. */ -typedef LOGFONT* PLOGFONT; +typedef LOGFONT* PLOGFONT; + /** * \var typedef LOGFONT* CPLOGFONT * \brief Data type of pointer to a LOGFONT. */ -typedef LOGFONT* CPLOGFONT; +typedef const LOGFONT* CPLOGFONT; struct _WORDINFO; + /** * \var typedef struct _WORDINFO WORDINFO * \brief Date type of _WORDINFO. @@ -6807,9 +6809,9 @@ MG_EXPORT PLOGFONT GUIAPI CreateLogFontEx (const char* type, const char* family, * * This function creates a logical font by a font name specified by * \a font_name. Note that since version 3.4.0, you can specify up - * to 4 family names in the LOGFONT name, such as: + * to 7 family names in the LOGFONT name, such as: * - * ttf-Courier,宋体,Naskh,SansSerif-rrncns-*-16-UTF-8 + * ttf-Courier,宋体,Naskh,SansSerif-rrncns-U-16-UTF-8 * * In this way, you can specify a logfont to use multiple devfonts * to render a complex text. This is useful when different glyphs are @@ -6817,13 +6819,21 @@ MG_EXPORT PLOGFONT GUIAPI CreateLogFontEx (const char* type, const char* family, * often designed for a particular language/script or a few similar * languages/scripts. * + * Since 3.4.0, the previous width field of a logfont name is used for + * the glyph orientation: + * + * - 'U': Glyphs stand upright (default). + * - 'S': Glyphs are rotated 90 degrees clockwise (sideways). + * - 'D': Glyphs are upside-down. + * - 'L': Glyphs are rotated 90 degrees counter-clockwise (sideways left). + * * \param font_name The name of the logfont. * * \return The pointer to the logical font created, NULL on error. * * \sa CreateLogFont, SelectFont */ -MG_EXPORT PLOGFONT GUIAPI CreateLogFontByName (const char* font_name); +MG_EXPORT PLOGFONT GUIAPI CreateLogFontByName(const char* font_name); /** * \fn PLOGFONT GUIAPI CreateLogFontIndirect (LOGFONT* logfont) @@ -12487,14 +12497,14 @@ typedef struct _TEXTRUNSINFO TEXTRUNSINFO; MG_EXPORT TEXTRUNSINFO* GUIAPI CreateTextRunsInfo(Uchar32* ucs, int nr_ucs, LanguageCode lang_code, ParagraphDir base_dir, GlyphRunDir run_dir, GlyphOrient glyph_orient, GlyphOrientPolicy orient_policy, - LOGFONT* logfont, RGBCOLOR color); + const char* logfont_name, RGBCOLOR color); /** * Set font of part characters. Please call this function before * calling ShapeTextRunsBaisc or ShapeTextRunsComplex. */ MG_EXPORT BOOL GUIAPI SetPartFontInTextRuns(TEXTRUNSINFO* run_info, - int start_index, int length, LOGFONT* logfont); + int start_index, int length, const char* logfont_name); /** * Set color of part characters. @@ -12507,7 +12517,7 @@ MG_EXPORT BOOL GUIAPI SetPartColorInTextRuns(TEXTRUNSINFO* run_info, * new LOGFONT. */ MG_EXPORT BOOL GUIAPI ResetFontInTextRuns(TEXTRUNSINFO* run_info, - LOGFONT* logfont); + const char* logfont_name); /** * Reset the color of glyph runs. @@ -12515,12 +12525,6 @@ MG_EXPORT BOOL GUIAPI ResetFontInTextRuns(TEXTRUNSINFO* run_info, MG_EXPORT BOOL GUIAPI ResetColorInTextRuns(TEXTRUNSINFO* run_info, RGBCOLOR color); -/** - * Reset the breaking opportunities of glyph runs. - */ -MG_EXPORT BOOL GUIAPI ResetBreaksInTextRuns(TEXTRUNSINFO* run_info, - Uint8 ctr, Uint8 wbr, Uint8 lbp); - /** * Reset the direction and orientation of glyph runs. */ diff --git a/src/font/fontname.c b/src/font/fontname.c index 558057b5..eb68500e 100644 --- a/src/font/fontname.c +++ b/src/font/fontname.c @@ -474,6 +474,38 @@ int fontGetWidthFromName (const char* name) return atoi (width); } +/* Since 3.4.0; only for LOGFONT name */ +char fontGetOrientFromName (const char* name) +{ + int i; + const char* orient_part = name; + char orient [LEN_LOGFONT_NAME_FIELD + 1]; + + for (i = 0; i < NR_LOOP_FOR_ORIENT; i++) { + if ((orient_part = strchr (orient_part, '-')) == NULL) + return FONT_ORIENT_UPRIGHT; + + if (*(++orient_part) == '\0') + return FONT_ORIENT_UPRIGHT; + } + + i = 0; + while (orient_part [i]) { + if (orient_part [i] == '-') { + orient [i] = '\0'; + break; + } + + orient [i] = orient_part [i]; + i++; + } + + if (orient_part [i] == '\0') + return FONT_ORIENT_UPRIGHT; + + return orient[0]; +} + int fontGetHeightFromName (const char* name) { int i; diff --git a/src/font/logfont.c b/src/font/logfont.c index 93baeae6..5f1bebd9 100644 --- a/src/font/logfont.c +++ b/src/font/logfont.c @@ -458,6 +458,7 @@ PLOGFONT GUIAPI CreateLogFontByName (const char* font_name) char charset[LEN_LOGFONT_NAME_FIELD + 1]; DWORD style; int height; + int rotation; if (!fontGetTypeNameFromName (font_name, type) || !fontGetFamilyFromName (font_name, family) || @@ -466,7 +467,26 @@ PLOGFONT GUIAPI CreateLogFontByName (const char* font_name) ((style = fontGetStyleFromName (font_name)) == 0xFFFFFFFF)) return NULL; - return gdiCreateLogFont (type, family, charset, style, height, 0); + switch (fontGetOrientFromName (font_name)) { + case FONT_ORIENT_SIDEWAYS: + rotation = -900; + break; + + case FONT_ORIENT_UPSIDE_DOWN: + rotation = 1800; + break; + + case FONT_ORIENT_SIDEWAYS_LEFT: + rotation = 900; + break; + + case FONT_ORIENT_UPRIGHT: + default: + rotation = 0; + break; + } + + return gdiCreateLogFont (type, family, charset, style, height, rotation); } void GUIAPI DestroyLogFont (PLOGFONT logfont) diff --git a/src/include/fontname.h b/src/include/fontname.h index 75c73df0..e94f412a 100644 --- a/src/include/fontname.h +++ b/src/include/fontname.h @@ -45,6 +45,7 @@ extern "C" { #define NR_LOOP_FOR_STYLE 2 #define NR_LOOP_FOR_WIDTH 3 +#define NR_LOOP_FOR_ORIENT NR_LOOP_FOR_WIDTH #define NR_LOOP_FOR_HEIGHT 4 #define NR_LOOP_FOR_CHARSET 5 @@ -59,6 +60,12 @@ BOOL fontCopyStyleFromName (const char* name, char* style); DWORD fontGetStyleFromName (const char* name); DWORD fontConvertStyle (const char* style_part); +#define FONT_ORIENT_UPRIGHT 'U' +#define FONT_ORIENT_SIDEWAYS 'S' +#define FONT_ORIENT_UPSIDE_DOWN 'D' +#define FONT_ORIENT_SIDEWAYS_LEFT 'L' +char fontGetOrientFromName (const char* name); + int fontGetWidthFromName (const char* name); int fontGetHeightFromName (const char* name); BOOL fontGetCharsetFromName (const char* name, char* charset); diff --git a/src/newgdi/textrunsinfo.c b/src/newgdi/textrunsinfo.c index c0689e6c..1d1533e5 100644 --- a/src/newgdi/textrunsinfo.c +++ b/src/newgdi/textrunsinfo.c @@ -33,7 +33,7 @@ */ /* -** glyphruninfo.c: The implementation of APIs related TEXTRUNSINFO +** textrunsinfo.c: The implementation of APIs related to TEXTRUNSINFO ** ** Create by WEI Yongming at 2019/03/15 */ @@ -52,6 +52,7 @@ #include "devfont.h" #include "unicode-ops.h" #include "textrunsinfo.h" +#include "fontname.h" /* Local array size, used for stack-based local arrays */ #if SIZEOF_PTR == 8 @@ -167,11 +168,10 @@ static void state_update_for_new_run (TEXTRUNSTATE *state) #endif } -/* we need a logfont cache */ static LOGFONT* create_logfont_for_run(const TEXTRUNSINFO* runinfo, const TEXTRUN* run) { - return runinfo->lf; + return NULL; } static BOOL state_process_run (TEXTRUNSTATE *state) @@ -322,16 +322,19 @@ out: return ok; } -static inline Uint8 get_glyph_orient_from_logfont (LOGFONT* lf) +static inline Uint8 get_glyph_orient_from_fontname (const char* fontname) { - switch (lf->rotation) { - case -900: + switch (fontGetOrientFromName (fontname)) { + case FONT_ORIENT_SIDEWAYS: return GLYPH_ORIENT_EAST; - case 900: - return GLYPH_ORIENT_WEST; - case 1800: + + case FONT_ORIENT_UPSIDE_DOWN: return GLYPH_ORIENT_NORTH; - case 0: + + case FONT_ORIENT_SIDEWAYS_LEFT: + return GLYPH_ORIENT_WEST; + + case FONT_ORIENT_UPRIGHT: default: return GLYPH_ORIENT_SOUTH; } @@ -376,7 +379,7 @@ void* GetNextTextRunInfo(TEXTRUNSINFO* runinfo, TEXTRUNSINFO* GUIAPI CreateTextRunsInfo(Uchar32* ucs, int nr_ucs, LanguageCode lang_code, ParagraphDir base_dir, GlyphRunDir run_dir, GlyphOrient glyph_orient, GlyphOrientPolicy orient_policy, - LOGFONT* logfont, RGBCOLOR color) + const char* logfont_name, RGBCOLOR color) { BOOL ok = FALSE; @@ -411,14 +414,14 @@ TEXTRUNSINFO* GUIAPI CreateTextRunsInfo(Uchar32* ucs, int nr_ucs, */ // Initialize other fields - runinfo->ucs = ucs; - runinfo->lf = logfont; - runinfo->nr_ucs = nr_ucs; - runinfo->lc = lang_code; - runinfo->base_dir = (base_dir == BIDI_PGDIR_LTR) ? 0 : 1; - runinfo->run_dir = run_dir; - runinfo->ort_base = glyph_orient; - runinfo->ort_plc = orient_policy; + runinfo->ucs = ucs; + runinfo->fontname = logfont_name; + runinfo->nr_ucs = nr_ucs; + runinfo->lc = lang_code; + runinfo->base_level = (base_dir == BIDI_PGDIR_LTR) ? 0 : 1; + runinfo->run_dir = run_dir; + runinfo->ort_base = glyph_orient; + runinfo->ort_plc = orient_policy; INIT_LIST_HEAD(&runinfo->cm_head.list); runinfo->cm_head.si = 0; @@ -429,7 +432,7 @@ TEXTRUNSINFO* GUIAPI CreateTextRunsInfo(Uchar32* ucs, int nr_ucs, runinfo->nr_runs = 0; if (runinfo->ort_base == GLYPH_ORIENT_AUTO) - runinfo->ort_rsv = get_glyph_orient_from_logfont (runinfo->lf); + runinfo->ort_rsv = get_glyph_orient_from_fontname (runinfo->fontname); else runinfo->ort_rsv = runinfo->ort_base; @@ -480,7 +483,7 @@ out: } BOOL GUIAPI SetPartFontInTextRuns(TEXTRUNSINFO* runinfo, - int start_index, int length, LOGFONT* logfont) + int start_index, int length, const char* logfont_name) { if (runinfo == NULL) return FALSE; @@ -496,13 +499,13 @@ BOOL GUIAPI SetPartFontInTextRuns(TEXTRUNSINFO* runinfo, return FALSE; } -RGBCOLOR __mg_glyphruns_get_color(const TEXTRUNSINFO* runinfo, int index) +RGBCOLOR __mg_textruns_get_color(const TEXTRUNSINFO* runinfo, int index) { struct list_head *i; list_for_each(i, &runinfo->cm_head.list) { - UCHARCOLORMAP* color_entry; - color_entry = (UCHARCOLORMAP*)i; + TEXTCOLORMAP* color_entry; + color_entry = (TEXTCOLORMAP*)i; if (index >= color_entry->si && (index < color_entry->si + color_entry->len)) { return color_entry->color; @@ -515,7 +518,7 @@ RGBCOLOR __mg_glyphruns_get_color(const TEXTRUNSINFO* runinfo, int index) BOOL GUIAPI SetPartColorInTextRuns(TEXTRUNSINFO* runinfo, int start_index, int length, RGBCOLOR color) { - UCHARCOLORMAP* color_entry = NULL; + TEXTCOLORMAP* color_entry = NULL; if (runinfo == NULL || start_index < 0 || length < 0 || start_index > runinfo->nr_ucs || @@ -523,7 +526,7 @@ BOOL GUIAPI SetPartColorInTextRuns(TEXTRUNSINFO* runinfo, goto error; } - color_entry = calloc(1, sizeof(UCHARCOLORMAP)); + color_entry = calloc(1, sizeof(TEXTCOLORMAP)); if (color_entry == NULL) { goto error; } @@ -540,7 +543,7 @@ error: return FALSE; } -BOOL GUIAPI ResetFontInTextRuns(TEXTRUNSINFO* runinfo, LOGFONT* logfont) +BOOL GUIAPI ResetFontInTextRuns(TEXTRUNSINFO* runinfo, const char* logfont_name) { if (runinfo == NULL) return FALSE; @@ -556,8 +559,7 @@ BOOL GUIAPI ResetFontInTextRuns(TEXTRUNSINFO* runinfo, LOGFONT* logfont) runinfo->se.destroy_engine(runinfo->se.engine); } - runinfo->lf = logfont; - + runinfo->fontname = logfont_name; return create_glyph_runs(runinfo, NULL); } @@ -602,7 +604,7 @@ BOOL GUIAPI ResetColorInTextRuns(TEXTRUNSINFO* runinfo, RGBCOLOR color) return FALSE; while (!list_empty(&runinfo->cm_head.list)) { - UCHARCOLORMAP* entry = (UCHARCOLORMAP*)runinfo->cm_head.list.prev; + TEXTCOLORMAP* entry = (TEXTCOLORMAP*)runinfo->cm_head.list.prev; list_del(runinfo->cm_head.list.prev); free(entry); } @@ -635,7 +637,7 @@ BOOL GUIAPI DestroyTextRunsInfo(TEXTRUNSINFO* runinfo) return FALSE; while (!list_empty(&runinfo->cm_head.list)) { - UCHARCOLORMAP* entry = (UCHARCOLORMAP*)runinfo->cm_head.list.prev; + TEXTCOLORMAP* entry = (TEXTCOLORMAP*)runinfo->cm_head.list.prev; list_del(runinfo->cm_head.list.prev); free(entry); } diff --git a/src/newgdi/textrunsinfo.h b/src/newgdi/textrunsinfo.h index fe905804..ae2bcc7c 100644 --- a/src/newgdi/textrunsinfo.h +++ b/src/newgdi/textrunsinfo.h @@ -33,7 +33,7 @@ */ /* -** glyphruninfo.h: Internal interface related TEXTRUNSINFO. +** textrunsinfo.h: Internal interface related to TEXTRUNSINFO. ** ** Create by WEI Yongming at 2019/03/15 */ @@ -86,47 +86,47 @@ typedef struct _TEXTRUN { Uint32 ort:2; // the glyph orientation } TEXTRUN; -typedef struct _UCHARCOLORMAP { +typedef struct _TEXTCOLORMAP { struct list_head list; int si; int len; RGBCOLOR color; -} UCHARCOLORMAP; +} TEXTCOLORMAP; struct _TEXTRUNSINFO { /* The following fields will be initialized by CreateGlyphRunInfo. */ const Uchar32* ucs; // the uchars - LOGFONT* lf; // the logfont specified + const char* fontname;// the logfont specified - UCHARCOLORMAP cm_head; // the head of color map list of the characters + TEXTCOLORMAP cm_head; // the head of color map list of the characters struct list_head run_head;// glyph runs (list) - int nr_ucs; // number of uchars - int nr_runs; // number of runs - Uint32 lc:8; // language code specified - Uint32 ort_base:3; // the glyph orientation specified - Uint32 ort_rsv:3; // the glyph orientation resolved - Uint32 ort_plc:2; // the glyph orientation policy specified - Uint32 run_dir:4; // the run direction specified - Uint32 base_dir:1; // the paragraph direction; 0 for LTR, 1 for RTL + int nr_ucs; // number of uchars + int nr_runs; // number of runs + Uint32 lc:8; // language code specified + Uint32 ort_base:3; // the glyph orientation specified + Uint32 ort_rsv:3; // the glyph orientation resolved + Uint32 ort_plc:2; // the glyph orientation policy specified + Uint32 run_dir:4; // the run direction specified + Uint32 base_level:1; // the paragraph direction; 0 for LTR, 1 for RTL /* The following fields will be initialized by the shapping engine. */ - SHAPPINGENGINE se; // the shapping engine + SHAPPINGENGINE se; // the shapping engine }; -typedef struct _LAYOUTINFO LAYOUTINFO; +typedef struct _GLYPHLAYOUTINFO GLYPHLAYOUTINFO; -typedef struct _LAYOUTRUN { +typedef struct _GLYPHRUN { struct list_head list; TEXTRUN* text_run; // the glyph run int start_idx; // the index in glyph run int nr_glyphs; // the number of glyphs -} LAYOUTRUN; +} GLYPHRUN; -typedef struct _LAYOUTLINE { - LAYOUTINFO* layout_info; +typedef struct _GLYPHLINE { + GLYPHLAYOUTINFO* layout_info; - struct list_head run_head; // the list head for layout runs + struct list_head run_head; // the list head for glyph layout runs int idx; // the index in uchar string int len; // the length in uchar string @@ -135,9 +135,9 @@ typedef struct _LAYOUTLINE { Uint8 resolved_dir:3; // resolved direction of the line Uint8 all_even:1; // flag indicating all level is even Uint8 all_odd:1; // flag indicating all level is odd -} LAYOUTLINE; +} GLYPHLINE; -struct _LAYOUTINFO { +struct _GLYPHLAYOUTINFO { const TEXTRUNSINFO* runinfo; struct list_head line_head; @@ -149,7 +149,7 @@ struct _LAYOUTINFO { extern "C" { #endif /* __cplusplus */ -RGBCOLOR __mg_glyphruns_get_color(const TEXTRUNSINFO* runinfo, int index); +RGBCOLOR __mg_textruns_get_color(const TEXTRUNSINFO* runinfo, int index); #ifdef __cplusplus } diff --git a/src/sysres/resmgr.c b/src/sysres/resmgr.c index a442f154..5675c8b7 100644 --- a/src/sysres/resmgr.c +++ b/src/sysres/resmgr.c @@ -365,7 +365,7 @@ BOOL InitializeResManager(int hash_table_size) { char szpath[MAX_PATH+1]; char* p = NULL; - pwd_res_path = strdup("./"); + pwd_res_path = strdup("./"); //initialize paths #if !defined(__NOUNIX__) || defined(WIN32) @@ -701,7 +701,7 @@ void* LoadResource(const char* res_name, int type, DWORD usr_param) RES_ENTRY * entry; RES_KEY key; RES_TYPE_INFO *ti = NULL; - int src_type = 0; + int src_type = 0; void *data = NULL; char szfilename[MAX_PATH+1]={0}; @@ -752,11 +752,11 @@ void* LoadResource(const char* res_name, int type, DWORD usr_param) { //add type info's ti->ops_ref ++; - src_type = GetSourceType(entry); - if(src_type == REF_SRC_NOTYPE){ - src_type = ti->def_source; - SetSourceType(entry, src_type); - } + src_type = GetSourceType(entry); + if(src_type == REF_SRC_NOTYPE){ + src_type = ti->def_source; + SetSourceType(entry, src_type); + } switch(src_type) { case REF_SRC_FILE: @@ -837,7 +837,7 @@ static void delete_entry(HASH_TABLE *table, RES_ENTRY* entry) int ReleaseRes(RES_KEY key) { - int ref = 0; + int ref = 0; RES_ENTRY *entry = NULL; RES_LOCK(); entry = get_entry(&hash_table, key, FALSE); @@ -845,7 +845,7 @@ int ReleaseRes(RES_KEY key) RES_UNLOCK(); return -1; } - ref = --entry->refcnt; + ref = --entry->refcnt; if(ref <= 0) delete_entry(&hash_table, entry); RES_UNLOCK(); diff --git a/src/sysres/resource.c b/src/sysres/resource.c index cdebb208..01c610b2 100644 --- a/src/sysres/resource.c +++ b/src/sysres/resource.c @@ -288,7 +288,7 @@ const BITMAP* GUIAPI GetSystemBitmap (HWND hWnd, const char* id) if (hWnd == HWND_NULL) return NULL; - + win_info = GetWindowInfo(hWnd); return GetSystemBitmapEx (win_info->we_rdr->name, id); } @@ -297,15 +297,15 @@ BOOL GUIAPI RegisterSystemBitmap (HDC hdc, const char* rdr_name, const char* id) { char file[MAX_NAME + 1] = "bmp/"; char* file_name; - + file_name = file+strlen(file); - + if (GetMgEtcValue (rdr_name, id, file_name, sizeof(file)-(file_name - file)) < 0 ) return FALSE; if (!LoadBitmapFromRes (HDC_SCREEN, file)) return FALSE; - + return TRUE; } @@ -323,11 +323,21 @@ void GUIAPI UnregisterSystemBitmap (HDC hdc, const char* rdr_name, const char* i BOOL mg_InitSystemRes (void) { - InitializeResManager(57); +#ifdef _MGCHARSET_UNICODE +# ifdef _MGCOMPLEX_SCRIPTS +# define _SIZE_RES_HASH_TABLE 256 +# else +# define _SIZE_RES_HASH_TABLE 128 +# endif +#else +# define _SIZE_RES_HASH_TABLE 64 +#endif + + InitializeResManager(_SIZE_RES_HASH_TABLE); + +#undef _SIZE_RES_HASH_TABLE sysres_init_inner_resource(); - - return TRUE; }