1// Copyright (C) 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 "CanonShaping.h"
24#endif
25
26#include "SimpleFontInstance.h"
27
28SimpleFontInstance::SimpleFontInstance(float pointSize, LEErrorCode &status)
29    : fPointSize(pointSize), fAscent(0), fDescent(0)
30{
31    if (LE_FAILURE(status)) {
32        return;
33    }
34
35    fAscent  = (le_int32) yUnitsToPoints(2000.0);
36    fDescent = (le_int32) yUnitsToPoints(600.0);
37
38    return;
39}
40
41SimpleFontInstance::~SimpleFontInstance()
42{
43    // nothing to do...
44}
45
46const void *SimpleFontInstance::getFontTable(LETag tableTag, size_t &length) const
47{
48  length = -1; // unknown for this test.
49#ifndef USING_ICULEHB
50    if (tableTag == LE_GSUB_TABLE_TAG) {
51        return CanonShaping::glyphSubstitutionTable;
52    }
53
54    if (tableTag == LE_GDEF_TABLE_TAG) {
55        return CanonShaping::glyphDefinitionTable;
56    }
57#endif
58    return NULL;
59}
60
61void SimpleFontInstance::getGlyphAdvance(LEGlyphID glyph, LEPoint &advance) const
62{
63#if 0
64    if (u_getCombiningClass((UChar32) glyph) == 0) {
65        advance.fX = xUnitsToPoints(2048);
66    } else {
67        advance.fX = 0;
68    }
69#else
70    (void)glyph;  // Suppress unused parameter compiler warning.
71    advance.fX = xUnitsToPoints(2048);
72#endif
73
74    advance.fY = 0;
75}
76
77le_int32 SimpleFontInstance::getUnitsPerEM() const
78{
79    return 2048;
80}
81
82le_int32 SimpleFontInstance::getAscent() const
83{
84    return fAscent;
85}
86
87le_int32 SimpleFontInstance::getDescent() const
88{
89    return fDescent;
90}
91
92le_int32 SimpleFontInstance::getLeading() const
93{
94    return 0;
95}
96
97// We really want to inherit this method from the superclass, but some compilers
98// issue a warning if we don't implement it...
99LEGlyphID SimpleFontInstance::mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper, le_bool filterZeroWidth) const
100{
101    return LEFontInstance::mapCharToGlyph(ch, mapper, filterZeroWidth);
102}
103
104// We really want to inherit this method from the superclass, but some compilers
105// issue a warning if we don't implement it...
106LEGlyphID SimpleFontInstance::mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const
107{
108    return LEFontInstance::mapCharToGlyph(ch, mapper);
109}
110
111LEGlyphID SimpleFontInstance::mapCharToGlyph(LEUnicode32 ch) const
112{
113    return (LEGlyphID) ch;
114}
115
116float SimpleFontInstance::getXPixelsPerEm() const
117{
118    return fPointSize;
119}
120
121float SimpleFontInstance::getYPixelsPerEm() const
122{
123    return fPointSize;
124}
125
126float SimpleFontInstance::getScaleFactorX() const
127{
128    return 1.0;
129}
130
131float SimpleFontInstance::getScaleFactorY() const
132{
133    return 1.0;
134}
135
136le_bool SimpleFontInstance::getGlyphPoint(LEGlyphID /*glyph*/, le_int32 /*pointNumber*/, LEPoint &/*point*/) const
137{
138    return FALSE;
139}
140
141