| 1 | // SPDX-License-Identifier: MIT OR MPL-2.0 OR LGPL-2.1-or-later OR GPL-2.0-or-later |
| 2 | // Copyright 2010, SIL International, All rights reserved. |
| 3 | |
| 4 | #include "graphite2/Font.h" |
| 5 | #include "inc/Font.h" |
| 6 | |
| 7 | |
| 8 | using namespace graphite2; |
| 9 | |
| 10 | extern "C" { |
| 11 | |
| 12 | void gr_engine_version(int *nMajor, int *nMinor, int *nBugFix) |
| 13 | { |
| 14 | if (nMajor) *nMajor = GR2_VERSION_MAJOR; |
| 15 | if (nMinor) *nMinor = GR2_VERSION_MINOR; |
| 16 | if (nBugFix) *nBugFix = GR2_VERSION_BUGFIX; |
| 17 | } |
| 18 | |
| 19 | gr_font* gr_make_font(float ppm/*pixels per em*/, const gr_face *face) |
| 20 | { |
| 21 | return gr_make_font_with_advance_fn(ppm, 0, 0, face); |
| 22 | } |
| 23 | |
| 24 | |
| 25 | gr_font* gr_make_font_with_ops(float ppm/*pixels per em*/, const void* appFontHandle/*non-NULL*/, const gr_font_ops * font_ops, const gr_face * face/*needed for scaling*/) |
| 26 | { //the appFontHandle must stay alive all the time when the gr_font is alive. When finished with the gr_font, call destroy_gr_font |
| 27 | if (face == 0 || ppm <= 0) return 0; |
| 28 | |
| 29 | Font * const res = new Font(ppm, *face, appFontHandle, font_ops); |
| 30 | if (*res) |
| 31 | return static_cast<gr_font*>(res); |
| 32 | else |
| 33 | { |
| 34 | delete res; |
| 35 | return 0; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | gr_font* gr_make_font_with_advance_fn(float ppm/*pixels per em*/, const void* appFontHandle/*non-NULL*/, gr_advance_fn getAdvance, const gr_face * face/*needed for scaling*/) |
| 40 | { |
| 41 | const gr_font_ops ops = {sizeof(gr_font_ops), getAdvance, NULL}; |
| 42 | return gr_make_font_with_ops(ppm, appFontHandle, &ops, face); |
| 43 | } |
| 44 | |
| 45 | void gr_font_destroy(gr_font *font) |
| 46 | { |
| 47 | delete static_cast<Font*>(font); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | } // extern "C" |
| 52 | |