[PATCH v2 0/2] MR3471: gdiplus: Reduce code redundancy.
i) Introduce a helper for calculating transform properties. ii) Re-use get_log_fontW to populate LOGFONTW from GpFont. Signed-off-by: David Kahurani k.kahurani(a)gmail.com -- v2: gdiplus: Use get_log_fontW in GdipGetLogFontW gdiplus: Use helper to calculate transform properties https://gitlab.winehq.org/wine/wine/-/merge_requests/3471
From: David Kahurani <k.kahurani(a)gmail.com> Signed-off-by: David Kahurani <k.kahurani(a)gmail.com> --- dlls/gdiplus/font.c | 14 +----- dlls/gdiplus/gdiplus_private.h | 1 + dlls/gdiplus/graphics.c | 88 ++++++++++++---------------------- 3 files changed, 32 insertions(+), 71 deletions(-) diff --git a/dlls/gdiplus/font.c b/dlls/gdiplus/font.c index 024d27c1ce7..316f65d84cf 100644 --- a/dlls/gdiplus/font.c +++ b/dlls/gdiplus/font.c @@ -456,7 +456,6 @@ GpStatus WINGDIPAPI GdipGetLogFontW(GpFont *font, GpGraphics *graphics, LOGFONTW { REAL angle, rel_height, height; GpMatrix matrix; - GpPointF pt[3]; TRACE("(%p, %p, %p)\n", font, graphics, lf); @@ -479,19 +478,8 @@ GpStatus WINGDIPAPI GdipGetLogFontW(GpFont *font, GpGraphics *graphics, LOGFONTW height = units_to_pixels(font->emSize, font->unit, graphics->yres, graphics->printer_display); } - pt[0].X = 0.0; - pt[0].Y = 0.0; - pt[1].X = 1.0; - pt[1].Y = 0.0; - pt[2].X = 0.0; - pt[2].Y = 1.0; - GdipMultiplyMatrix(&matrix, &graphics->gdi_transform, MatrixOrderAppend); - GdipTransformMatrixPoints(&matrix, pt, 3); - angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X)); - rel_height = sqrt((pt[2].Y - pt[0].Y) * (pt[2].Y - pt[0].Y)+ - (pt[2].X - pt[0].X) * (pt[2].X - pt[0].X)); - + transform_properties(graphics, &matrix, FALSE, NULL, &rel_height, &angle); lf->lfHeight = -gdip_round(height * rel_height); lf->lfWidth = 0; lf->lfEscapement = lf->lfOrientation = gdip_round((angle / M_PI) * 1800.0); diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h index c292318b06e..1bc058b3413 100644 --- a/dlls/gdiplus/gdiplus_private.h +++ b/dlls/gdiplus/gdiplus_private.h @@ -69,6 +69,7 @@ extern GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace d GpCoordinateSpace src_space, GpMatrix *matrix); extern GpStatus gdip_transform_points(GpGraphics *graphics, GpCoordinateSpace dst_space, GpCoordinateSpace src_space, GpPointF *points, INT count); +void transform_properties(GpGraphics *, GDIPCONST GpMatrix *, BOOL, REAL *, REAL *, REAL *); extern GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics); extern GpStatus encode_image_png(GpImage *image, IStream* stream, GDIPCONST EncoderParameters* params); diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c index 6dc34707bbf..87d9a74c396 100644 --- a/dlls/gdiplus/graphics.c +++ b/dlls/gdiplus/graphics.c @@ -2303,7 +2303,6 @@ static void get_font_hfont(GpGraphics *graphics, GDIPCONST GpFont *font, LOGFONTW *lfw_return, GDIPCONST GpMatrix *matrix) { HDC hdc = CreateCompatibleDC(0); - GpPointF pt[3]; REAL angle, rel_width, rel_height, font_height; LOGFONTW lfw; HFONT unscaled_font; @@ -2321,24 +2320,7 @@ static void get_font_hfont(GpGraphics *graphics, GDIPCONST GpFont *font, font_height = font->emSize * unit_scale; } - pt[0].X = 0.0; - pt[0].Y = 0.0; - pt[1].X = 1.0; - pt[1].Y = 0.0; - pt[2].X = 0.0; - pt[2].Y = 1.0; - if (matrix) - { - GpMatrix xform = *matrix; - GdipTransformMatrixPoints(&xform, pt, 3); - } - - gdip_transform_points(graphics, WineCoordinateSpaceGdiDevice, CoordinateSpaceWorld, pt, 3); - angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X)); - rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+ - (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X)); - rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+ - (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X)); + transform_properties(graphics, matrix, TRUE, &rel_width, &rel_height, &angle); /* If the font unit is not pixels scaling should not be applied */ if (font->unit != UnitPixel && font->unit != UnitWorld) { @@ -5373,6 +5355,31 @@ GpStatus gdip_format_string(HDC hdc, return stat; } +void transform_properties(GpGraphics *graphics, GDIPCONST GpMatrix *matrix, BOOL graphics_transform, + REAL *rel_width, REAL *rel_height, REAL *angle) +{ + GpPointF pt[3] {{0.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}}; + GpMatrix xform; + + if (matrix) + { + xform = *matrix; + GdipTransformMatrixPoints(&xform, pt, 3); + } + + if (graphics_transform) + gdip_transform_points(graphics, WineCoordinateSpaceGdiDevice, CoordinateSpaceWorld, pt, 3); + + if (rel_width) + *rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+ + (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X)); + if (rel_height) + *rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+ + (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X)); + if (angle) + *angle = -gdiplus_atan2((pt[1].Y - pt[0].Y), (pt[1].X - pt[0].X)); +} + struct measure_ranges_args { GpRegion **regions; REAL rel_width, rel_height; @@ -5427,7 +5434,6 @@ GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics, HFONT gdifont, oldfont; struct measure_ranges_args args; HDC hdc, temp_hdc=NULL; - GpPointF pt[3]; RectF scaled_rect; REAL margin_x; @@ -5451,21 +5457,10 @@ GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics, if (stringFormat->attr) TRACE("may be ignoring some format flags: attr %x\n", stringFormat->attr); - pt[0].X = 0.0; - pt[0].Y = 0.0; - pt[1].X = 1.0; - pt[1].Y = 0.0; - pt[2].X = 0.0; - pt[2].Y = 1.0; - gdip_transform_points(graphics, WineCoordinateSpaceGdiDevice, CoordinateSpaceWorld, pt, 3); - args.rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+ - (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X)); - args.rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+ - (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X)); margin_x = stringFormat->generic_typographic ? 0.0 : font->emSize / 6.0; margin_x *= units_scale(font->unit, graphics->unit, graphics->xres, graphics->printer_display); - + transform_properties(graphics, NULL, TRUE, &args.rel_width, &args.rel_height, NULL); scaled_rect.X = (layoutRect->X + margin_x) * args.rel_width; scaled_rect.Y = layoutRect->Y * args.rel_height; scaled_rect.Width = layoutRect->Width * args.rel_width; @@ -5554,7 +5549,6 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics, HFONT oldfont, gdifont; struct measure_string_args args; HDC temp_hdc=NULL, hdc; - GpPointF pt[3]; RectF scaled_rect; REAL margin_x; INT lines, glyphs; @@ -5580,18 +5574,7 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics, if(format) TRACE("may be ignoring some format flags: attr %x\n", format->attr); - pt[0].X = 0.0; - pt[0].Y = 0.0; - pt[1].X = 1.0; - pt[1].Y = 0.0; - pt[2].X = 0.0; - pt[2].Y = 1.0; - gdip_transform_points(graphics, WineCoordinateSpaceGdiDevice, CoordinateSpaceWorld, pt, 3); - args.rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+ - (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X)); - args.rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+ - (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X)); - + transform_properties(graphics, NULL, TRUE, &args.rel_width, &args.rel_height, NULL); margin_x = (format && format->generic_typographic) ? 0.0 : font->emSize / 6.0; margin_x *= units_scale(font->unit, graphics->unit, graphics->xres, graphics->printer_display); @@ -5699,7 +5682,7 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string { HRGN rgn = NULL; HFONT gdifont; - GpPointF pt[3], rectcpy[4]; + GpPointF rectcpy[4]; POINT corners[4]; REAL rel_width, rel_height, margin_x; INT save_state, format_flags = 0; @@ -5748,18 +5731,7 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string save_state = SaveDC(hdc); - pt[0].X = 0.0; - pt[0].Y = 0.0; - pt[1].X = 1.0; - pt[1].Y = 0.0; - pt[2].X = 0.0; - pt[2].Y = 1.0; - gdip_transform_points(graphics, WineCoordinateSpaceGdiDevice, CoordinateSpaceWorld, pt, 3); - rel_width = sqrt((pt[1].Y-pt[0].Y)*(pt[1].Y-pt[0].Y)+ - (pt[1].X-pt[0].X)*(pt[1].X-pt[0].X)); - rel_height = sqrt((pt[2].Y-pt[0].Y)*(pt[2].Y-pt[0].Y)+ - (pt[2].X-pt[0].X)*(pt[2].X-pt[0].X)); - + transform_properties(graphics, NULL, TRUE, &rel_width, &rel_height, NULL); rectcpy[3].X = rectcpy[0].X = rect->X; rectcpy[1].Y = rectcpy[0].Y = rect->Y; rectcpy[2].X = rectcpy[1].X = rect->X + rect->Width; -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/3471
From: David Kahurani <k.kahurani(a)gmail.com> Signed-off-by: David Kahurani <k.kahurani(a)gmail.com> --- dlls/gdiplus/font.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/dlls/gdiplus/font.c b/dlls/gdiplus/font.c index 316f65d84cf..7bd60750e6d 100644 --- a/dlls/gdiplus/font.c +++ b/dlls/gdiplus/font.c @@ -480,24 +480,15 @@ GpStatus WINGDIPAPI GdipGetLogFontW(GpFont *font, GpGraphics *graphics, LOGFONTW GdipMultiplyMatrix(&matrix, &graphics->gdi_transform, MatrixOrderAppend); transform_properties(graphics, &matrix, FALSE, NULL, &rel_height, &angle); + get_log_fontW(font, graphics, lf); + lf->lfHeight = -gdip_round(height * rel_height); - lf->lfWidth = 0; lf->lfEscapement = lf->lfOrientation = gdip_round((angle / M_PI) * 1800.0); if (lf->lfEscapement < 0) { lf->lfEscapement += 3600; lf->lfOrientation += 3600; } - lf->lfWeight = font->otm.otmTextMetrics.tmWeight; - lf->lfItalic = font->otm.otmTextMetrics.tmItalic ? 1 : 0; - lf->lfUnderline = font->otm.otmTextMetrics.tmUnderlined ? 1 : 0; - lf->lfStrikeOut = font->otm.otmTextMetrics.tmStruckOut ? 1 : 0; - lf->lfCharSet = font->otm.otmTextMetrics.tmCharSet; - lf->lfOutPrecision = OUT_DEFAULT_PRECIS; - lf->lfClipPrecision = CLIP_DEFAULT_PRECIS; - lf->lfQuality = DEFAULT_QUALITY; - lf->lfPitchAndFamily = 0; - lstrcpyW(lf->lfFaceName, font->family->FamilyName); TRACE("=> %s,%ld\n", debugstr_w(lf->lfFaceName), lf->lfHeight); -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/3471
Hi, It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated. The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=135501 Your paranoid android. === debian11 (build log) === ../wine/dlls/gdiplus/graphics.c:5361:20: error: expected ���=���, ���,���, ���;���, ���asm��� or ���__attribute__��� before ���{��� token ../wine/dlls/gdiplus/graphics.c:5361:32: error: expected ���;��� before ���}��� token ../wine/dlls/gdiplus/graphics.c:5361:33: error: expected expression before ���,��� token ../wine/dlls/gdiplus/graphics.c:5367:43: error: ���pt��� undeclared (first use in this function); did you mean ���putw���? Task: The win32 Wine build failed === debian11b (build log) === ../wine/dlls/gdiplus/graphics.c:5361:20: error: expected ���=���, ���,���, ���;���, ���asm��� or ���__attribute__��� before ���{��� token ../wine/dlls/gdiplus/graphics.c:5361:32: error: expected ���;��� before ���}��� token ../wine/dlls/gdiplus/graphics.c:5361:33: error: expected expression before ���,��� token ../wine/dlls/gdiplus/graphics.c:5367:43: error: ���pt��� undeclared (first use in this function); did you mean ���putw���? Task: The wow64 Wine build failed
participants (3)
-
David Kahurani -
David Kahurani (@kahurani) -
Marvin