1 /*
2 *******************************************************************************
3 *
4 * © 2016 and later: Unicode, Inc. and others.
5 * License & terms of use: http://www.unicode.org/copyright.html
6 *
7 *******************************************************************************
8 *******************************************************************************
9 *
10 * Copyright (C) 1999-2013, International Business Machines
11 * Corporation and others. All Rights Reserved.
12 *
13 *******************************************************************************
14 * file name: SimpleFontInstance.cpp
15 *
16 * created on: 03/30/2006
17 * created by: Eric R. Mader
18 */
19
20 #include "unicode/utypes.h"
21 #include "unicode/uchar.h"
22
23 #include "layout/LETypes.h"
24 #include "layout/LEFontInstance.h"
25
26 #include "layout/CanonShaping.h"
27 #include "SimpleFontInstance.h"
28
SimpleFontInstance(float pointSize,LEErrorCode & status)29 SimpleFontInstance::SimpleFontInstance(float pointSize, LEErrorCode &status)
30 : fPointSize(pointSize), fAscent(0), fDescent(0)
31 {
32 if (LE_FAILURE(status)) {
33 return;
34 }
35
36 fAscent = (le_int32) yUnitsToPoints(2000.0);
37 fDescent = (le_int32) yUnitsToPoints(600.0);
38 }
39
~SimpleFontInstance()40 SimpleFontInstance::~SimpleFontInstance()
41 {
42 // nothing to do...
43 }
44
getFontTable(LETag tableTag) const45 const void *SimpleFontInstance::getFontTable(LETag tableTag) const
46 {
47 if (tableTag == LE_GSUB_TABLE_TAG) {
48 return CanonShaping::glyphSubstitutionTable;
49 }
50
51 if (tableTag == LE_GDEF_TABLE_TAG) {
52 return CanonShaping::glyphDefinitionTable;
53 }
54
55 return nullptr;
56 }
57
getGlyphAdvance(LEGlyphID glyph,LEPoint & advance) const58 void SimpleFontInstance::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const
59 {
60 #if 0
61 if (u_getCombiningClass((UChar32) glyph) == 0) {
62 advance.fX = xUnitsToPoints(2048);
63 } else {
64 advance.fX = 0;
65 }
66 #else
67 advance.fX = xUnitsToPoints(2048);
68 #endif
69
70 advance.fY = 0;
71 }
72
getUnitsPerEM() const73 le_int32 SimpleFontInstance::getUnitsPerEM() const
74 {
75 return 2048;
76 }
77
getAscent() const78 le_int32 SimpleFontInstance::getAscent() const
79 {
80 return fAscent;
81 }
82
getDescent() const83 le_int32 SimpleFontInstance::getDescent() const
84 {
85 return fDescent;
86 }
87
getLeading() const88 le_int32 SimpleFontInstance::getLeading() const
89 {
90 return 0;
91 }
92
93 // We really want to inherit this method from the superclass, but some compilers
94 // issue a warning if we don't implement it...
mapCharToGlyph(LEUnicode32 ch,const LECharMapper * mapper,le_bool filterZeroWidth) const95 LEGlyphID SimpleFontInstance::mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper, le_bool filterZeroWidth) const
96 {
97 return LEFontInstance::mapCharToGlyph(ch, mapper, filterZeroWidth);
98 }
99
100 // We really want to inherit this method from the superclass, but some compilers
101 // issue a warning if we don't implement it...
mapCharToGlyph(LEUnicode32 ch,const LECharMapper * mapper) const102 LEGlyphID SimpleFontInstance::mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const
103 {
104 return LEFontInstance::mapCharToGlyph(ch, mapper);
105 }
106
mapCharToGlyph(LEUnicode32 ch) const107 LEGlyphID SimpleFontInstance::mapCharToGlyph(LEUnicode32 ch) const
108 {
109 return (LEGlyphID) ch;
110 }
111
getXPixelsPerEm() const112 float SimpleFontInstance::getXPixelsPerEm() const
113 {
114 return fPointSize;
115 }
116
getYPixelsPerEm() const117 float SimpleFontInstance::getYPixelsPerEm() const
118 {
119 return fPointSize;
120 }
121
getScaleFactorX() const122 float SimpleFontInstance::getScaleFactorX() const
123 {
124 return 1.0;
125 }
126
getScaleFactorY() const127 float SimpleFontInstance::getScaleFactorY() const
128 {
129 return 1.0;
130 }
131
getGlyphPoint(LEGlyphID,le_int32,LEPoint &) const132 le_bool SimpleFontInstance::getGlyphPoint(LEGlyphID /*glyph*/, le_int32 /*pointNumber*/, LEPoint &/*point*/) const
133 {
134 return false;
135 }
136
137