55
56
m_fontSourceFileType(0),
56
57
m_fontNameLength(0),
59
60
_read(input, dataOffset, dataSize);
62
63
WP6FontDescriptorPacket::~WP6FontDescriptorPacket()
67
67
void WP6FontDescriptorPacket::_readContents(WPXInputStream *input)
69
// short sized characteristics
70
m_characterWidth = readU16(input);
71
m_ascenderHeight = readU16(input);
72
m_xHeight = readU16(input);
73
m_descenderHeight = readU16(input);
74
m_italicsAdjust = readU16(input);
75
// byte sized characteristics
76
m_primaryFamilyMemberId = readU8(input);
77
m_primaryFamilyId = readU8(input);
78
m_scriptingSystem = readU8(input);
79
m_primaryCharacterSet = readU8(input);
80
m_width = readU8(input);
81
m_weight = readU8(input);
82
m_attributes = readU8(input);
83
m_generalCharacteristics = readU8(input);
84
m_classification = readU8(input);
85
m_fill = readU8(input);
86
m_fontType = readU8(input);
87
m_fontSourceFileType = readU8(input);
89
m_fontNameLength = readU16(input);
92
if (m_fontNameLength > ((std::numeric_limits<uint16_t>::max)() / 2))
69
// short sized characteristics
70
m_characterWidth = readU16(input);
71
m_ascenderHeight = readU16(input);
72
m_xHeight = readU16(input);
73
m_descenderHeight = readU16(input);
74
m_italicsAdjust = readU16(input);
75
// byte sized characteristics
76
m_primaryFamilyMemberId = readU8(input);
77
m_primaryFamilyId = readU8(input);
78
m_scriptingSystem = readU8(input);
79
m_primaryCharacterSet = readU8(input);
80
m_width = readU8(input);
81
m_weight = readU8(input);
82
m_attributes = readU8(input);
83
m_generalCharacteristics = readU8(input);
84
m_classification = readU8(input);
85
m_fill = readU8(input);
86
m_fontType = readU8(input);
87
m_fontSourceFileType = readU8(input);
89
m_fontNameLength = readU16(input);
92
if (m_fontNameLength > ((std::numeric_limits<uint16_t>::max)() / 2))
93
93
m_fontNameLength = ((std::numeric_limits<uint16_t>::max)() / 2);
94
if (m_fontNameLength == 0)
96
m_fontName = new char[1];
102
m_fontName = new char[m_fontNameLength];
104
uint16_t tempLength=0;
106
int lastTokenPosition=0;
107
for (uint16_t i=0; i<(m_fontNameLength/2); i++)
109
uint16_t charWord = readU16(input);
111
uint8_t characterSet = (uint8_t)((charWord >> 8) & 0x00FF);
112
uint8_t character = (uint8_t)(charWord & 0xFF);
114
const uint16_t *chars;
115
extendedCharacterWP6ToUCS2(character, characterSet, &chars);
116
/* We are only using ascii characters here, and
117
* if we have more than one character, that's
118
* going to be an international character, so
119
* we don't actually iterate through the list of
120
* characters returned - we assume that just one
121
* character was returned.
123
if (chars[0] == 0x20) {
124
m_fontName[tempLength]=' ';
127
lastTokenPosition=tempLength;
129
else if (chars[0] != 0x00 && chars[0] < 0x7F) {
130
m_fontName[tempLength]=(char) chars[0];
134
m_fontName[tempLength]='\0';
135
// TODO/HACK: probably should create a proper static function for doing this
136
// consume the last token (by replacing the first char with a null-terminator) if its a weight signifier
137
// also remove annoying -WP postfix
138
// (NB: not all wp fonts are terminated by weight, just enough of them to make this annoying)
139
// NB: also this is O(n^2). Could be a performance hotspot.
140
WPD_DEBUG_MSG(("WordPerfect: stripping font name (original: %s)\n", m_fontName));
141
for (int stringPosition=(tempLength-1); stringPosition>=0; stringPosition--)
144
for (k=0; k<countElements(FONT_WEIGHT_STRINGS); k++)
146
if (stringPosition > 0 && !strcmp(FONT_WEIGHT_STRINGS[k], &m_fontName[stringPosition]))
148
m_fontName[stringPosition-1]='\0';
149
tempLength = (uint16_t)(stringPosition-1);
153
// SPECIAL CASE: eliminate the -WP postfix (if it's there), which isn't spaced out from
154
// the rest of the font
155
if (k==countElements(FONT_WEIGHT_STRINGS))
157
if (!strcmp(USELESS_WP_POSTFIX, &m_fontName[stringPosition]))
159
m_fontName[stringPosition]='\0';
160
tempLength = (uint16_t)(stringPosition - 1);
163
// also consume any whitespace at the end of the font..
164
while ((tempLength - 1) > 0 && m_fontName[tempLength-1] == ' ')
166
m_fontName[tempLength-1] = '\0';
169
WPD_DEBUG_MSG(("WordPerfect: stripping font name (final: %s)\n", m_fontName));
171
WPD_DEBUG_MSG(("WordPerfect: Read Font (primary family id: %i, family member id: %i, font type: %i, font source file type: %i font name length: %i, font name: %s)\n", (int) m_primaryFamilyId, (int) m_primaryFamilyMemberId, (int) m_fontType, (int) m_fontSourceFileType, (int) m_fontNameLength, m_fontName));
96
for (uint16_t i=0; i<(m_fontNameLength/2); i++)
98
uint16_t charWord = readU16(input);
99
uint8_t characterSet = (uint8_t)((charWord >> 8) & 0x00FF);
100
uint8_t character = (uint8_t)(charWord & 0xFF);
102
if (character == 0x00 && characterSet == 0x00)
105
const uint16_t *chars;
106
int len = extendedCharacterWP6ToUCS2(character, characterSet, &chars);
108
for (int j = 0; j < len; j++)
109
appendUCS4(m_fontName, (uint32_t)chars[j]);
112
WPD_DEBUG_MSG(("WordPerfect: stripping font name (original: %s)\n", m_fontName.cstr()));
113
std::string stringValue(m_fontName.cstr());
114
std::string::size_type pos;
115
for (unsigned k = 0; k < countElements(FONT_WEIGHT_STRINGS); k++)
117
if (!stringValue.empty())
118
while ((pos = stringValue.find(FONT_WEIGHT_STRINGS[k])) != std::string::npos)
119
stringValue.replace(pos, strlen(FONT_WEIGHT_STRINGS[k]),"");
121
// SPECIAL CASE: eliminate the -WP postfix (if it's there), which isn't spaced out from
122
// the rest of the font
123
if (!stringValue.empty())
124
while ((pos = stringValue.find(USELESS_WP_POSTFIX)) != std::string::npos)
125
stringValue.replace(pos, strlen(USELESS_WP_POSTFIX), "");
126
// also consume any whitespace at the end of the font.
127
if (!stringValue.empty())
128
while ((pos = stringValue.find(" ")) != std::string::npos)
129
stringValue.replace(pos, strlen(" "), " ");
130
if (!stringValue.empty())
131
while ((pos = stringValue.find(" ", stringValue.size() - 1)) != std::string::npos)
132
stringValue.replace(pos, strlen(" "), "");
133
if (!stringValue.empty())
134
while ((pos = stringValue.find("-", stringValue.size() - 1)) != std::string::npos)
135
stringValue.replace(pos, strlen("-"), "");
137
m_fontName = WPXString(stringValue.c_str());
138
WPD_DEBUG_MSG(("WordPerfect: stripping font name (final: %s)\n", m_fontName.cstr()));
140
WPD_DEBUG_MSG(("WordPerfect: Read Font (primary family id: %i, family member id: %i, font type: %i, font source file type: %i font name length: %i, font name: %s)\n",
141
(int) m_primaryFamilyId, (int) m_primaryFamilyMemberId, (int) m_fontType, (int) m_fontSourceFileType, (int) m_fontNameLength, m_fontName.cstr()));