• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // © 2016 and later: Unicode, Inc. and others.
2 // License & terms of use: http://www.unicode.org/copyright.html
3 /*
4  *******************************************************************************
5  *
6  *   Copyright (C) 1999-2015, International Business Machines
7  *   Corporation and others.  All Rights Reserved.
8  *
9  *******************************************************************************
10  *   file name:  SimpleFontInstance.cpp
11  *
12  *   created on: 03/30/2006
13  *   created by: Eric R. Mader
14  */
15 
16 #include "unicode/utypes.h"
17 #include "unicode/uchar.h"
18 
19 #include "layout/LETypes.h"
20 #include "layout/LEFontInstance.h"
21 
22 #ifndef USING_ICULEHB
23 #include "layout/CanonShaping.h"
24 #endif
25 
26 #include "SimpleFontInstance.h"
27 
SimpleFontInstance(float pointSize,LEErrorCode & status)28 SimpleFontInstance::SimpleFontInstance(float pointSize, LEErrorCode &status)
29     : fPointSize(pointSize), fAscent(0), fDescent(0)
30 {
31     if (LE_FAILURE(status)) {
32         return;
33     }
34 
35     fAscent = static_cast<le_int32>(yUnitsToPoints(2000.0));
36     fDescent = static_cast<le_int32>(yUnitsToPoints(600.0));
37 }
38 
~SimpleFontInstance()39 SimpleFontInstance::~SimpleFontInstance()
40 {
41     // nothing to do...
42 }
43 
getFontTable(LETag tableTag,size_t & length) const44 const void *SimpleFontInstance::getFontTable(LETag tableTag, size_t &length) const
45 {
46   length = -1; // unknown for this test.
47 #ifndef USING_ICULEHB
48     if (tableTag == LE_GSUB_TABLE_TAG) {
49         return CanonShaping::glyphSubstitutionTable;
50     }
51 
52     if (tableTag == LE_GDEF_TABLE_TAG) {
53         return CanonShaping::glyphDefinitionTable;
54     }
55 #endif
56     return nullptr;
57 }
58 
getGlyphAdvance(LEGlyphID glyph,LEPoint & advance) const59 void SimpleFontInstance::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const
60 {
61 #if 0
62     if (u_getCombiningClass((UChar32) glyph) == 0) {
63         advance.fX = xUnitsToPoints(2048);
64     } else {
65         advance.fX = 0;
66     }
67 #else
68     (void)glyph;  // Suppress unused parameter compiler warning.
69     advance.fX = xUnitsToPoints(2048);
70 #endif
71 
72     advance.fY = 0;
73 }
74 
getUnitsPerEM() const75 le_int32 SimpleFontInstance::getUnitsPerEM() const
76 {
77     return 2048;
78 }
79 
getAscent() const80 le_int32 SimpleFontInstance::getAscent() const
81 {
82     return fAscent;
83 }
84 
getDescent() const85 le_int32 SimpleFontInstance::getDescent() const
86 {
87     return fDescent;
88 }
89 
getLeading() const90 le_int32 SimpleFontInstance::getLeading() const
91 {
92     return 0;
93 }
94 
95 // We really want to inherit this method from the superclass, but some compilers
96 // issue a warning if we don't implement it...
mapCharToGlyph(LEUnicode32 ch,const LECharMapper * mapper,le_bool filterZeroWidth) const97 LEGlyphID SimpleFontInstance::mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper, le_bool filterZeroWidth) const
98 {
99     return LEFontInstance::mapCharToGlyph(ch, mapper, filterZeroWidth);
100 }
101 
102 // We really want to inherit this method from the superclass, but some compilers
103 // issue a warning if we don't implement it...
mapCharToGlyph(LEUnicode32 ch,const LECharMapper * mapper) const104 LEGlyphID SimpleFontInstance::mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const
105 {
106     return LEFontInstance::mapCharToGlyph(ch, mapper);
107 }
108 
mapCharToGlyph(LEUnicode32 ch) const109 LEGlyphID SimpleFontInstance::mapCharToGlyph(LEUnicode32 ch) const
110 {
111     return static_cast<LEGlyphID>(ch);
112 }
113 
getXPixelsPerEm() const114 float SimpleFontInstance::getXPixelsPerEm() const
115 {
116     return fPointSize;
117 }
118 
getYPixelsPerEm() const119 float SimpleFontInstance::getYPixelsPerEm() const
120 {
121     return fPointSize;
122 }
123 
getScaleFactorX() const124 float SimpleFontInstance::getScaleFactorX() const
125 {
126     return 1.0;
127 }
128 
getScaleFactorY() const129 float SimpleFontInstance::getScaleFactorY() const
130 {
131     return 1.0;
132 }
133 
getGlyphPoint(LEGlyphID,le_int32,LEPoint &) const134 le_bool SimpleFontInstance::getGlyphPoint(LEGlyphID /*glyph*/, le_int32 /*pointNumber*/, LEPoint &/*point*/) const
135 {
136     return false;
137 }
138 
139