QtBase  v6.3.1
hb-gdi.cc
Go to the documentation of this file.
1 /*
2  * Copyright © 2019 Ebrahim Byagowi
3  *
4  * This is part of HarfBuzz, a text shaping library.
5  *
6  * Permission is hereby granted, without written agreement and without
7  * license or royalty fees, to use, copy, modify, and distribute this
8  * software and its documentation for any purpose, provided that the
9  * above copyright notice and the following two paragraphs appear in
10  * all copies of this software.
11  *
12  * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR
13  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
14  * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN
15  * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
16  * DAMAGE.
17  *
18  * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
19  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
21  * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO
22  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
23  */
24 
25 #include "hb.hh"
26 
27 #ifdef HAVE_GDI
28 
29 #include "hb-gdi.h"
30 
31 
41 static hb_blob_t *
42 _hb_gdi_reference_table (hb_face_t *face HB_UNUSED, hb_tag_t tag, void *user_data)
43 {
44  char *buffer = nullptr;
45  DWORD length = 0;
46 
47  HDC hdc = GetDC (nullptr);
48  if (unlikely (!SelectObject (hdc, (HFONT) user_data))) goto fail;
49 
50  length = GetFontData (hdc, hb_uint32_swap (tag), 0, buffer, length);
51  if (unlikely (length == GDI_ERROR)) goto fail_with_releasedc;
52 
53  buffer = (char *) hb_malloc (length);
54  if (unlikely (!buffer)) goto fail_with_releasedc;
55  length = GetFontData (hdc, hb_uint32_swap (tag), 0, buffer, length);
56  if (unlikely (length == GDI_ERROR)) goto fail_with_releasedc_and_free;
57  ReleaseDC (nullptr, hdc);
58 
60 
61 fail_with_releasedc_and_free:
62  hb_free (buffer);
63 fail_with_releasedc:
64  ReleaseDC (nullptr, hdc);
65 fail:
66  return hb_blob_get_empty ();
67 }
68 
79 hb_face_t *
80 hb_gdi_face_create (HFONT hfont)
81 {
82  return hb_face_create_for_tables (_hb_gdi_reference_table, (void *) hfont, nullptr);
83 }
84 
85 #endif
hb_blob_t * hb_blob_get_empty()
Definition: hb-blob.cc:226
hb_blob_t * hb_blob_create(const char *data, unsigned int length, hb_memory_mode_t mode, void *user_data, hb_destroy_func_t destroy)
Definition: hb-blob.cc:69
void const void *obj HB_UNUSED
Definition: hb-debug.hh:180
hb_face_t * hb_face_create_for_tables(hb_reference_table_func_t reference_table_func, void *user_data, hb_destroy_func_t destroy)
Definition: hb-face.cc:119
HB_BEGIN_DECLS HB_EXTERN hb_face_t * hb_gdi_face_create(HFONT hfont)
#define hb_malloc
Definition: hb.hh:235
#define unlikely(expr)
Definition: hb.hh:251
#define hb_free
Definition: hb.hh:238
GLenum GLuint GLenum GLsizei length
Definition: qopengl.h:270
GLenum face
GLenum GLuint buffer
@ HB_MEMORY_MODE_WRITABLE
Definition: hb-blob.h:72
uint32_t hb_tag_t
Definition: hb-common.h:157
HB_EXTERN hb_font_get_glyph_func_t void * user_data
XmlOutput::xml_output tag(const QString &name)
Definition: xmloutput.h:154