Skip to content

Commit

Permalink
gdiplus: Replace HDC with GpGraphics in parameters.
Browse files Browse the repository at this point in the history
(cherry picked from commit 1454ffe)
  • Loading branch information
tati-frog authored and ivyl committed Feb 15, 2024
1 parent c3e3bfe commit e8babc9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 25 deletions.
4 changes: 2 additions & 2 deletions dlls/gdiplus/gdiplus_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -606,13 +606,13 @@ static inline const void *buffer_read(struct memory_buffer *mbuf, INT size)
return NULL;
}

typedef GpStatus (*gdip_format_string_callback)(HDC hdc,
typedef GpStatus (*gdip_format_string_callback)(GpGraphics *graphics,
GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
INT lineno, const RectF *bounds, INT *underlined_indexes,
INT underlined_index_count, void *user_data);

GpStatus gdip_format_string(HDC hdc,
GpStatus gdip_format_string(GpGraphics *graphics,
GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, int ignore_empty_clip,
gdip_format_string_callback callback, void *user_data);
Expand Down
36 changes: 17 additions & 19 deletions dlls/gdiplus/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -5161,7 +5161,7 @@ GpStatus WINGDIPAPI GdipIsVisibleRectI(GpGraphics *graphics, INT x, INT y, INT w
return GdipIsVisibleRect(graphics, (REAL)x, (REAL)y, (REAL)width, (REAL)height, result);
}

GpStatus gdip_format_string(HDC hdc,
GpStatus gdip_format_string(GpGraphics *graphics,
GDIPCONST WCHAR *string, INT length, GDIPCONST GpFont *font,
GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format, int ignore_empty_clip,
gdip_format_string_callback callback, void *user_data)
Expand Down Expand Up @@ -5243,7 +5243,7 @@ GpStatus gdip_format_string(HDC hdc,
halign = format->align;

while(sum < length){
GetTextExtentExPointW(hdc, stringdup + sum, length - sum,
GetTextExtentExPointW(graphics->hdc, stringdup + sum, length - sum,
nwidth, &fit, NULL, &size);
fitcpy = fit;

Expand Down Expand Up @@ -5292,7 +5292,7 @@ GpStatus gdip_format_string(HDC hdc,
else
lineend = fit;

GetTextExtentExPointW(hdc, stringdup + sum, lineend,
GetTextExtentExPointW(graphics->hdc, stringdup + sum, lineend,
nwidth, &j, NULL, &size);

bounds.Width = size.cx;
Expand Down Expand Up @@ -5326,7 +5326,7 @@ GpStatus gdip_format_string(HDC hdc,
if (hotkeyprefix_offsets[hotkeyprefix_end_pos] >= sum + lineend)
break;

stat = callback(hdc, stringdup, sum, lineend,
stat = callback(graphics, stringdup, sum, lineend,
font, rect, format, lineno, &bounds,
&hotkeyprefix_offsets[hotkeyprefix_pos],
hotkeyprefix_end_pos-hotkeyprefix_pos, user_data);
Expand Down Expand Up @@ -5392,7 +5392,7 @@ struct measure_ranges_args {
REAL rel_width, rel_height;
};

static GpStatus measure_ranges_callback(HDC hdc,
static GpStatus measure_ranges_callback(GpGraphics *graphics,
GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
INT lineno, const RectF *bounds, INT *underlined_indexes,
Expand All @@ -5414,11 +5414,11 @@ static GpStatus measure_ranges_callback(HDC hdc,
range_rect.Y = bounds->Y / args->rel_height;
range_rect.Height = bounds->Height / args->rel_height;

GetTextExtentExPointW(hdc, string + index, range_start - index,
GetTextExtentExPointW(graphics->hdc, string + index, range_start - index,
INT_MAX, NULL, NULL, &range_size);
range_rect.X = (bounds->X + range_size.cx) / args->rel_width;

GetTextExtentExPointW(hdc, string + index, range_end - index,
GetTextExtentExPointW(graphics->hdc, string + index, range_end - index,
INT_MAX, NULL, NULL, &range_size);
range_rect.Width = (bounds->X + range_size.cx) / args->rel_width - range_rect.X;

Expand Down Expand Up @@ -5496,7 +5496,7 @@ GpStatus WINGDIPAPI GdipMeasureCharacterRanges(GpGraphics* graphics,

gdi_transform_acquire(graphics);

stat = gdip_format_string(hdc, string, length, font, &scaled_rect, stringFormat,
stat = gdip_format_string(graphics, string, length, font, &scaled_rect, stringFormat,
(stringFormat->attr & StringFormatFlagsNoClip) != 0, measure_ranges_callback, &args);

gdi_transform_release(graphics);
Expand All @@ -5517,7 +5517,7 @@ struct measure_string_args {
REAL rel_width, rel_height;
};

static GpStatus measure_string_callback(HDC hdc,
static GpStatus measure_string_callback(GpGraphics *graphics,
GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
INT lineno, const RectF *bounds, INT *underlined_indexes,
Expand Down Expand Up @@ -5619,7 +5619,7 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,

gdi_transform_acquire(graphics);

gdip_format_string(hdc, string, length, font, &scaled_rect, format, TRUE,
gdip_format_string(graphics, string, length, font, &scaled_rect, format, TRUE,
measure_string_callback, &args);

gdi_transform_release(graphics);
Expand All @@ -5640,12 +5640,11 @@ GpStatus WINGDIPAPI GdipMeasureString(GpGraphics *graphics,
}

struct draw_string_args {
GpGraphics *graphics;
GDIPCONST GpBrush *brush;
REAL x, y, rel_width, rel_height, ascent;
};

static GpStatus draw_string_callback(HDC hdc,
static GpStatus draw_string_callback(GpGraphics *graphics,
GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
INT lineno, const RectF *bounds, INT *underlined_indexes,
Expand All @@ -5658,7 +5657,7 @@ static GpStatus draw_string_callback(HDC hdc,
position.X = args->x + bounds->X / args->rel_width;
position.Y = args->y + bounds->Y / args->rel_height + args->ascent;

stat = draw_driver_string(args->graphics, &string[index], length, font, format,
stat = draw_driver_string(graphics, &string[index], length, font, format,
args->brush, &position,
DriverStringOptionsCmapLookup|DriverStringOptionsRealizedAdvance, NULL);

Expand All @@ -5668,7 +5667,7 @@ static GpStatus draw_string_callback(HDC hdc,
REAL underline_y, underline_height;
int i;

GetOutlineTextMetricsW(hdc, sizeof(otm), &otm);
GetOutlineTextMetricsW(graphics->hdc, sizeof(otm), &otm);

underline_height = otm.otmsUnderscoreSize / args->rel_height;
underline_y = position.Y - otm.otmsUnderscorePosition / args->rel_height - underline_height / 2;
Expand All @@ -5679,13 +5678,13 @@ static GpStatus draw_string_callback(HDC hdc,
SIZE text_size;
INT ofs = underlined_indexes[i] - index;

GetTextExtentExPointW(hdc, string + index, ofs, INT_MAX, NULL, NULL, &text_size);
GetTextExtentExPointW(graphics->hdc, string + index, ofs, INT_MAX, NULL, NULL, &text_size);
start_x = text_size.cx / args->rel_width;

GetTextExtentExPointW(hdc, string + index, ofs+1, INT_MAX, NULL, NULL, &text_size);
GetTextExtentExPointW(graphics->hdc, string + index, ofs+1, INT_MAX, NULL, NULL, &text_size);
end_x = text_size.cx / args->rel_width;

GdipFillRectangle(args->graphics, (GpBrush*)args->brush, position.X+start_x, underline_y, end_x-start_x, underline_height);
GdipFillRectangle(graphics, (GpBrush*)args->brush, position.X+start_x, underline_y, end_x-start_x, underline_height);
}
}

Expand Down Expand Up @@ -5783,7 +5782,6 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string
get_font_hfont(graphics, font, format, &gdifont, NULL, NULL);
SelectObject(hdc, gdifont);

args.graphics = graphics;
args.brush = brush;

args.x = rect->X;
Expand All @@ -5797,7 +5795,7 @@ GpStatus WINGDIPAPI GdipDrawString(GpGraphics *graphics, GDIPCONST WCHAR *string
GetTextMetricsW(hdc, &textmetric);
args.ascent = textmetric.tmAscent / rel_height;

gdip_format_string(hdc, string, length, font, &scaled_rect, format, TRUE,
gdip_format_string(graphics, string, length, font, &scaled_rect, format, TRUE,
draw_string_callback, &args);

gdi_transform_release(graphics);
Expand Down
8 changes: 4 additions & 4 deletions dlls/gdiplus/graphicspath.c
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ struct format_string_args
float ascent;
};

static GpStatus format_string_callback(HDC dc,
static GpStatus format_string_callback(GpGraphics *graphics,
GDIPCONST WCHAR *string, INT index, INT length, GDIPCONST GpFont *font,
GDIPCONST RectF *rect, GDIPCONST GpStringFormat *format,
INT lineno, const RectF *bounds, INT *underlined_indexes,
Expand All @@ -975,7 +975,7 @@ static GpStatus format_string_callback(HDC dc,
TTPOLYGONHEADER *ph = NULL, *origph;
char *start;
DWORD len, ofs = 0;
len = GetGlyphOutlineW(dc, string[i], GGO_BEZIER, &gm, 0, NULL, &identity);
len = GetGlyphOutlineW(graphics->hdc, string[i], GGO_BEZIER, &gm, 0, NULL, &identity);
if (len == GDI_ERROR)
{
status = GenericError;
Expand All @@ -989,7 +989,7 @@ static GpStatus format_string_callback(HDC dc,
status = OutOfMemory;
break;
}
GetGlyphOutlineW(dc, string[i], GGO_BEZIER, &gm, len, start, &identity);
GetGlyphOutlineW(graphics->hdc, string[i], GGO_BEZIER, &gm, len, start, &identity);

ofs = 0;
while (ofs < len)
Expand Down Expand Up @@ -1117,7 +1117,7 @@ GpStatus WINGDIPAPI GdipAddPathString(GpPath* path, GDIPCONST WCHAR* string, INT
args.maxY = 0;
args.scale = emSize / native_height;
args.ascent = textmetric.tmAscent * args.scale;
status = gdip_format_string(dc, string, length, NULL, &scaled_layout_rect,
status = gdip_format_string(graphics, string, length, NULL, &scaled_layout_rect,
format, TRUE, format_string_callback, &args);

DeleteDC(dc);
Expand Down

0 comments on commit e8babc9

Please sign in to comment.