2
******************************************************************************
3
* Copyright (C) 1998-2001, International Business Machines Corporation and *
4
* others. All Rights Reserved. *
5
******************************************************************************
12
#include "unicode/utypes.h"
13
#include "unicode/uscript.h"
15
#include "layout/LETypes.h"
16
#include "layout/LEScripts.h"
18
#include "RenderingFontInstance.h"
19
#include "GUISupport.h"
22
FontMap::FontMap(const char *fileName, le_int16 pointSize, GUISupport *guiSupport, RFIErrorCode &status)
23
: fPointSize(pointSize), fFontCount(0), fGUISupport(guiSupport)
27
for (i = 0; i < scriptCodeCount; i += 1) {
30
fFontInstances[i] = NULL;
33
if (LE_FAILURE(status)) {
37
char *c, *s, *line, buffer[BUFFER_SIZE];
40
file = fopen(fileName, "r");
43
sprintf(errorMessage, "Could not open the font map file: %s.", fileName);
44
fGUISupport->postErrorMessage(errorMessage, "Font Map Error");
45
status = RFI_FONT_FILE_NOT_FOUND_ERROR;
49
while (fgets(buffer, BUFFER_SIZE, file) != NULL) {
50
UScriptCode scriptCode;
51
UErrorCode scriptStatus = U_ZERO_ERROR;
54
if (line[0] == '#' || line[0] == 0) {
58
c = strchr(line, ':');
62
uscript_getCode(strip(line), &scriptCode, 1, &scriptStatus);
64
if (U_FAILURE(scriptStatus) || scriptStatus == U_USING_FALLBACK_WARNING ||
65
scriptStatus == U_USING_DEFAULT_WARNING) {
66
sprintf(errorMessage, "The script name %s is invalid.", line);
67
fGUISupport->postErrorMessage(errorMessage, "Font Map Error");
68
status = RFI_ILLEGAL_ARGUMENT_ERROR;
73
script = (le_int32) scriptCode;
75
if (fFontIndices[script] >= 0) {
76
// FIXME: complain that this is a duplicate entry and bail (?)
77
fFontIndices[script] = -1;
80
fFontIndices[script] = getFontIndex(s);
90
for (font = 0; font < fFontCount; font += 1) {
91
if (fFontNames[font] != NULL) {
92
delete[] (char *) fFontNames[font];
96
for (font = 0; font < fFontCount; font += 1) {
97
if (fFontInstances[font] != NULL) {
98
delete fFontInstances[font];
103
le_int32 FontMap::getFontIndex(const char *fontName)
107
for (index = 0; index < fFontCount; index += 1) {
108
if (strcmp(fontName, fFontNames[index]) == 0) {
113
if (fFontCount < (le_int32) scriptCodeCount) {
114
index = fFontCount++;
116
// The font name table is full. Since there can
117
// only be scriptCodeCount fonts in use at once,
118
// there should be at least one that's not being
119
// reference; find it and resue it's index.
121
for (index = 0; index < fFontCount; index += 1) {
124
for (script = 0; script < scriptCodeCount; script += 1) {
125
if (fFontIndices[script] == index) {
130
if (script >= scriptCodeCount) {
136
if (index >= scriptCodeCount) {
140
le_int32 len = strlen(fontName);
141
char *s = new char[len + 1];
143
fFontNames[index] = strcpy(s, fontName);
147
char *FontMap::strip(char *s)
149
le_int32 start, end, len;
154
while (start < len && isspace(s[start])) {
160
while (end > start && isspace(s[end])) {
171
const RenderingFontInstance *FontMap::getScriptFont(le_int32 scriptCode, RFIErrorCode &status)
173
if (LE_FAILURE(status)) {
177
if (scriptCode <= -1 || scriptCode >= scriptCodeCount) {
178
status = RFI_ILLEGAL_ARGUMENT_ERROR;
183
le_int32 fontIndex = fFontIndices[scriptCode];
186
sprintf(errorMessage, "No font was set for script %s", uscript_getName((UScriptCode) scriptCode));
187
fGUISupport->postErrorMessage(errorMessage, "Font Map Error");
188
status = RFI_FONT_FILE_NOT_FOUND_ERROR;
192
if (fFontInstances[fontIndex] == NULL) {
193
fFontInstances[fontIndex] = openFont(fFontNames[fontIndex], fPointSize, status);
195
if (LE_FAILURE(status)) {
196
sprintf(errorMessage, "Could not open font file %s", fFontNames[fontIndex]);
197
fGUISupport->postErrorMessage(errorMessage, "Font Map Error");
202
return fFontInstances[fontIndex];