Module: wine Branch: master Commit: e70aa825cf557c425e646e22b81e6057618d7835 URL: https://gitlab.winehq.org/wine/wine/-/commit/e70aa825cf557c425e646e22b81e605...
Author: Piotr Caban piotr@codeweavers.com Date: Wed May 17 18:16:58 2023 +0200
wineps: Simplify PSDRV_UVMetrics implementation.
---
dlls/wineps.drv/afm.c | 36 ++++++++++++++++++++++++++++++++---- dlls/wineps.drv/builtin.c | 39 --------------------------------------- dlls/wineps.drv/psdrv.h | 1 - 3 files changed, 32 insertions(+), 44 deletions(-)
diff --git a/dlls/wineps.drv/afm.c b/dlls/wineps.drv/afm.c index cd08cee55f8..ef4f4485b22 100644 --- a/dlls/wineps.drv/afm.c +++ b/dlls/wineps.drv/afm.c @@ -22,6 +22,7 @@ */
#include <string.h> +#include <stdlib.h>
#include "psdrv.h" #include "wine/debug.h" @@ -185,6 +186,33 @@ static void PSDRV_DumpFontList(void) return; }
+/****************************************************************************** + * PSDRV_UVMetrics + * + * Find the AFMMETRICS for a given UV. Returns NULL if the font does not + * have a glyph for the given UV. + */ +static int __cdecl MetricsByUV(const void *a, const void *b) +{ + return (int)(((const AFMMETRICS *)a)->UV - ((const AFMMETRICS *)b)->UV); +} + +static const AFMMETRICS *PSDRV_UVMetrics(LONG UV, const AFM *afm) +{ + AFMMETRICS key; + + /* + * Ugly work-around for symbol fonts. Wine is sending characters which + * belong in the Unicode private use range (U+F020 - U+F0FF) as ASCII + * characters (U+0020 - U+00FF). + */ + + if ((afm->Metrics->UV & 0xff00) == 0xf000 && UV < 0x100) + UV |= 0xf000; + + key.UV = UV; + return bsearch(&key, afm->Metrics, afm->NumofMetrics, sizeof(AFMMETRICS), MetricsByUV); +}
/******************************************************************************* * PSDRV_CalcAvgCharWidth @@ -208,7 +236,7 @@ static inline SHORT MeanCharWidth(const AFM *afm) return (SHORT)(w + 0.5); }
-static const struct { LONG UV; int weight; } UVweight[27] = +static const struct { LONG UV; int weight; } UVweight[] = { { 0x0061, 64 }, { 0x0062, 14 }, { 0x0063, 27 }, { 0x0064, 35 }, { 0x0065, 100 }, { 0x0066, 20 }, { 0x0067, 14 }, { 0x0068, 42 }, @@ -224,13 +252,13 @@ SHORT PSDRV_CalcAvgCharWidth(const AFM *afm) float w = 0.0; int i;
- for (i = 0; i < 27; ++i) + for (i = 0; i < ARRAY_SIZE(UVweight); ++i) { const AFMMETRICS *afmm;
afmm = PSDRV_UVMetrics(UVweight[i].UV, afm); - if (afmm->UV != UVweight[i].UV) /* UVMetrics returns first glyph */ - return MeanCharWidth(afm); /* in font if UV is missing */ + if (!afmm) + return MeanCharWidth(afm);
w += afmm->WX * (float)(UVweight[i].weight); } diff --git a/dlls/wineps.drv/builtin.c b/dlls/wineps.drv/builtin.c index 02b452b0a8b..028c185d59c 100644 --- a/dlls/wineps.drv/builtin.c +++ b/dlls/wineps.drv/builtin.c @@ -84,42 +84,3 @@ BOOL PSDRV_WriteBuiltinGlyphShow(print_ctx *ctx, LPCWSTR str, INT count)
return TRUE; } - -/****************************************************************************** - * PSDRV_UVMetrics - * - * Find the AFMMETRICS for a given UV. Returns first glyph in the font - * (space?) if the font does not have a glyph for the given UV. - */ -static int __cdecl MetricsByUV(const void *a, const void *b) -{ - return (int)(((const AFMMETRICS *)a)->UV - ((const AFMMETRICS *)b)->UV); -} - -const AFMMETRICS *PSDRV_UVMetrics(LONG UV, const AFM *afm) -{ - AFMMETRICS key; - const AFMMETRICS *needle; - - /* - * Ugly work-around for symbol fonts. Wine is sending characters which - * belong in the Unicode private use range (U+F020 - U+F0FF) as ASCII - * characters (U+0020 - U+00FF). - */ - - if ((afm->Metrics->UV & 0xff00) == 0xf000 && UV < 0x100) - UV |= 0xf000; - - key.UV = UV; - - needle = bsearch(&key, afm->Metrics, afm->NumofMetrics, sizeof(AFMMETRICS), - MetricsByUV); - - if (needle == NULL) - { - WARN("No glyph for U+%.4lX in %s\n", UV, afm->FontName); - needle = afm->Metrics; - } - - return needle; -} diff --git a/dlls/wineps.drv/psdrv.h b/dlls/wineps.drv/psdrv.h index 981ef6868dd..afeaa5fec0c 100644 --- a/dlls/wineps.drv/psdrv.h +++ b/dlls/wineps.drv/psdrv.h @@ -501,7 +501,6 @@ INT PSDRV_GlyphListInit(void) DECLSPEC_HIDDEN; const GLYPHNAME *PSDRV_GlyphName(LPCSTR szName) DECLSPEC_HIDDEN; VOID PSDRV_IndexGlyphList(void) DECLSPEC_HIDDEN; BOOL PSDRV_GetType1Metrics(void) DECLSPEC_HIDDEN; -const AFMMETRICS *PSDRV_UVMetrics(LONG UV, const AFM *afm) DECLSPEC_HIDDEN; SHORT PSDRV_CalcAvgCharWidth(const AFM *afm) DECLSPEC_HIDDEN;
extern BOOL PSDRV_WriteSetBuiltinFont(print_ctx *ctx) DECLSPEC_HIDDEN;