2
*******************************************************************************
4
* Copyright (C) 1999-2001, International Business Machines
5
* Corporation and others. All Rights Reserved.
7
*******************************************************************************
8
* file name: RenderingFontInstance.cpp
10
* created on: 10/22/2001
11
* created by: Eric R. Mader
15
#include "LEFontInstance.h"
16
#include "RenderingFontInstance.h"
23
RenderingFontInstance::RenderingFontInstance(void *surface, le_int16 pointSize)
24
: fSurface(surface), fPointSize(pointSize), fUnitsPerEM(0), fAscent(0), fDescent(), fLeading(0),
25
fTableCache(NULL), fTableCacheCurr(0), fTableCacheSize(0), fMapper(NULL)
27
// we expect the subclass to call
28
// initMapper() and initFontTableCache
31
RenderingFontInstance::~RenderingFontInstance()
33
flushFontTableCache();
39
void RenderingFontInstance::mapCharsToGlyphs(const LEUnicode chars[], le_int32 offset, le_int32 count,
40
le_bool reverse, const LECharMapper *mapper, LEGlyphID glyphs[]) const
42
le_int32 i, out = 0, dir = 1;
49
for (i = offset; i < offset + count; i += 1, out += dir) {
50
LEUnicode16 high = chars[i];
51
LEUnicode32 code = high;
53
if (i < offset + count - 1 && high >= 0xD800 && high <= 0xDBFF) {
54
LEUnicode16 low = chars[i + 1];
56
if (low >= 0xDC00 && low <= 0xDFFF) {
57
code = (high - 0xD800) * 0x400 + low - 0xDC00 + 0x10000;
61
glyphs[out] = mapCharToGlyph(code, mapper);
63
if (code >= 0x10000) {
65
glyphs[out += dir] = 0xFFFF;
70
LEGlyphID RenderingFontInstance::mapCharToGlyph(LEUnicode32 ch, const LECharMapper *mapper) const
72
LEUnicode32 mappedChar = mapper->mapChar(ch);
74
if (mappedChar == 0xFFFE || mappedChar == 0xFFFF) {
78
if (mappedChar == 0x200C || mappedChar == 0x200D) {
82
return fMapper->unicodeToGlyph(mappedChar);
85
const void *RenderingFontInstance::getFontTable(LETag tableTag) const
87
for (int i = 0; i < fTableCacheCurr; i += 1) {
88
if (fTableCache[i].tag == tableTag) {
89
return fTableCache[i].table;
93
RenderingFontInstance *realThis = (RenderingFontInstance *) this;
95
if (realThis->fTableCacheCurr >= realThis->fTableCacheSize) {
96
le_int32 newSize = realThis->fTableCacheSize + TABLE_CACHE_GROW;
97
TableCacheEntry *newTable = new TableCacheEntry[newSize];
99
// FIXME: need a better strategy than this...
100
if (newTable == NULL) {
104
memcpy(newTable, realThis->fTableCache, realThis->fTableCacheSize * sizeof realThis->fTableCache[0]);
105
delete[] realThis->fTableCache;
107
for (int i = realThis->fTableCacheSize; i < newSize; i += 1) {
109
newTable[i].table = NULL;
112
realThis->fTableCache = newTable;
113
realThis->fTableCacheSize = newSize;
116
realThis->fTableCache[realThis->fTableCacheCurr].tag = tableTag;
117
realThis->fTableCache[realThis->fTableCacheCurr].table = (void *) realThis->readFontTable(tableTag);
119
return fTableCache[realThis->fTableCacheCurr++].table;
122
RFIErrorCode RenderingFontInstance::initMapper()
124
LETag cmapTag = 0x636D6170; // 'cmap'
125
const CMAPTable *cmap = (const CMAPTable *) readFontTable(cmapTag);
128
return RFI_MISSING_FONT_TABLE_ERROR;
131
fMapper = CMAPMapper::createUnicodeMapper(cmap);
133
if (fMapper == NULL) {
134
return RFI_MISSING_FONT_TABLE_ERROR;
140
RFIErrorCode RenderingFontInstance::initFontTableCache()
142
fTableCacheSize = TABLE_CACHE_INIT;
143
fTableCache = new TableCacheEntry[fTableCacheSize];
145
if (fTableCache == 0) {
146
return RFI_OUT_OF_MEMORY_ERROR;
149
for (int i = 0; i < fTableCacheSize; i += 1) {
150
fTableCache[i].tag = 0;
151
fTableCache[i].table = NULL;
157
void RenderingFontInstance::flushFontTableCache()
159
for (int i = fTableCacheCurr - 1; i >= 0; i -= 1) {
160
delete[] (char *) fTableCache[i].table;