mirror of
https://gitlab.freedesktop.org/cairo/cairo.git
synced 2026-05-09 03:48:03 +02:00
[win32] Allow for creating a font from a HFONT
(cherry picked from 677f6c84f9beae3afd375663fed0a440007ebca2 commit)
This commit is contained in:
parent
244c111fca
commit
a10bbecaf8
2 changed files with 34 additions and 4 deletions
|
|
@ -98,7 +98,8 @@ typedef struct {
|
|||
|
||||
HFONT scaled_hfont;
|
||||
HFONT unscaled_hfont;
|
||||
|
||||
|
||||
cairo_bool_t delete_scaled_hfont;
|
||||
} cairo_win32_scaled_font_t;
|
||||
|
||||
static cairo_status_t
|
||||
|
|
@ -225,6 +226,7 @@ _get_system_quality (void)
|
|||
|
||||
static cairo_scaled_font_t *
|
||||
_win32_scaled_font_create (LOGFONTW *logfont,
|
||||
HFONT hfont,
|
||||
cairo_font_face_t *font_face,
|
||||
const cairo_matrix_t *font_matrix,
|
||||
const cairo_matrix_t *ctm,
|
||||
|
|
@ -270,9 +272,12 @@ _win32_scaled_font_create (LOGFONTW *logfont,
|
|||
}
|
||||
|
||||
f->em_square = 0;
|
||||
f->scaled_hfont = NULL;
|
||||
f->scaled_hfont = hfont;
|
||||
f->unscaled_hfont = NULL;
|
||||
|
||||
/* don't delete the hfont if it was passed in to us */
|
||||
f->delete_scaled_hfont = !hfont;
|
||||
|
||||
cairo_matrix_multiply (&scale, font_matrix, ctm);
|
||||
_compute_transform (f, &scale);
|
||||
|
||||
|
|
@ -516,7 +521,7 @@ _cairo_win32_scaled_font_create_toy (cairo_toy_font_face_t *toy_face,
|
|||
if (!logfont.lfFaceName)
|
||||
return CAIRO_STATUS_NO_MEMORY;
|
||||
|
||||
scaled_font = _win32_scaled_font_create (&logfont, &toy_face->base,
|
||||
scaled_font = _win32_scaled_font_create (&logfont, NULL, &toy_face->base,
|
||||
font_matrix, ctm, options);
|
||||
if (!scaled_font)
|
||||
return CAIRO_STATUS_NO_MEMORY;
|
||||
|
|
@ -534,7 +539,7 @@ _cairo_win32_scaled_font_fini (void *abstract_font)
|
|||
if (scaled_font == NULL)
|
||||
return;
|
||||
|
||||
if (scaled_font->scaled_hfont)
|
||||
if (scaled_font->scaled_hfont && scaled_font->delete_scaled_hfont)
|
||||
DeleteObject (scaled_font->scaled_hfont);
|
||||
|
||||
if (scaled_font->unscaled_hfont)
|
||||
|
|
@ -1371,6 +1376,7 @@ typedef struct _cairo_win32_font_face cairo_win32_font_face_t;
|
|||
struct _cairo_win32_font_face {
|
||||
cairo_font_face_t base;
|
||||
LOGFONTW logfont;
|
||||
HFONT hfont;
|
||||
};
|
||||
|
||||
/* implement the platform-specific interface */
|
||||
|
|
@ -1390,6 +1396,7 @@ _cairo_win32_font_face_scaled_font_create (void *abstract_face,
|
|||
cairo_win32_font_face_t *font_face = abstract_face;
|
||||
|
||||
*font = _win32_scaled_font_create (&font_face->logfont,
|
||||
font_face->hfont,
|
||||
&font_face->base,
|
||||
font_matrix, ctm, options);
|
||||
if (*font)
|
||||
|
|
@ -1431,6 +1438,26 @@ cairo_win32_font_face_create_for_logfontw (LOGFONTW *logfont)
|
|||
}
|
||||
|
||||
font_face->logfont = *logfont;
|
||||
font_face->hfont = NULL;
|
||||
|
||||
_cairo_font_face_init (&font_face->base, &_cairo_win32_font_face_backend);
|
||||
|
||||
return &font_face->base;
|
||||
}
|
||||
|
||||
|
||||
cairo_font_face_t *
|
||||
cairo_win32_font_face_create_for_hfont (HFONT font)
|
||||
{
|
||||
cairo_win32_font_face_t *font_face;
|
||||
|
||||
font_face = malloc (sizeof (cairo_win32_font_face_t));
|
||||
if (!font_face) {
|
||||
_cairo_error (CAIRO_STATUS_NO_MEMORY);
|
||||
return (cairo_font_face_t *)&_cairo_font_face_nil;
|
||||
}
|
||||
|
||||
font_face->hfont = font;
|
||||
|
||||
_cairo_font_face_init (&font_face->base, &_cairo_win32_font_face_backend);
|
||||
|
||||
|
|
|
|||
|
|
@ -58,6 +58,9 @@ cairo_win32_surface_get_dc (cairo_surface_t *surface);
|
|||
cairo_public cairo_font_face_t *
|
||||
cairo_win32_font_face_create_for_logfontw (LOGFONTW *logfont);
|
||||
|
||||
cairo_public cairo_font_face_t *
|
||||
cairo_win32_font_face_create_for_hfont (HFONT font);
|
||||
|
||||
cairo_public cairo_status_t
|
||||
cairo_win32_scaled_font_select_font (cairo_scaled_font_t *scaled_font,
|
||||
HDC hdc);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue