| 1 | //#include <string.h> |
|---|
| 2 | #include "utfStruct.h" |
|---|
| 3 | #include "_utfDebugOn.hxx" |
|---|
| 4 | |
|---|
| 5 | #define _WT_VIRTUAL_HEADER_SIZE 80 |
|---|
| 6 | #define _UT_MAX_CMAP_LEN (0x10000 * 6) |
|---|
| 7 | |
|---|
| 8 | #ifdef _UT_USE_FONT_INFO_CACHE |
|---|
| 9 | #define UT_DEFINE_FONT_INFO_1(cap, temp_cap) UT_FONT* cap |
|---|
| 10 | #define UT_DEFINE_FONT_INFO_2(cap, temp_cap) UT_FONT_CAP* cap |
|---|
| 11 | #define utm_GetFontInfo_1(stream, face, cap) cap = &face->font.info |
|---|
| 12 | #define utm_GetFontInfo_2(stream, face, cap) cap = &face->font |
|---|
| 13 | #else /*#ifdef _UT_USE_FONT_INFO_CACHE*/ |
|---|
| 14 | #define UT_DEFINE_FONT_INFO_1(cap, temp_cap) UT_FONT temp_cap; UT_FONT* cap = &temp_cap |
|---|
| 15 | #define UT_DEFINE_FONT_INFO_2(cap, temp_cap) UT_FONT_CAP temp_cap; UT_FONT_CAP* cap = &temp_cap |
|---|
| 16 | #define utm_GetFontInfo_1(stream, face, cap) utm_GetFontCap(stream, cap, sizeof(UT_FONT)) |
|---|
| 17 | #define utm_GetFontInfo_2(stream, face, cap) utm_GetFontCap(stream, cap, sizeof(UT_FONT_CAP)) |
|---|
| 18 | #endif /*#ifdef _UT_USE_FONT_INFO_CACHE*/ |
|---|
| 19 | |
|---|
| 20 | /***************************************************************************/ |
|---|
| 21 | |
|---|
| 22 | #ifdef _UT_USE_BITMAP_ALL_TYPE |
|---|
| 23 | #define _UT_USE_BITMAP_IMG |
|---|
| 24 | #define _UT_USE_BITMAP_IMGP |
|---|
| 25 | #define _UT_USE_BITMAP_SBM |
|---|
| 26 | #define _UT_USE_BITMAP_SBMP |
|---|
| 27 | #define _UT_USE_BITMAP_LCD |
|---|
| 28 | #define _UT_USE_BITMAP_LCDR |
|---|
| 29 | #endif /*#ifdef _UT_USE_BITMAP_ALL_TYPE*/ |
|---|
| 30 | |
|---|
| 31 | /***************************************************************************/ |
|---|
| 32 | |
|---|
| 33 | #define ut_STREAM_OFFSET(stream, offset) ((stream)->basement+offset) |
|---|
| 34 | |
|---|
| 35 | UT_STATIC_API int utm_SbinarySearch_U32(UT_U32* data, int count, UT_U32 key) |
|---|
| 36 | { |
|---|
| 37 | int s = 0; |
|---|
| 38 | int e = count - 1; |
|---|
| 39 | int m; |
|---|
| 40 | if (ut_SWAP_U32(data[s]) == key) return s; |
|---|
| 41 | if (ut_SWAP_U32(data[e]) == key) return e; |
|---|
| 42 | for (;;) |
|---|
| 43 | { |
|---|
| 44 | m = (s + e) >> 1; |
|---|
| 45 | if (ut_SWAP_U32(data[m]) == key) return m; |
|---|
| 46 | if (s == m) return -1; |
|---|
| 47 | if (ut_SWAP_U32(data[m]) > key) e = m; |
|---|
| 48 | else s = m; |
|---|
| 49 | } |
|---|
| 50 | return -1; |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | UT_STATIC_API void ut_FreeFace(UT_FONT_MANAGER* fontManager, UT_FACE* face) |
|---|
| 54 | { |
|---|
| 55 | if (face->isVolatile) |
|---|
| 56 | { |
|---|
| 57 | if (fontManager->FreeMemory) fontManager->FreeMemory(face); |
|---|
| 58 | } |
|---|
| 59 | else face->stream.handle = 0; |
|---|
| 60 | } |
|---|
| 61 | |
|---|
| 62 | UT_STATIC_API UT_FACE* ut_AllocFace(UT_FONT_MANAGER* fontManager) |
|---|
| 63 | { |
|---|
| 64 | if (fontManager->staticFontBuffer && fontManager->staticFontBufferCount) |
|---|
| 65 | { |
|---|
| 66 | UT_FACE* face = fontManager->staticFontBuffer; |
|---|
| 67 | UT_FACE* stop = face + fontManager->staticFontBufferCount; |
|---|
| 68 | for (; face<stop; face++) |
|---|
| 69 | { |
|---|
| 70 | if (face->stream.handle) continue; |
|---|
| 71 | face->isVolatile = _UT_FALSE; |
|---|
| 72 | return face; |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | if (fontManager->AllocMemory) |
|---|
| 76 | { |
|---|
| 77 | UT_FACE* face = (UT_FACE*)fontManager->AllocMemory(sizeof(UT_FACE)); |
|---|
| 78 | if (face) |
|---|
| 79 | { |
|---|
| 80 | face->isVolatile = _UT_TRUE; |
|---|
| 81 | return face; |
|---|
| 82 | } |
|---|
| 83 | } |
|---|
| 84 | return 0; |
|---|
| 85 | } |
|---|
| 86 | |
|---|
| 87 | UT_STATIC_API void ut_FreeGridFitBuffer(UT_FONT_TASK* task) |
|---|
| 88 | { |
|---|
| 89 | UT_FONT_MANAGER* fontManager = task->fontManager; |
|---|
| 90 | if (task->gridFitBufferIsVolatile) |
|---|
| 91 | { |
|---|
| 92 | if (task->gridFitBuffer && fontManager->FreeMemory) fontManager->FreeMemory(task->gridFitBuffer); |
|---|
| 93 | task->gridFitBufferIsVolatile = _UT_FALSE; |
|---|
| 94 | } |
|---|
| 95 | task->gridFitBuffer = 0; |
|---|
| 96 | task->gridFitBufferSize = 0; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | UT_STATIC_API char* ut_AllocGridFitBuffer(UT_FONT_TASK* task, int size) |
|---|
| 100 | { |
|---|
| 101 | UT_FONT_MANAGER* fontManager = task->fontManager; |
|---|
| 102 | UT_TRACE2("ut_AllocGridFitBuffer(size = %d)", size); |
|---|
| 103 | if (size < task->staticRasterBufferSize) |
|---|
| 104 | { |
|---|
| 105 | ut_FreeGridFitBuffer(task); |
|---|
| 106 | task->gridFitBufferSize = size; |
|---|
| 107 | task->gridFitBufferIsVolatile = _UT_FALSE; |
|---|
| 108 | return task->staticRasterBuffer; |
|---|
| 109 | } |
|---|
| 110 | if (fontManager->AllocMemory) |
|---|
| 111 | { |
|---|
| 112 | if (task->gridFitBufferSize < size) |
|---|
| 113 | { |
|---|
| 114 | ut_FreeGridFitBuffer(task); |
|---|
| 115 | task->gridFitBuffer = (char*)fontManager->AllocMemory(size); |
|---|
| 116 | task->gridFitBufferSize = size; |
|---|
| 117 | task->gridFitBufferIsVolatile = _UT_TRUE; |
|---|
| 118 | } |
|---|
| 119 | return task->gridFitBuffer; |
|---|
| 120 | } |
|---|
| 121 | return 0; |
|---|
| 122 | } |
|---|
| 123 | |
|---|
| 124 | void utm_FreeScanBuffer(UT_FONT_TASK* task) |
|---|
| 125 | { |
|---|
| 126 | UT_FONT_MANAGER* fontManager = task->fontManager; |
|---|
| 127 | if (task->scanBufferIsVolatile) |
|---|
| 128 | { |
|---|
| 129 | if (task->scanBuffer && fontManager->FreeMemory) fontManager->FreeMemory(task->scanBuffer); |
|---|
| 130 | task->scanBufferIsVolatile = _UT_FALSE; |
|---|
| 131 | } |
|---|
| 132 | task->scanBuffer = 0; |
|---|
| 133 | task->scanBufferSize = 0; |
|---|
| 134 | } |
|---|
| 135 | |
|---|
| 136 | char* ut_AllocScanBuffer(UT_FONT_TASK* task, UT_IMAGE* image, int size) |
|---|
| 137 | { |
|---|
| 138 | UT_FONT_MANAGER* fontManager = task->fontManager; |
|---|
| 139 | UT_TRACE2("ut_AllocScanBuffer(size = %d)", size); |
|---|
| 140 | UT_TRACE2(" image->lSize = %d", image->lSize); |
|---|
| 141 | size += ((image->lSize+3)>>2)<<2; |
|---|
| 142 | UT_TRACE2(" total size = %d", size); |
|---|
| 143 | if (size < task->staticRasterBufferSize-task->gridFitBufferSize) |
|---|
| 144 | { |
|---|
| 145 | utm_FreeScanBuffer(task); |
|---|
| 146 | task->scanBufferIsVolatile = _UT_FALSE; |
|---|
| 147 | image->data = (unsigned char*)(task->staticRasterBuffer+task->gridFitBufferSize); |
|---|
| 148 | } |
|---|
| 149 | if (fontManager->AllocMemory) |
|---|
| 150 | { |
|---|
| 151 | if (task->scanBufferSize < size) |
|---|
| 152 | { |
|---|
| 153 | utm_FreeScanBuffer(task); |
|---|
| 154 | task->scanBuffer = (char*)fontManager->AllocMemory(size); |
|---|
| 155 | task->scanBufferSize = size; |
|---|
| 156 | task->scanBufferIsVolatile = _UT_TRUE; |
|---|
| 157 | } |
|---|
| 158 | image->data = (unsigned char*)task->scanBuffer; |
|---|
| 159 | } |
|---|
| 160 | if (!image->data) return 0; |
|---|
| 161 | return ((char*)image->data) + (((image->lSize+3)>>2)<<2); |
|---|
| 162 | } |
|---|
| 163 | |
|---|
| 164 | UT_STATIC_API void ut_FreeCmapBuffer(UT_FC* fc) |
|---|
| 165 | { |
|---|
| 166 | UT_FONT_MANAGER* fontManager = fc->task->fontManager; |
|---|
| 167 | if (fc->cmapBufferIsVolatile) |
|---|
| 168 | { |
|---|
| 169 | if (fc->cmapBuffer && fontManager->FreeMemory) fontManager->FreeMemory(fc->cmapBuffer); |
|---|
| 170 | fc->cmapBufferIsVolatile = _UT_FALSE; |
|---|
| 171 | } |
|---|
| 172 | fc->cmapBuffer = 0; |
|---|
| 173 | fc->cmapBufferSize = 0; |
|---|
| 174 | } |
|---|
| 175 | |
|---|
| 176 | UT_STATIC_API char* ut_AllocCmapBuffer(UT_FC* fc, int size) |
|---|
| 177 | { |
|---|
| 178 | UT_FONT_MANAGER* fontManager = fc->task->fontManager; |
|---|
| 179 | UT_TRACE2("ut_AllocCmapBuffer(size = %d)", size); |
|---|
| 180 | if (size < fc->staticCmapBufferSize) |
|---|
| 181 | { |
|---|
| 182 | ut_FreeCmapBuffer(fc); |
|---|
| 183 | fc->cmapBuffer = fc->staticCmapBuffer; |
|---|
| 184 | fc->cmapBufferSize = size; |
|---|
| 185 | fc->cmapBufferIsVolatile = _UT_FALSE; |
|---|
| 186 | return fc->cmapBuffer; |
|---|
| 187 | } |
|---|
| 188 | if (fontManager->AllocMemory) |
|---|
| 189 | { |
|---|
| 190 | if (fc->cmapBufferSize < size) |
|---|
| 191 | { |
|---|
| 192 | ut_FreeCmapBuffer(fc); |
|---|
| 193 | fc->cmapBuffer = (char*)fontManager->AllocMemory(size); |
|---|
| 194 | fc->cmapBufferSize = size; |
|---|
| 195 | fc->cmapBufferIsVolatile = _UT_TRUE; |
|---|
| 196 | } |
|---|
| 197 | return fc->cmapBuffer; |
|---|
| 198 | } |
|---|
| 199 | return 0; |
|---|
| 200 | } |
|---|
| 201 | |
|---|
| 202 | #if defined(_UT_USE_KS_CODE) && defined(_UT_USE_STOCK_FNT_KS_2_UNI_CODE) |
|---|
| 203 | #include "_utfKS2UNI.cxx" |
|---|
| 204 | #else |
|---|
| 205 | #define ut_InitKsToUniCode(fontManager) |
|---|
| 206 | #endif |
|---|
| 207 | |
|---|
| 208 | /***************************************************************************/ |
|---|
| 209 | |
|---|
| 210 | UT_STATIC_API void ut_GetGlyphMetric_FIXED(UT_CMAP* cmap, UT_TABLE* table, int index, UT_DATA* data, int* metric) |
|---|
| 211 | { |
|---|
| 212 | UT_TRACE1("ut_GetGlyphMetric_FIXED()"); |
|---|
| 213 | *metric = ut_SWAP_I16(table->fixed); |
|---|
| 214 | UT_TRACE2(" metric = %d", *metric); |
|---|
| 215 | } |
|---|
| 216 | |
|---|
| 217 | UT_STATIC_API void ut_GetGlyphMetric_VARIABLE_BYTE(UT_CMAP* cmap, UT_TABLE* table, int index, UT_DATA* data, int* metric) |
|---|
| 218 | { |
|---|
| 219 | UT_TRACE1("ut_GetGlyphMetric_VARIABLE_BYTE()"); |
|---|
| 220 | *metric = *data->p.i8++; |
|---|
| 221 | UT_TRACE2(" metric = %d", *metric); |
|---|
| 222 | } |
|---|
| 223 | |
|---|
| 224 | UT_STATIC_API void ut_GetGlyphMetric_VARIABLE_SHORT(UT_CMAP* cmap, UT_TABLE* table, int index, UT_DATA* data, int* metric) |
|---|
| 225 | { |
|---|
| 226 | UT_TRACE1("ut_GetGlyphMetric_VARIABLE_SHORT()"); |
|---|
| 227 | *metric = (data->p.i8[0] << 8) | data->p.u8[1]; |
|---|
| 228 | data->p.p += 2; |
|---|
| 229 | UT_TRACE2(" metric = %d", *metric); |
|---|
| 230 | } |
|---|
| 231 | |
|---|
| 232 | UT_STATIC_API void ut_GetGlyphMetric_JOHAP(UT_CMAP* cmap, UT_TABLE* table, int index, UT_DATA* data, int* metric) |
|---|
| 233 | { |
|---|
| 234 | UT_METX_JOHAP* fmt = (UT_METX_JOHAP*)(((char*)cmap) + ut_SWAP_U32(table->offset)); |
|---|
| 235 | int c0, c1, c2, g0, g1, g2, i = index; |
|---|
| 236 | c0 = i / (21*28); i %= (21*28); |
|---|
| 237 | c1 = i / 28; |
|---|
| 238 | c2 = i % 28; |
|---|
| 239 | g0 = fmt->groupMap[0][c0]; |
|---|
| 240 | g1 = fmt->groupMap[1][c1]; |
|---|
| 241 | g2 = fmt->groupMap[2][c2]; |
|---|
| 242 | i = (g0*fmt->nGroup[1]+g1)*fmt->nGroup[2]+g2; |
|---|
| 243 | if (fmt->isByte) *metric = fmt->value.b[i]; |
|---|
| 244 | UT_TRACE1("ut_GetGlyphMetric_JOHAP()"); |
|---|
| 245 | } |
|---|
| 246 | |
|---|
| 247 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 248 | #define ut_GetGlyphMetricFnt fontManager->GetGlyphMetricFnt |
|---|
| 249 | #define SET_VALUE(index, value) ut_GetGlyphMetricFnt[index] = value |
|---|
| 250 | UT_STATIC_API void ut_InitGetGlyphMetricFnt(UT_FONT_MANAGER* fontManager) |
|---|
| 251 | { |
|---|
| 252 | #else |
|---|
| 253 | #define SET_VALUE(index, value) value |
|---|
| 254 | #define ut_InitGetGlyphMetricFnt(fontManager) |
|---|
| 255 | static void (*ut_GetGlyphMetricFnt[])(UT_CMAP* cmap, UT_TABLE* table, int index, UT_DATA* data, int* metric) = |
|---|
| 256 | { |
|---|
| 257 | #endif |
|---|
| 258 | SET_VALUE(0, ut_GetGlyphMetric_FIXED), |
|---|
| 259 | SET_VALUE(1, ut_GetGlyphMetric_VARIABLE_BYTE), |
|---|
| 260 | SET_VALUE(2, ut_GetGlyphMetric_VARIABLE_SHORT), |
|---|
| 261 | SET_VALUE(3, ut_GetGlyphMetric_JOHAP) |
|---|
| 262 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 263 | ;} |
|---|
| 264 | #else |
|---|
| 265 | }; |
|---|
| 266 | #endif |
|---|
| 267 | #undef SET_VALUE |
|---|
| 268 | |
|---|
| 269 | /***************************************************************************/ |
|---|
| 270 | |
|---|
| 271 | UT_STATIC_API void ut_GetGlyphBbox_NO(UT_CMAP* cmap, UT_DATA* data) |
|---|
| 272 | { |
|---|
| 273 | UT_TRACE1("ut_GetGlyphBbox_NO()"); |
|---|
| 274 | } |
|---|
| 275 | |
|---|
| 276 | UT_STATIC_API void ut_GetGlyphBbox_X(UT_CMAP* cmap, UT_DATA* data) |
|---|
| 277 | { |
|---|
| 278 | data->bbox.ox = *data->p.i8++; |
|---|
| 279 | data->bbox.oy = cmap->depend.bbox.oy; |
|---|
| 280 | data->bbox.sx = *data->p.u8++; |
|---|
| 281 | data->bbox.sy = cmap->depend.bbox.sy; |
|---|
| 282 | UT_TRACE1("ut_GetGlyphBbox_X()"); |
|---|
| 283 | UT_TRACE2(" data->bbox.ox = %d", data->bbox.ox); |
|---|
| 284 | UT_TRACE2(" data->bbox.oy = %d", data->bbox.oy); |
|---|
| 285 | UT_TRACE2(" data->bbox.sx = %d", data->bbox.sx); |
|---|
| 286 | UT_TRACE2(" data->bbox.sy = %d", data->bbox.sy); |
|---|
| 287 | } |
|---|
| 288 | |
|---|
| 289 | UT_STATIC_API void ut_GetGlyphBbox_Y(UT_CMAP* cmap, UT_DATA* data) |
|---|
| 290 | { |
|---|
| 291 | data->bbox.ox = cmap->depend.bbox.ox; |
|---|
| 292 | data->bbox.oy = *data->p.i8++; |
|---|
| 293 | data->bbox.sx = cmap->depend.bbox.sx; |
|---|
| 294 | data->bbox.sy = *data->p.u8++; |
|---|
| 295 | UT_TRACE1("ut_GetGlyphBbox_Y()"); |
|---|
| 296 | UT_TRACE2(" data->bbox.ox = %d", data->bbox.ox); |
|---|
| 297 | UT_TRACE2(" data->bbox.oy = %d", data->bbox.oy); |
|---|
| 298 | UT_TRACE2(" data->bbox.sx = %d", data->bbox.sx); |
|---|
| 299 | UT_TRACE2(" data->bbox.sy = %d", data->bbox.sy); |
|---|
| 300 | } |
|---|
| 301 | |
|---|
| 302 | UT_STATIC_API void ut_GetGlyphBbox_1(UT_CMAP* cmap, UT_DATA* data) |
|---|
| 303 | { |
|---|
| 304 | UT_TRACE1("ut_GetGlyphBbox_1()"); |
|---|
| 305 | data->bbox.ox = *data->p.i8++; |
|---|
| 306 | data->bbox.oy = *data->p.i8++; |
|---|
| 307 | data->bbox.sx = *data->p.u8++; |
|---|
| 308 | data->bbox.sy = *data->p.u8++; |
|---|
| 309 | UT_TRACE2(" data->bbox.ox = %d", data->bbox.ox); |
|---|
| 310 | UT_TRACE2(" data->bbox.oy = %d", data->bbox.oy); |
|---|
| 311 | UT_TRACE2(" data->bbox.sx = %d", data->bbox.sx); |
|---|
| 312 | UT_TRACE2(" data->bbox.sy = %d", data->bbox.sy); |
|---|
| 313 | } |
|---|
| 314 | |
|---|
| 315 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 316 | #define ut_GetGlyphBboxFnt fontManager->GetGlyphBboxFnt |
|---|
| 317 | #define SET_VALUE(index, value) ut_GetGlyphBboxFnt[index] = value |
|---|
| 318 | UT_STATIC_API void ut_InitGetGlyphBboxFnt(UT_FONT_MANAGER* fontManager) |
|---|
| 319 | { |
|---|
| 320 | #else |
|---|
| 321 | #define SET_VALUE(index, value) value |
|---|
| 322 | #define ut_InitGetGlyphBboxFnt(fontManager) |
|---|
| 323 | static void (*ut_GetGlyphBboxFnt[])(UT_CMAP* cmap, UT_DATA* data) = |
|---|
| 324 | { |
|---|
| 325 | #endif |
|---|
| 326 | SET_VALUE(0, ut_GetGlyphBbox_NO), |
|---|
| 327 | SET_VALUE(1, ut_GetGlyphBbox_1), |
|---|
| 328 | SET_VALUE(2, ut_GetGlyphBbox_X), |
|---|
| 329 | SET_VALUE(3, ut_GetGlyphBbox_Y) |
|---|
| 330 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 331 | ;} |
|---|
| 332 | #else |
|---|
| 333 | }; |
|---|
| 334 | #endif |
|---|
| 335 | #undef SET_VALUE |
|---|
| 336 | |
|---|
| 337 | /***************************************************************************/ |
|---|
| 338 | |
|---|
| 339 | UT_STATIC_API void ut_ReadGlyphData(UT_FONT_STREAM* stream, UT_CMAP* cmap, int offset, int length, UT_DATA* data) |
|---|
| 340 | { |
|---|
| 341 | if (stream->Read) |
|---|
| 342 | { |
|---|
| 343 | stream->Read(stream->handle, ut_STREAM_OFFSET(stream,cmap->glyfOffset+offset), length, data->temp); |
|---|
| 344 | data->p.p = data->temp; |
|---|
| 345 | } |
|---|
| 346 | else |
|---|
| 347 | { |
|---|
| 348 | data->p.p = ut_GLYF(cmap, offset); |
|---|
| 349 | } |
|---|
| 350 | data->end.p = data->p.p + length; |
|---|
| 351 | data->xOffset = 0; |
|---|
| 352 | } |
|---|
| 353 | |
|---|
| 354 | UT_STATIC_API int ut_GetGlyphData_FIXED(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, int index, UT_GLYPH* glyph) |
|---|
| 355 | { |
|---|
| 356 | UT_DATA* data = glyph->data + glyph->count; |
|---|
| 357 | UT_U32 length = ut_SWAP_U16(cmap->loca.fixed); |
|---|
| 358 | UT_TRACE1("ut_GetGlyphData_FIXED()"); |
|---|
| 359 | UT_TRACE_TAB_INC(); |
|---|
| 360 | UT_TRACE2("length = %d", length); |
|---|
| 361 | ut_ReadGlyphData(stream, cmap, length*index, length, data); |
|---|
| 362 | if (index >= 0) |
|---|
| 363 | { |
|---|
| 364 | ut_GetGlyphMetricFnt[cmap->widthFormat](cmap, &cmap->width, index, data, &glyph->width); |
|---|
| 365 | ut_GetGlyphMetricFnt[cmap->heightFormat](cmap, &cmap->height, index, data, &glyph->height); |
|---|
| 366 | } |
|---|
| 367 | data->bbox.ox = cmap->depend.bbox.ox; |
|---|
| 368 | data->bbox.oy = cmap->depend.bbox.oy; |
|---|
| 369 | data->bbox.sx = cmap->depend.bbox.sx; |
|---|
| 370 | data->bbox.sy = cmap->depend.bbox.sy; |
|---|
| 371 | UT_TRACE2("data->bbox.ox = %d", data->bbox.ox); |
|---|
| 372 | UT_TRACE2("data->bbox.oy = %d", data->bbox.oy); |
|---|
| 373 | UT_TRACE2("data->bbox.sx = %d", data->bbox.sx); |
|---|
| 374 | UT_TRACE2("data->bbox.sy = %d", data->bbox.sy); |
|---|
| 375 | UT_TRACE_TAB_DEC(); |
|---|
| 376 | return data->end.p - data->p.p; |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | UT_STATIC_API int ut_GetGlyphData_SHORT(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, int index, UT_GLYPH* glyph) |
|---|
| 380 | { |
|---|
| 381 | UT_DATA* data = glyph->data + glyph->count; |
|---|
| 382 | UT_LOCA_SHORT* loca = (UT_LOCA_SHORT*)ut_LOCA(cmap); |
|---|
| 383 | UT_U32 offset = ut_SWAP_U16(loca->offset[index]); |
|---|
| 384 | UT_U32 length = ut_SWAP_U16(loca->offset[index+1]) - offset; |
|---|
| 385 | UT_TRACE1("ut_GetGlyphData_SHORT()"); |
|---|
| 386 | UT_TRACE_TAB_INC(); |
|---|
| 387 | UT_TRACE2("offset = %d", offset); |
|---|
| 388 | UT_TRACE2("length = %d", length); |
|---|
| 389 | if (!length) |
|---|
| 390 | { |
|---|
| 391 | if (cmap->widthFormat == _UT_METX_FIXED) |
|---|
| 392 | { |
|---|
| 393 | ut_GetGlyphMetricFnt[cmap->widthFormat](cmap, &cmap->width, index, data, &glyph->width); |
|---|
| 394 | } |
|---|
| 395 | else glyph->width = 0; |
|---|
| 396 | if (cmap->heightFormat == _UT_METX_FIXED) |
|---|
| 397 | { |
|---|
| 398 | ut_GetGlyphMetricFnt[cmap->heightFormat](cmap, &cmap->height, index, data, &glyph->height); |
|---|
| 399 | } |
|---|
| 400 | else glyph->height = 0; |
|---|
| 401 | UT_TRACE_TAB_DEC(); |
|---|
| 402 | return 0; |
|---|
| 403 | } |
|---|
| 404 | ut_ReadGlyphData(stream, cmap, offset, length, data); |
|---|
| 405 | if (index >= 0) |
|---|
| 406 | { |
|---|
| 407 | ut_GetGlyphMetricFnt[cmap->widthFormat](cmap, &cmap->width, index, data, &glyph->width); |
|---|
| 408 | ut_GetGlyphMetricFnt[cmap->heightFormat](cmap, &cmap->height, index, data, &glyph->height); |
|---|
| 409 | } |
|---|
| 410 | ut_GetGlyphBboxFnt[cmap->glyphBBoxType](cmap, data); |
|---|
| 411 | UT_TRACE_TAB_DEC(); |
|---|
| 412 | return data->end.p - data->p.p; |
|---|
| 413 | } |
|---|
| 414 | |
|---|
| 415 | UT_STATIC_API int ut_GetGlyphData_LONG(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, int index, UT_GLYPH* glyph) |
|---|
| 416 | { |
|---|
| 417 | UT_DATA* data = glyph->data + glyph->count; |
|---|
| 418 | UT_LOCA_LONG* loca = (UT_LOCA_LONG*)ut_LOCA(cmap); |
|---|
| 419 | UT_U32 offset = ut_SWAP_U32(loca->offset[index]); |
|---|
| 420 | UT_U32 length = ut_SWAP_U32(loca->offset[index+1]) - offset; |
|---|
| 421 | UT_TRACE1("ut_GetGlyphData_LONG()"); |
|---|
| 422 | UT_TRACE_TAB_INC(); |
|---|
| 423 | UT_TRACE2("offset = %d", offset); |
|---|
| 424 | UT_TRACE2("length = %d", length); |
|---|
| 425 | if (!length) |
|---|
| 426 | { |
|---|
| 427 | if (cmap->widthFormat == _UT_METX_FIXED) |
|---|
| 428 | { |
|---|
| 429 | ut_GetGlyphMetricFnt[cmap->widthFormat](cmap, &cmap->width, index, data, &glyph->width); |
|---|
| 430 | } |
|---|
| 431 | else glyph->width = 0; |
|---|
| 432 | if (cmap->heightFormat == _UT_METX_FIXED) |
|---|
| 433 | { |
|---|
| 434 | ut_GetGlyphMetricFnt[cmap->heightFormat](cmap, &cmap->height, index, data, &glyph->height); |
|---|
| 435 | } |
|---|
| 436 | else glyph->height = 0; |
|---|
| 437 | UT_TRACE_TAB_DEC(); |
|---|
| 438 | return 0; |
|---|
| 439 | } |
|---|
| 440 | ut_ReadGlyphData(stream, cmap, offset, length, data); |
|---|
| 441 | if (index >= 0) |
|---|
| 442 | { |
|---|
| 443 | ut_GetGlyphMetricFnt[cmap->widthFormat](cmap, &cmap->width, index, data, &glyph->width); |
|---|
| 444 | ut_GetGlyphMetricFnt[cmap->heightFormat](cmap, &cmap->height, index, data, &glyph->height); |
|---|
| 445 | } |
|---|
| 446 | ut_GetGlyphBboxFnt[cmap->glyphBBoxType](cmap, data); |
|---|
| 447 | UT_TRACE_TAB_DEC(); |
|---|
| 448 | return data->end.p - data->p.p; |
|---|
| 449 | } |
|---|
| 450 | |
|---|
| 451 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 452 | #define ut_GetGlyphDataFnt fontManager->GetGlyphDataFnt |
|---|
| 453 | #define SET_VALUE(index, value) ut_GetGlyphDataFnt[index] = value |
|---|
| 454 | UT_STATIC_API void ut_InitGetGlyphDataFnt(UT_FONT_MANAGER* fontManager) |
|---|
| 455 | { |
|---|
| 456 | #else |
|---|
| 457 | #define SET_VALUE(index, value) value |
|---|
| 458 | #define ut_InitGetGlyphDataFnt(fontManager) |
|---|
| 459 | static int (*ut_GetGlyphDataFnt[])(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, int index, UT_GLYPH* glyph) = |
|---|
| 460 | { |
|---|
| 461 | #endif |
|---|
| 462 | SET_VALUE(0, ut_GetGlyphData_FIXED), |
|---|
| 463 | SET_VALUE(1, ut_GetGlyphData_SHORT), |
|---|
| 464 | SET_VALUE(2, ut_GetGlyphData_LONG) |
|---|
| 465 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 466 | ;} |
|---|
| 467 | #else |
|---|
| 468 | }; |
|---|
| 469 | #endif |
|---|
| 470 | #undef SET_VALUE |
|---|
| 471 | |
|---|
| 472 | /***************************************************************************/ |
|---|
| 473 | |
|---|
| 474 | UT_BOOL ut_GetIndexedGlyph(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, int index, UT_GLYPH* glyph) |
|---|
| 475 | { |
|---|
| 476 | return ut_GetGlyphDataFnt[cmap->locaFormat](fontManager, stream, cmap, index, glyph); |
|---|
| 477 | } |
|---|
| 478 | |
|---|
| 479 | UT_STATIC_API UT_BOOL ut_GetGlyph_CONTINUOUS(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, UT_CODE code, UT_GLYPH* glyph) |
|---|
| 480 | { |
|---|
| 481 | UT_U16 index = code - ut_SWAP_U16(cmap->startCode); |
|---|
| 482 | UT_TRACE1("ut_GetGlyph_CONTINUOUS()"); |
|---|
| 483 | UT_TRACE_TAB_INC(); |
|---|
| 484 | UT_TRACE2("index = %d", index); |
|---|
| 485 | if (ut_GetGlyphDataFnt[cmap->locaFormat](fontManager, stream, cmap, index, glyph)) glyph->count++; |
|---|
| 486 | UT_TRACE_TAB_DEC(); |
|---|
| 487 | return _UT_TRUE; |
|---|
| 488 | } |
|---|
| 489 | |
|---|
| 490 | UT_STATIC_API UT_BOOL ut_GetGlyph_BLOCK(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, UT_CODE code, UT_GLYPH* glyph) |
|---|
| 491 | { |
|---|
| 492 | int hi_f = ut_SWAP_U16(cmap->startCode) >> 8; |
|---|
| 493 | int lo_f = ut_SWAP_U16(cmap->startCode) & 255; |
|---|
| 494 | // int hi_t = ut_SWAP_U16(cmap->endCode) >> 8; |
|---|
| 495 | int lo_t = ut_SWAP_U16(cmap->endCode) & 255; |
|---|
| 496 | int hi = code >> 8; |
|---|
| 497 | int lo = code & 255; |
|---|
| 498 | int index; |
|---|
| 499 | if ((lo < lo_f) || (lo > lo_t)) return _UT_FALSE; |
|---|
| 500 | index = (hi - hi_f) * (lo_t - lo_f + 1) + (lo - lo_f); |
|---|
| 501 | UT_TRACE1("ut_GetGlyph_BLOCK()"); |
|---|
| 502 | UT_TRACE_TAB_INC(); |
|---|
| 503 | UT_TRACE2("hi_f = 0x%02x", hi_f); |
|---|
| 504 | UT_TRACE2("lo_f = 0x%02x", lo_f); |
|---|
| 505 | UT_TRACE2("hi_t = 0x%02x", hi_t); |
|---|
| 506 | UT_TRACE2("lo_t = 0x%02x", lo_t); |
|---|
| 507 | UT_TRACE2("hi = 0x%02x", hi); |
|---|
| 508 | UT_TRACE2("lo = 0x%02x", lo); |
|---|
| 509 | UT_TRACE2("index = %d", index); |
|---|
| 510 | if (ut_GetGlyphDataFnt[cmap->locaFormat](fontManager, stream, cmap, index, glyph)) glyph->count++; |
|---|
| 511 | UT_TRACE_TAB_DEC(); |
|---|
| 512 | return _UT_TRUE; |
|---|
| 513 | } |
|---|
| 514 | |
|---|
| 515 | UT_STATIC_API UT_BOOL ut_GetGlyph_SPARSE(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, UT_CODE code, UT_GLYPH* glyph) |
|---|
| 516 | { |
|---|
| 517 | UT_CMAP_SPARSE* fmt = (UT_CMAP_SPARSE*)cmap; |
|---|
| 518 | int index, count = ut_SWAP_U16(fmt->count); |
|---|
| 519 | UT_TRACE1("ut_GetGlyph_SPARSE()"); |
|---|
| 520 | UT_TRACE_TAB_INC(); |
|---|
| 521 | for (index=0; index<count; index++) |
|---|
| 522 | { |
|---|
| 523 | if (ut_SWAP_U16(fmt->code[index]) == code) |
|---|
| 524 | { |
|---|
| 525 | UT_TRACE2("index = %d", index); |
|---|
| 526 | if (ut_GetGlyphDataFnt[cmap->locaFormat](fontManager, stream, cmap, index, glyph)) glyph->count++; |
|---|
| 527 | UT_TRACE_TAB_DEC(); |
|---|
| 528 | return _UT_TRUE; |
|---|
| 529 | } |
|---|
| 530 | } |
|---|
| 531 | UT_TRACE_TAB_DEC(); |
|---|
| 532 | return _UT_FALSE; |
|---|
| 533 | } |
|---|
| 534 | |
|---|
| 535 | UT_STATIC_API UT_BOOL ut_GetGlyph_MAPPING(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, UT_CODE code, UT_GLYPH* glyph) |
|---|
| 536 | { |
|---|
| 537 | UT_CMAP_MAPPING* fmt = (UT_CMAP_MAPPING*)cmap; |
|---|
| 538 | int hi_f = ut_SWAP_U16(cmap->startCode) >> 8; |
|---|
| 539 | int lo_f = ut_SWAP_U16(cmap->startCode) & 255; |
|---|
| 540 | int hi_t = ut_SWAP_U16(cmap->endCode) >> 8; |
|---|
| 541 | int lo_t = ut_SWAP_U16(cmap->endCode) & 255; |
|---|
| 542 | int hi = code >> 8; |
|---|
| 543 | int lo = code & 255; |
|---|
| 544 | int index = hi - hi_f; |
|---|
| 545 | UT_TRACE1("ut_GetGlyph_MAPPING()"); |
|---|
| 546 | UT_TRACE_TAB_INC(); |
|---|
| 547 | UT_TRACE2("hi_f = 0x%02x", hi_f); |
|---|
| 548 | UT_TRACE2("lo_f = 0x%02x", lo_f); |
|---|
| 549 | UT_TRACE2("hi_t = 0x%02x", hi_t); |
|---|
| 550 | UT_TRACE2("lo_t = 0x%02x", lo_t); |
|---|
| 551 | UT_TRACE2("hi = %d", hi); |
|---|
| 552 | UT_TRACE2("lo = %d", lo); |
|---|
| 553 | if ((lo < lo_f) || (lo > lo_t)) |
|---|
| 554 | { |
|---|
| 555 | UT_TRACE_TAB_DEC(); |
|---|
| 556 | return _UT_FALSE; |
|---|
| 557 | } |
|---|
| 558 | UT_TRACE2("fmt->hiHash[index] = %d", fmt->hiHash[index]); |
|---|
| 559 | UT_TRACE2("fmt->hiHash[index+1] = %d", fmt->hiHash[index+1]); |
|---|
| 560 | if (fmt->hiHash[index] == fmt->hiHash[index+1]) |
|---|
| 561 | { |
|---|
| 562 | UT_TRACE_TAB_DEC(); |
|---|
| 563 | return _UT_FALSE; |
|---|
| 564 | } |
|---|
| 565 | index = fmt->hiHash[index] * (lo_t - lo_f + 1) + (lo - lo_f); |
|---|
| 566 | UT_TRACE2("index = %d", index); |
|---|
| 567 | if (cmap->locaFormat == _UT_LOCA_FIXED) |
|---|
| 568 | { |
|---|
| 569 | UT_POINTER p; |
|---|
| 570 | p.u8 = fmt->hiHash + ((((hi_t-hi_f+1)+2)>>1)<<1); |
|---|
| 571 | UT_TRACE2("p.u16[index] = %d", p.u16[index]); |
|---|
| 572 | UT_TRACE2("p.u16[index+1] = %d", p.u16[index+1]); |
|---|
| 573 | if (p.u16[index] == p.u16[index+1]) |
|---|
| 574 | { |
|---|
| 575 | UT_TRACE_TAB_DEC(); |
|---|
| 576 | return _UT_FALSE; |
|---|
| 577 | } |
|---|
| 578 | index = ut_SWAP_U16(p.u16[index]); |
|---|
| 579 | UT_TRACE2("index = %d", index); |
|---|
| 580 | } |
|---|
| 581 | if (ut_GetGlyphDataFnt[cmap->locaFormat](fontManager, stream, cmap, index, glyph)) glyph->count++; |
|---|
| 582 | UT_TRACE_TAB_DEC(); |
|---|
| 583 | return _UT_TRUE; |
|---|
| 584 | } |
|---|
| 585 | |
|---|
| 586 | UT_STATIC_API UT_BOOL ut_GetGlyph_JOHAP_1(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, UT_CODE code, UT_GLYPH* glyph) |
|---|
| 587 | { |
|---|
| 588 | UT_CMAP_JOHAP_1* fmt = (UT_CMAP_JOHAP_1*)cmap; |
|---|
| 589 | int s, g0, g1, g2, c[3], i, index; |
|---|
| 590 | UT_TRACE1("ut_GetGlyph_JOHAP_1()"); |
|---|
| 591 | UT_TRACE_TAB_INC(); |
|---|
| 592 | #ifdef _UT_USE_KS_CODE |
|---|
| 593 | if (fmt->level == _UT_CMAP_JOHAP_LEVEL_KS_2350) |
|---|
| 594 | { |
|---|
| 595 | UT_TRACE2("code1 = 0x%04x", code); |
|---|
| 596 | code = ut_cbKsToUniCode(fontManager, code); |
|---|
| 597 | UT_TRACE2("code = 0x%04x", code); |
|---|
| 598 | UT_TRACE2("code2 = 0x%04x", code); |
|---|
| 599 | if (code == (UT_CODE)-1) |
|---|
| 600 | { |
|---|
| 601 | UT_TRACE_TAB_DEC(); |
|---|
| 602 | return _UT_FALSE; |
|---|
| 603 | } |
|---|
| 604 | index = code - 0xac00; |
|---|
| 605 | UT_TRACE2("index = %d", index); |
|---|
| 606 | } |
|---|
| 607 | else |
|---|
| 608 | #endif |
|---|
| 609 | index = code - ut_SWAP_U16(cmap->startCode); |
|---|
| 610 | UT_TRACE2("index = %d", index); |
|---|
| 611 | i = index; |
|---|
| 612 | c[0] = i / (21*28); i %= (21*28); |
|---|
| 613 | c[1] = i / 28; |
|---|
| 614 | c[2] = i % 28; |
|---|
| 615 | UT_TRACE2("c[0] = %d", c[0]); |
|---|
| 616 | UT_TRACE2("c[1] = %d", c[1]); |
|---|
| 617 | UT_TRACE2("c[2] = %d", c[2]); |
|---|
| 618 | for (s=c[2]?2:1; s>=0; s--) |
|---|
| 619 | { |
|---|
| 620 | UT_TRACE2("s = %d", s); |
|---|
| 621 | UT_TRACE_TAB_INC(); |
|---|
| 622 | g0 = fmt->groupMap[s][0][c[0]]; |
|---|
| 623 | g1 = fmt->groupMap[s][1][c[1]]; |
|---|
| 624 | g2 = fmt->groupMap[s][2][c[2]]; |
|---|
| 625 | UT_TRACE2("g0 = %d", g0); |
|---|
| 626 | UT_TRACE2("g1 = %d", g1); |
|---|
| 627 | UT_TRACE2("g2 = %d", g2); |
|---|
| 628 | i = ut_SWAP_U16(fmt->valueBase[s]) + (g0*fmt->nGroup[s][1]+g1)*fmt->nGroup[s][2]+g2; |
|---|
| 629 | UT_TRACE2("fmt->valueBase[s] = %d", ut_SWAP_U16(fmt->valueBase[s])); |
|---|
| 630 | UT_TRACE2("fmt->nGroup[s][1] = %d", fmt->nGroup[s][1]); |
|---|
| 631 | UT_TRACE2("fmt->nGroup[s][2] = %d", fmt->nGroup[s][2]); |
|---|
| 632 | i = fmt->value[i] + ut_SWAP_U16(fmt->jasoBase[s][c[s]]); |
|---|
| 633 | UT_TRACE2("fmt->value[i] = %d", fmt->value[i]); |
|---|
| 634 | UT_TRACE2("fmt->jasoBase[s][c[s]] = %d", ut_SWAP_U16(fmt->jasoBase[s][c[s]])); |
|---|
| 635 | UT_TRACE2("i = %d", i); |
|---|
| 636 | if (ut_GetGlyphDataFnt[cmap->locaFormat](fontManager, stream, cmap, i, glyph)) glyph->count++; |
|---|
| 637 | UT_TRACE_TAB_DEC(); |
|---|
| 638 | } |
|---|
| 639 | ut_GetGlyphMetricFnt[cmap->widthFormat](cmap, &cmap->width, index, 0, &glyph->width); |
|---|
| 640 | ut_GetGlyphMetricFnt[cmap->heightFormat](cmap, &cmap->height, index, 0, &glyph->height); |
|---|
| 641 | UT_TRACE_TAB_DEC(); |
|---|
| 642 | return _UT_TRUE; |
|---|
| 643 | } |
|---|
| 644 | |
|---|
| 645 | UT_STATIC_API UT_BOOL ut_GetGlyph_JOHAP_2(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, UT_CODE code, UT_GLYPH* glyph) |
|---|
| 646 | { |
|---|
| 647 | UT_CMAP_JOHAP_2* fmt = (UT_CMAP_JOHAP_2*)cmap; |
|---|
| 648 | int c0, c1, c2, g0, g1, g2, i, j, index; |
|---|
| 649 | int nValue = ut_SWAP_U16(fmt->nValue); |
|---|
| 650 | UT_TRACE1("ut_GetGlyph_JOHAP_1()"); |
|---|
| 651 | UT_TRACE_TAB_INC(); |
|---|
| 652 | UT_TRACE2("nValue = %d", nValue); |
|---|
| 653 | #ifdef _UT_USE_KS_CODE |
|---|
| 654 | if (fmt->level == _UT_CMAP_JOHAP_LEVEL_KS_2350) |
|---|
| 655 | { |
|---|
| 656 | code = ut_cbKsToUniCode(fontManager, code); |
|---|
| 657 | UT_TRACE2("code = 0x%04x", code); |
|---|
| 658 | if (code == (UT_CODE)-1) |
|---|
| 659 | { |
|---|
| 660 | UT_TRACE_TAB_DEC(); |
|---|
| 661 | return _UT_FALSE; |
|---|
| 662 | } |
|---|
| 663 | index = code - 0xac00; |
|---|
| 664 | UT_TRACE2("index = %d", index); |
|---|
| 665 | } |
|---|
| 666 | else |
|---|
| 667 | #endif |
|---|
| 668 | index = code - ut_SWAP_U16(cmap->startCode); |
|---|
| 669 | UT_TRACE2("index = %d", index); |
|---|
| 670 | i = index; |
|---|
| 671 | c0 = i / (21*28); i %= (21*28); |
|---|
| 672 | c1 = i / 28; |
|---|
| 673 | c2 = i % 28; |
|---|
| 674 | g0 = fmt->groupMap[0][c0]; |
|---|
| 675 | g1 = fmt->groupMap[1][c1]; |
|---|
| 676 | g2 = fmt->groupMap[2][c2]; |
|---|
| 677 | UT_TRACE2("c0 = %d", c0); |
|---|
| 678 | UT_TRACE2("c1 = %d", c1); |
|---|
| 679 | UT_TRACE2("c2 = %d", c2); |
|---|
| 680 | UT_TRACE2("g0 = %d", g0); |
|---|
| 681 | UT_TRACE2("g1 = %d", g1); |
|---|
| 682 | UT_TRACE2("g2 = %d", g2); |
|---|
| 683 | j = (g0*fmt->nGroup[1]+g1)*fmt->nGroup[2]+g2; |
|---|
| 684 | UT_TRACE2("fmt->nGroup[1] = %d", fmt->nGroup[1]); |
|---|
| 685 | UT_TRACE2("fmt->nGroup[2] = %d", fmt->nGroup[2]); |
|---|
| 686 | UT_TRACE2("j = %d", j); |
|---|
| 687 | i = ut_SWAP_U16(fmt->jasoBase[0][c0]) + fmt->value[j]; |
|---|
| 688 | UT_TRACE2("fmt->jasoBase[0][c0] = %d", ut_SWAP_U16(fmt->jasoBase[0][c0])); |
|---|
| 689 | UT_TRACE2("fmt->value[j] = %d", fmt->value[j]); |
|---|
| 690 | UT_TRACE2("i = %d", i); |
|---|
| 691 | if (ut_GetGlyphDataFnt[cmap->locaFormat](fontManager, stream, cmap, i, glyph)) glyph->count++; |
|---|
| 692 | i = ut_SWAP_U16(fmt->jasoBase[1][c1]) + fmt->value[nValue+j]; |
|---|
| 693 | UT_TRACE2("fmt->jasoBase[1][c1] = %d", ut_SWAP_U16(fmt->jasoBase[1][c1])); |
|---|
| 694 | UT_TRACE2("fmt->value[nValue+j] = %d", fmt->value[nValue+j]); |
|---|
| 695 | UT_TRACE2("i = %d", i); |
|---|
| 696 | if (ut_GetGlyphDataFnt[cmap->locaFormat](fontManager, stream, cmap, i, glyph)) glyph->count++; |
|---|
| 697 | if (c2) |
|---|
| 698 | { |
|---|
| 699 | i = ut_SWAP_U16(fmt->jasoBase[2][c2]) + fmt->value[nValue+nValue+j]; |
|---|
| 700 | UT_TRACE2("fmt->jasoBase[2][c2] = %d", ut_SWAP_U16(fmt->jasoBase[2][c2])); |
|---|
| 701 | UT_TRACE2("fmt->value[nValue+nValue+j] = %d", fmt->value[nValue+nValue+j]); |
|---|
| 702 | UT_TRACE2("i = %d", i); |
|---|
| 703 | if (ut_GetGlyphDataFnt[cmap->locaFormat](fontManager, stream, cmap, i, glyph)) glyph->count++; |
|---|
| 704 | } |
|---|
| 705 | ut_GetGlyphMetricFnt[cmap->widthFormat](cmap, &cmap->width, index, 0, &glyph->width); |
|---|
| 706 | ut_GetGlyphMetricFnt[cmap->heightFormat](cmap, &cmap->height, index, 0, &glyph->height); |
|---|
| 707 | UT_TRACE_TAB_DEC(); |
|---|
| 708 | return _UT_TRUE; |
|---|
| 709 | } |
|---|
| 710 | |
|---|
| 711 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 712 | #define ut_johap3_jungsung_map0 fontManager->johap3_jungsung_map0 |
|---|
| 713 | #define SET_VALUE(index, value) ut_johap3_jungsung_map0[index] = value |
|---|
| 714 | UT_STATIC_API void ut_InitJohap3JungsungMap0(UT_FONT_MANAGER* fontManager) |
|---|
| 715 | { |
|---|
| 716 | #else |
|---|
| 717 | #define SET_VALUE(index, value) value |
|---|
| 718 | #define ut_InitJohap3JungsungMap0(fontManager) |
|---|
| 719 | static signed char ut_johap3_jungsung_map0[] = |
|---|
| 720 | { |
|---|
| 721 | #endif |
|---|
| 722 | SET_VALUE( 0, 0), |
|---|
| 723 | SET_VALUE( 1, 1), |
|---|
| 724 | SET_VALUE( 2, 2), |
|---|
| 725 | SET_VALUE( 3, 3), |
|---|
| 726 | SET_VALUE( 4, 4), |
|---|
| 727 | SET_VALUE( 5, 5), |
|---|
| 728 | SET_VALUE( 6, 6), |
|---|
| 729 | SET_VALUE( 7, 7), |
|---|
| 730 | SET_VALUE( 8, 8), |
|---|
| 731 | SET_VALUE( 9, 9), |
|---|
| 732 | SET_VALUE(10, 9), |
|---|
| 733 | SET_VALUE(11, 9), |
|---|
| 734 | SET_VALUE(12, 10), |
|---|
| 735 | SET_VALUE(13, 11), |
|---|
| 736 | SET_VALUE(14, 12), |
|---|
| 737 | SET_VALUE(15, 12), |
|---|
| 738 | SET_VALUE(16, 12), |
|---|
| 739 | SET_VALUE(17, 13), |
|---|
| 740 | SET_VALUE(18, 14), |
|---|
| 741 | SET_VALUE(19, 15), |
|---|
| 742 | SET_VALUE(20, 16) |
|---|
| 743 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 744 | ;} |
|---|
| 745 | #else |
|---|
| 746 | }; |
|---|
| 747 | #endif |
|---|
| 748 | #undef SET_VALUE |
|---|
| 749 | |
|---|
| 750 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 751 | #define ut_johap3_jungsung_map1 fontManager->johap3_jungsung_map1 |
|---|
| 752 | #define SET_VALUE(index, value) ut_johap3_jungsung_map1[index] = value |
|---|
| 753 | UT_STATIC_API void ut_InitJohap3JungsungMap1(UT_FONT_MANAGER* fontManager) |
|---|
| 754 | { |
|---|
| 755 | #else |
|---|
| 756 | #define SET_VALUE(index, value) value |
|---|
| 757 | #define ut_InitJohap3JungsungMap1(fontManager) |
|---|
| 758 | static signed char ut_johap3_jungsung_map1[] = |
|---|
| 759 | { |
|---|
| 760 | #endif |
|---|
| 761 | SET_VALUE( 0, -1), |
|---|
| 762 | SET_VALUE( 1, -1), |
|---|
| 763 | SET_VALUE( 2, -1), |
|---|
| 764 | SET_VALUE( 3, -1), |
|---|
| 765 | SET_VALUE( 4, -1), |
|---|
| 766 | SET_VALUE( 5, -1), |
|---|
| 767 | SET_VALUE( 6, -1), |
|---|
| 768 | SET_VALUE( 7, -1), |
|---|
| 769 | SET_VALUE( 8, -1), |
|---|
| 770 | SET_VALUE( 9, 0), |
|---|
| 771 | SET_VALUE(10, 1), |
|---|
| 772 | SET_VALUE(11, 16), |
|---|
| 773 | SET_VALUE(12, -1), |
|---|
| 774 | SET_VALUE(13, -1), |
|---|
| 775 | SET_VALUE(14, 4), |
|---|
| 776 | SET_VALUE(15, 5), |
|---|
| 777 | SET_VALUE(16, 16), |
|---|
| 778 | SET_VALUE(17, -1), |
|---|
| 779 | SET_VALUE(18, -1), |
|---|
| 780 | SET_VALUE(19, -1), |
|---|
| 781 | SET_VALUE(20, -1) |
|---|
| 782 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 783 | ;} |
|---|
| 784 | #else |
|---|
| 785 | }; |
|---|
| 786 | #endif |
|---|
| 787 | #undef SET_VALUE |
|---|
| 788 | |
|---|
| 789 | UT_STATIC_API UT_BOOL ut_GetGlyph_JOHAP_3(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, UT_CODE code, UT_GLYPH* glyph) |
|---|
| 790 | { |
|---|
| 791 | UT_CMAP_JOHAP_3* fmt = (UT_CMAP_JOHAP_3*)cmap; |
|---|
| 792 | int index, i, s, c0, c1, c2, j[4]; |
|---|
| 793 | int width = 0; |
|---|
| 794 | UT_TRACE1("ut_GetGlyph_JOHAP_3()"); |
|---|
| 795 | UT_TRACE_TAB_INC(); |
|---|
| 796 | #ifdef _UT_USE_KS_CODE |
|---|
| 797 | if (fmt->level == _UT_CMAP_JOHAP_LEVEL_KS_2350) |
|---|
| 798 | { |
|---|
| 799 | code = ut_cbKsToUniCode(fontManager, code); |
|---|
| 800 | UT_TRACE2("code = 0x%04x", code); |
|---|
| 801 | if (code == (UT_CODE)-1) |
|---|
| 802 | { |
|---|
| 803 | UT_TRACE_TAB_DEC(); |
|---|
| 804 | return _UT_FALSE; |
|---|
| 805 | } |
|---|
| 806 | index = code - 0xac00; |
|---|
| 807 | UT_TRACE2("index = %d", index); |
|---|
| 808 | } |
|---|
| 809 | else |
|---|
| 810 | #endif |
|---|
| 811 | index = code - ut_SWAP_U16(cmap->startCode); |
|---|
| 812 | UT_TRACE2("index = %d", index); |
|---|
| 813 | i = index; |
|---|
| 814 | c0 = i / (21*28); i %= (21*28); |
|---|
| 815 | c1 = i / 28; |
|---|
| 816 | c2 = i % 28; |
|---|
| 817 | UT_TRACE2("c0 = %d", c0); |
|---|
| 818 | UT_TRACE2("c1 = %d", c1); |
|---|
| 819 | UT_TRACE2("c2 = %d", c2); |
|---|
| 820 | j[0] = c0; |
|---|
| 821 | j[1] = ut_johap3_jungsung_map0[c1] + 19; |
|---|
| 822 | j[2] = ut_johap3_jungsung_map1[c1]; if (j[2] >= 0) j[2] += 19; |
|---|
| 823 | if (!c2) j[3] = -1; |
|---|
| 824 | else |
|---|
| 825 | { |
|---|
| 826 | j[3] = c2 + 35; |
|---|
| 827 | if (ut_SWAP_U16(fmt->nGlyph) == 90) |
|---|
| 828 | { |
|---|
| 829 | if ( |
|---|
| 830 | //(c1 == 0) || /*¤¿*/ |
|---|
| 831 | //(c1 == 1) || /*¤À*/ |
|---|
| 832 | //(c1 == 2) || /*¤Á*/ |
|---|
| 833 | //(c1 == 3) || /*¤Â*/ |
|---|
| 834 | //(c1 == 4) || /*¤Ã*/ |
|---|
| 835 | //(c1 == 5) || /*¤Ä*/ |
|---|
| 836 | //(c1 == 6) || /*¤Å*/ |
|---|
| 837 | //(c1 == 7) || /*¤Æ*/ |
|---|
| 838 | (c1 == 8) || /*¤Ç*/ |
|---|
| 839 | (c1 == 9) || /*¤È*/ |
|---|
| 840 | (c1 == 10) || /*¤É*/ |
|---|
| 841 | (c1 == 11) || /*¤Ê*/ |
|---|
| 842 | (c1 == 12) || /*¤Ë*/ |
|---|
| 843 | (c1 == 13) || /*¤Ì*/ |
|---|
| 844 | (c1 == 14) || /*¤Í*/ |
|---|
| 845 | (c1 == 15) || /*¤Î*/ |
|---|
| 846 | (c1 == 16) || /*¤Ï*/ |
|---|
| 847 | (c1 == 17) || /*¤Ð*/ |
|---|
| 848 | (c1 == 18) || /*¤Ñ*/ |
|---|
| 849 | (c1 == 19) || /*¤Ò*/ |
|---|
| 850 | //(c1 == 20) || /*¤Ó*/ |
|---|
| 851 | 0) j[3] += 27; |
|---|
| 852 | } |
|---|
| 853 | } |
|---|
| 854 | for (s=0; s<4; s++) |
|---|
| 855 | { |
|---|
| 856 | UT_TRACE2("s = %d", s); |
|---|
| 857 | if (j[s] == -1) continue; |
|---|
| 858 | i = j[s]; |
|---|
| 859 | UT_TRACE_TAB_INC(); |
|---|
| 860 | UT_TRACE2("i = %d", i); |
|---|
| 861 | if (ut_GetGlyphDataFnt[cmap->locaFormat](fontManager, stream, cmap, i, glyph)) |
|---|
| 862 | { |
|---|
| 863 | glyph->data[glyph->count].xOffset = width; |
|---|
| 864 | width += glyph->width; |
|---|
| 865 | glyph->count++; |
|---|
| 866 | } |
|---|
| 867 | UT_TRACE_TAB_DEC(); |
|---|
| 868 | } |
|---|
| 869 | glyph->width = width; |
|---|
| 870 | UT_TRACE_TAB_DEC(); |
|---|
| 871 | return _UT_TRUE; |
|---|
| 872 | } |
|---|
| 873 | |
|---|
| 874 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 875 | #define ut_GetGlyphFnt fontManager->GetGlyphFnt |
|---|
| 876 | #define SET_VALUE(index, value) ut_GetGlyphFnt[index] = value |
|---|
| 877 | UT_STATIC_API void ut_InitGetGlyphFnt(UT_FONT_MANAGER* fontManager) |
|---|
| 878 | { |
|---|
| 879 | #else |
|---|
| 880 | #define SET_VALUE(index, value) value |
|---|
| 881 | #define ut_InitGetGlyphFnt(fontManager) |
|---|
| 882 | static UT_BOOL (*ut_GetGlyphFnt[])(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream, UT_CMAP* cmap, UT_CODE code, UT_GLYPH* glyph) = |
|---|
| 883 | { |
|---|
| 884 | #endif |
|---|
| 885 | SET_VALUE(0, ut_GetGlyph_CONTINUOUS), |
|---|
| 886 | SET_VALUE(1, ut_GetGlyph_BLOCK), |
|---|
| 887 | SET_VALUE(2, ut_GetGlyph_SPARSE), |
|---|
| 888 | SET_VALUE(3, ut_GetGlyph_MAPPING), |
|---|
| 889 | SET_VALUE(4, ut_GetGlyph_JOHAP_1), |
|---|
| 890 | SET_VALUE(5, ut_GetGlyph_JOHAP_2), |
|---|
| 891 | SET_VALUE(6, ut_GetGlyph_JOHAP_3) |
|---|
| 892 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 893 | ;} |
|---|
| 894 | #else |
|---|
| 895 | }; |
|---|
| 896 | #endif |
|---|
| 897 | #undef SET_VALUE |
|---|
| 898 | |
|---|
| 899 | /***************************************************************************/ |
|---|
| 900 | |
|---|
| 901 | UT_STATIC_API int ut_GetGridFitBufferSize(UT_FC* fc) |
|---|
| 902 | { |
|---|
| 903 | UT_FONT_TASK* task = fc->task; |
|---|
| 904 | int maxDepth; |
|---|
| 905 | int maxPath; |
|---|
| 906 | int maxPoint; |
|---|
| 907 | int maxGlyphLength; |
|---|
| 908 | int gridFitBufferSize; |
|---|
| 909 | if (task->maxDepth < fc->font.info.maxDepth) task->maxDepth = fc->font.info.maxDepth; |
|---|
| 910 | if (task->maxPath < (fc->font.info.maxPath+1)) task->maxPath = fc->font.info.maxPath+1; |
|---|
| 911 | if (task->maxPoint < fc->font.info.maxPoint) task->maxPoint = fc->font.info.maxPoint; |
|---|
| 912 | if (task->maxGlyphLength < fc->font.maxGlyphLength) task->maxGlyphLength = fc->font.maxGlyphLength; |
|---|
| 913 | if (!task->maxDepth) task->maxDepth = 1; |
|---|
| 914 | maxDepth = task->maxDepth; |
|---|
| 915 | maxPath = task->maxPath; |
|---|
| 916 | maxPoint = task->maxPoint; |
|---|
| 917 | maxGlyphLength = task->maxGlyphLength; |
|---|
| 918 | UT_TRACE2("ut_GetGridFitBufferSize() maxDepth = %d", maxDepth); |
|---|
| 919 | UT_TRACE2(" maxPath = %d", maxPath); |
|---|
| 920 | UT_TRACE2(" maxPoint = %d", maxPoint); |
|---|
| 921 | UT_TRACE2(" maxGlyphLength = %d", maxGlyphLength); |
|---|
| 922 | if (maxPath) maxPath = ((maxPath + 1) >> 1) << 1; |
|---|
| 923 | if (maxPoint) maxPoint = ((maxPoint + 4) >> 2) << 2; |
|---|
| 924 | gridFitBufferSize = |
|---|
| 925 | + sizeof(UT_GLYPH) |
|---|
| 926 | + sizeof(UT_DATA) * maxDepth |
|---|
| 927 | + sizeof(UT_I16) * maxPath /*scanGlyph_startPoint*/ |
|---|
| 928 | + sizeof(UT_COORD) * maxPoint /*scanGlyph_x*/ |
|---|
| 929 | + sizeof(UT_COORD) * maxPoint /*scanGlyph_y*/ |
|---|
| 930 | + sizeof(UT_U8) * maxPoint /*scanGlyph_on*/ |
|---|
| 931 | + sizeof(UT_COORD) * maxPoint /*scanGlyph_ox*/ |
|---|
| 932 | + sizeof(UT_COORD) * maxPoint /*scanGlyph_oy*/ |
|---|
| 933 | + maxGlyphLength*maxDepth + 4; |
|---|
| 934 | return ((gridFitBufferSize+3)>>2)<<2; |
|---|
| 935 | } |
|---|
| 936 | |
|---|
| 937 | UT_STATIC_API void ut_SetGridFitBuffer(UT_FC* fc, char* buffer) |
|---|
| 938 | { |
|---|
| 939 | char* glyfBuffer; |
|---|
| 940 | UT_FONT_TASK* task = fc->task; |
|---|
| 941 | int maxDepth = task->maxDepth; |
|---|
| 942 | int maxPath = task->maxPath; |
|---|
| 943 | int maxPoint = task->maxPoint; |
|---|
| 944 | int maxGlyphLength = task->maxGlyphLength; |
|---|
| 945 | unsigned long align = ((unsigned long)buffer) & 3; |
|---|
| 946 | if (align) buffer += 4 - align; |
|---|
| 947 | UT_TRACE2("ut_SetGridFitBuffer() maxDepth = %d", maxDepth); |
|---|
| 948 | UT_TRACE2(" maxPath = %d", maxPath); |
|---|
| 949 | UT_TRACE2(" maxPoint = %d", maxPoint); |
|---|
| 950 | if (maxPath) maxPath = ((maxPath + 1) >> 1) << 1; |
|---|
| 951 | if (maxPoint) maxPoint = ((maxPoint + 4) >> 2) << 2; |
|---|
| 952 | task->glyph = (UT_GLYPH*)&buffer[0]; |
|---|
| 953 | task->rootGlyph.startPointIndex = (UT_I16*) &task->glyph->data[maxDepth+1]; |
|---|
| 954 | task->rootGlyph.x = (UT_COORD*)&task->rootGlyph.startPointIndex[maxPath]; |
|---|
| 955 | task->rootGlyph.y = (UT_COORD*)&task->rootGlyph.x[maxPoint]; |
|---|
| 956 | task->rootGlyph.on = (UT_U8*) &task->rootGlyph.y[maxPoint]; |
|---|
| 957 | task->rootGlyph.ox = (UT_COORD*)&task->rootGlyph.on[maxPoint]; |
|---|
| 958 | task->rootGlyph.oy = (UT_COORD*)&task->rootGlyph.ox[maxPoint]; |
|---|
| 959 | glyfBuffer = (char*) &task->rootGlyph.oy[maxPoint]; |
|---|
| 960 | if (maxGlyphLength) |
|---|
| 961 | { |
|---|
| 962 | int i; |
|---|
| 963 | for (i=0; i<maxDepth; i++) |
|---|
| 964 | { |
|---|
| 965 | task->glyph->data[i].temp = glyfBuffer; |
|---|
| 966 | glyfBuffer += maxGlyphLength; |
|---|
| 967 | } |
|---|
| 968 | } |
|---|
| 969 | } |
|---|
| 970 | |
|---|
| 971 | UT_FONT* utm_GetFontCap(UT_FONT_STREAM* stream, void* capBuffer, int capBufferSize) |
|---|
| 972 | { |
|---|
| 973 | UT_FONT_CAP* cap = (UT_FONT_CAP*)capBuffer; |
|---|
| 974 | UT_FONT* ffff = &cap->info; |
|---|
| 975 | UT_FONT* result; |
|---|
| 976 | if (stream->Read) |
|---|
| 977 | { |
|---|
| 978 | if (stream->Read(stream->handle, ut_STREAM_OFFSET(stream,0), sizeof(UT_FONT), &cap->info) != sizeof(UT_FONT)) return 0; |
|---|
| 979 | result = &cap->info; |
|---|
| 980 | } |
|---|
| 981 | else |
|---|
| 982 | { |
|---|
| 983 | UT_MEMCPY(&cap->info, (((char*)stream->handle)+stream->basement), sizeof(UT_FONT)); |
|---|
| 984 | result = (UT_FONT*)(((char*)stream->handle)+stream->basement); |
|---|
| 985 | } |
|---|
| 986 | ffff->identifier = ut_SWAP_U32(ffff->identifier); |
|---|
| 987 | if (ffff->identifier != _UT_IDENTIFIER) return 0; |
|---|
| 988 | ffff->fileSize = ut_SWAP_U32(ffff->fileSize); |
|---|
| 989 | ffff->id = ut_SWAP_U32(ffff->id); |
|---|
| 990 | ffff->limit = ut_SWAP_U16(ffff->limit); |
|---|
| 991 | ffff->maxPath = ut_SWAP_U16(ffff->maxPath); |
|---|
| 992 | ffff->maxPoint = ut_SWAP_U16(ffff->maxPoint); |
|---|
| 993 | ffff->xLimit = ut_SWAP_U16(ffff->xLimit); |
|---|
| 994 | ffff->moreOffset = ut_SWAP_U32(ffff->moreOffset); |
|---|
| 995 | if (capBufferSize == _UT_FONT_STRUCTURE_SIZE) return result; |
|---|
| 996 | cap->version = 0; |
|---|
| 997 | cap->cmapLength = 0; |
|---|
| 998 | cap->maxGlyphLength = 0; |
|---|
| 999 | cap->maxTwilighitPoint = 0; |
|---|
| 1000 | cap->maxStack = 0; |
|---|
| 1001 | cap->maxStorage = 0; |
|---|
| 1002 | cap->maxCvt = 0; |
|---|
| 1003 | cap->maxFunction = 0; |
|---|
| 1004 | cap->maxInstruction = 0; |
|---|
| 1005 | cap->typefaceName[0] = 0; |
|---|
| 1006 | cap->fontName[0] = 0; |
|---|
| 1007 | cap->ascent = 0; |
|---|
| 1008 | cap->descent = 0; |
|---|
| 1009 | if (ffff->moreOffset) |
|---|
| 1010 | { |
|---|
| 1011 | int moreOffset = ffff->moreOffset; |
|---|
| 1012 | #if 1 |
|---|
| 1013 | UT_U8 op; |
|---|
| 1014 | UT_U8 data[4]; |
|---|
| 1015 | for (;;) |
|---|
| 1016 | { |
|---|
| 1017 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 1, &op); |
|---|
| 1018 | else op = *(((UT_U8*)result)+moreOffset); moreOffset++; |
|---|
| 1019 | if (op == _UT_END) break; |
|---|
| 1020 | if (op == _UT_FONT_MORE_OP_CMAP_LENGTH) |
|---|
| 1021 | { |
|---|
| 1022 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 4, data); |
|---|
| 1023 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 4); moreOffset += 4; |
|---|
| 1024 | cap->cmapLength = (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3]; |
|---|
| 1025 | continue; |
|---|
| 1026 | } |
|---|
| 1027 | if (op == _UT_FONT_MORE_OP_MAX_GLYPH_LENGTH) |
|---|
| 1028 | { |
|---|
| 1029 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1030 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1031 | cap->maxGlyphLength = (data[0] << 8) | data[1]; |
|---|
| 1032 | continue; |
|---|
| 1033 | } |
|---|
| 1034 | if (op == _UT_FONT_MORE_OP_MAX_TWILIGHT_POINT) |
|---|
| 1035 | { |
|---|
| 1036 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1037 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1038 | cap->maxTwilighitPoint = (data[0] << 8) | data[1]; |
|---|
| 1039 | continue; |
|---|
| 1040 | } |
|---|
| 1041 | if (op == _UT_FONT_MORE_OP_MAX_STACK) |
|---|
| 1042 | { |
|---|
| 1043 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1044 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1045 | cap->maxStack = (data[0] << 8) | data[1]; |
|---|
| 1046 | continue; |
|---|
| 1047 | } |
|---|
| 1048 | if (op == _UT_FONT_MORE_OP_MAX_STORAGE) |
|---|
| 1049 | { |
|---|
| 1050 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1051 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1052 | cap->maxStorage = (data[0] << 8) | data[1]; |
|---|
| 1053 | continue; |
|---|
| 1054 | } |
|---|
| 1055 | if (op == _UT_FONT_MORE_OP_MAX_CVT) |
|---|
| 1056 | { |
|---|
| 1057 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1058 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1059 | cap->maxCvt = (data[0] << 8) | data[1]; |
|---|
| 1060 | continue; |
|---|
| 1061 | } |
|---|
| 1062 | if (op == _UT_FONT_MORE_OP_MAX_FUNCTION) |
|---|
| 1063 | { |
|---|
| 1064 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1065 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1066 | cap->maxFunction = (data[0] << 8) | data[1]; |
|---|
| 1067 | continue; |
|---|
| 1068 | } |
|---|
| 1069 | if (op == _UT_FONT_MORE_OP_MAX_INSTRUCTION) |
|---|
| 1070 | { |
|---|
| 1071 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1072 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1073 | cap->maxInstruction = (data[0] << 8) | data[1]; |
|---|
| 1074 | continue; |
|---|
| 1075 | } |
|---|
| 1076 | if (op == _UT_FONT_MORE_OP_TYPEFACE_NAME) |
|---|
| 1077 | { |
|---|
| 1078 | int i, length; |
|---|
| 1079 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 1, data); |
|---|
| 1080 | else data[0] = *(((UT_U8*)result)+moreOffset); moreOffset++; |
|---|
| 1081 | length = data[0]; |
|---|
| 1082 | for (i=0; i<length; i++) |
|---|
| 1083 | { |
|---|
| 1084 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1085 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1086 | cap->typefaceName[i] = (data[0] << 8) | data[1]; |
|---|
| 1087 | } |
|---|
| 1088 | cap->typefaceName[i] = 0; |
|---|
| 1089 | continue; |
|---|
| 1090 | } |
|---|
| 1091 | if (op == _UT_FONT_MORE_OP_FONT_NAME) |
|---|
| 1092 | { |
|---|
| 1093 | int i, length; |
|---|
| 1094 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 1, data); |
|---|
| 1095 | else data[0] = *(((UT_U8*)result)+moreOffset); moreOffset++; |
|---|
| 1096 | length = data[0]; |
|---|
| 1097 | for (i=0; i<length; i++) |
|---|
| 1098 | { |
|---|
| 1099 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1100 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1101 | cap->fontName[i] = (data[0] << 8) | data[1]; |
|---|
| 1102 | } |
|---|
| 1103 | cap->fontName[i] = 0; |
|---|
| 1104 | continue; |
|---|
| 1105 | } |
|---|
| 1106 | if (op == _UT_FONT_MORE_OP_ASCENT) |
|---|
| 1107 | { |
|---|
| 1108 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1109 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1110 | cap->ascent = (data[0] << 8) | data[1]; |
|---|
| 1111 | continue; |
|---|
| 1112 | } |
|---|
| 1113 | if (op == _UT_FONT_MORE_OP_DESCENT) |
|---|
| 1114 | { |
|---|
| 1115 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1116 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1117 | cap->descent = (data[0] << 8) | data[1]; |
|---|
| 1118 | continue; |
|---|
| 1119 | } |
|---|
| 1120 | if (op == _UT_FONT_MORE_OP_VERSION) |
|---|
| 1121 | { |
|---|
| 1122 | if (stream->Read) stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), 2, data); |
|---|
| 1123 | else UT_MEMCPY(data, ((char*)result)+moreOffset, 2); moreOffset += 2; |
|---|
| 1124 | cap->version = (data[0] << 8) | data[1]; |
|---|
| 1125 | continue; |
|---|
| 1126 | } |
|---|
| 1127 | } |
|---|
| 1128 | #else |
|---|
| 1129 | char more[512]; |
|---|
| 1130 | UT_POINTER p; |
|---|
| 1131 | if (stream->Read) |
|---|
| 1132 | { |
|---|
| 1133 | if (stream->Read(stream->handle, ut_STREAM_OFFSET(stream,moreOffset), sizeof(more), more) < 1) return result; |
|---|
| 1134 | p.p = more; |
|---|
| 1135 | } |
|---|
| 1136 | else |
|---|
| 1137 | { |
|---|
| 1138 | UT_MEMCPY(more, ((char*)result)+moreOffset, sizeof(more)); |
|---|
| 1139 | p.p = more; |
|---|
| 1140 | } |
|---|
| 1141 | while (*p.u8 != _UT_END) |
|---|
| 1142 | { |
|---|
| 1143 | UT_U8 op = *p.u8++; |
|---|
| 1144 | if (op == _UT_FONT_MORE_OP_CMAP_LENGTH) |
|---|
| 1145 | { |
|---|
| 1146 | cap->cmapLength = (p.u8[0] << 24) | (p.u8[1] << 16) | (p.u8[2] << 8) | p.u8[3]; |
|---|
| 1147 | p.u8 += 4; |
|---|
| 1148 | continue; |
|---|
| 1149 | } |
|---|
| 1150 | if (op == _UT_FONT_MORE_OP_MAX_GLYPH_LENGTH) |
|---|
| 1151 | { |
|---|
| 1152 | cap->maxGlyphLength = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1153 | p.u8 += 2; |
|---|
| 1154 | continue; |
|---|
| 1155 | } |
|---|
| 1156 | if (op == _UT_FONT_MORE_OP_MAX_TWILIGHT_POINT) |
|---|
| 1157 | { |
|---|
| 1158 | cap->maxTwilighitPoint = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1159 | p.u8 += 2; |
|---|
| 1160 | continue; |
|---|
| 1161 | } |
|---|
| 1162 | if (op == _UT_FONT_MORE_OP_MAX_STACK) |
|---|
| 1163 | { |
|---|
| 1164 | cap->maxStack = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1165 | p.u8 += 2; |
|---|
| 1166 | continue; |
|---|
| 1167 | } |
|---|
| 1168 | if (op == _UT_FONT_MORE_OP_MAX_STORAGE) |
|---|
| 1169 | { |
|---|
| 1170 | cap->maxStorage = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1171 | p.u8 += 2; |
|---|
| 1172 | continue; |
|---|
| 1173 | } |
|---|
| 1174 | if (op == _UT_FONT_MORE_OP_MAX_CVT) |
|---|
| 1175 | { |
|---|
| 1176 | cap->maxCvt = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1177 | p.u8 += 2; |
|---|
| 1178 | continue; |
|---|
| 1179 | } |
|---|
| 1180 | if (op == _UT_FONT_MORE_OP_MAX_FUNCTION) |
|---|
| 1181 | { |
|---|
| 1182 | cap->maxFunction = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1183 | p.u8 += 2; |
|---|
| 1184 | continue; |
|---|
| 1185 | } |
|---|
| 1186 | if (op == _UT_FONT_MORE_OP_MAX_INSTRUCTION) |
|---|
| 1187 | { |
|---|
| 1188 | cap->maxInstruction = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1189 | p.u8 += 2; |
|---|
| 1190 | continue; |
|---|
| 1191 | } |
|---|
| 1192 | if (op == _UT_FONT_MORE_OP_TYPEFACE_NAME) |
|---|
| 1193 | { |
|---|
| 1194 | int i, length = *p.u8++; |
|---|
| 1195 | for (i=0; i<length; i++,p.u16++) cap->typefaceName[i] = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1196 | cap->typefaceName[i] = 0; |
|---|
| 1197 | continue; |
|---|
| 1198 | } |
|---|
| 1199 | if (op == _UT_FONT_MORE_OP_FONT_NAME) |
|---|
| 1200 | { |
|---|
| 1201 | int i, length = *p.u8++; |
|---|
| 1202 | for (i=0; i<length; i++,p.u16++) cap->fontName[i] = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1203 | cap->fontName[i] = 0; |
|---|
| 1204 | continue; |
|---|
| 1205 | } |
|---|
| 1206 | if (op == _UT_FONT_MORE_OP_ASCENT) |
|---|
| 1207 | { |
|---|
| 1208 | cap->ascent = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1209 | p.u8 += 2; |
|---|
| 1210 | continue; |
|---|
| 1211 | } |
|---|
| 1212 | if (op == _UT_FONT_MORE_OP_DESCENT) |
|---|
| 1213 | { |
|---|
| 1214 | cap->descent = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1215 | p.u8 += 2; |
|---|
| 1216 | continue; |
|---|
| 1217 | } |
|---|
| 1218 | if (op == _UT_FONT_MORE_OP_VERSION) |
|---|
| 1219 | { |
|---|
| 1220 | cap->version = (p.u8[0] << 8) | p.u8[1]; |
|---|
| 1221 | p.u8 += 2; |
|---|
| 1222 | continue; |
|---|
| 1223 | } |
|---|
| 1224 | } |
|---|
| 1225 | #endif |
|---|
| 1226 | } |
|---|
| 1227 | if ((cap->version >> 8) > _UT_VERSION_MAJOR << 8) |
|---|
| 1228 | { |
|---|
| 1229 | UT_TRACE2("cap->version = %d", cap->version); |
|---|
| 1230 | return 0; |
|---|
| 1231 | } |
|---|
| 1232 | return result; |
|---|
| 1233 | } |
|---|
| 1234 | |
|---|
| 1235 | //UT_STATIC_API UT_FONT* utm_LoadFont(UT_FONT_STREAM* stream, void* capBuffer, int capBufferSize) |
|---|
| 1236 | //{ |
|---|
| 1237 | // UT_FONT_CAP* cap = (UT_FONT_CAP*)capBuffer; |
|---|
| 1238 | // if (stream->Read) |
|---|
| 1239 | // { |
|---|
| 1240 | // if (stream->Read(stream->handle, ut_STREAM_OFFSET(stream,0), sizeof(UT_FONT), &cap->info) != sizeof(UT_FONT)) return 0; |
|---|
| 1241 | // return &cap->info; |
|---|
| 1242 | // } |
|---|
| 1243 | // else |
|---|
| 1244 | // { |
|---|
| 1245 | // UT_MEMCPY(&cap->info, (((char*)stream->handle)+stream->basement), sizeof(UT_FONT)); |
|---|
| 1246 | // return (UT_FONT*)(((char*)stream->handle)+stream->basement); |
|---|
| 1247 | // } |
|---|
| 1248 | //} |
|---|
| 1249 | |
|---|
| 1250 | #if defined(_UT_USE_OUTLINE_FONT) && defined(_UT_USE_ENHANCED_RASTERIZER) |
|---|
| 1251 | int FT_GetGridFitBufferSize(UT_FC* fc); |
|---|
| 1252 | void FT_SetGridFitBuffer(UT_FC* fc, char* buffer); |
|---|
| 1253 | #else |
|---|
| 1254 | int FT_GetGridFitBufferSize(UT_FC* fc) {return 0;} |
|---|
| 1255 | void FT_SetGridFitBuffer(UT_FC* fc, char* buffer) {} |
|---|
| 1256 | #endif |
|---|
| 1257 | |
|---|
| 1258 | UT_STATIC_API int utm_SetStreamFontDirect_(UT_FC* fc, UT_FACE* face) |
|---|
| 1259 | { |
|---|
| 1260 | int gridFitBufferSize; |
|---|
| 1261 | char* buffer; |
|---|
| 1262 | int cmapLength = fc->font.cmapLength; |
|---|
| 1263 | UT_FONT_STREAM* stream; |
|---|
| 1264 | UT_DEFINE_FONT_INFO_2(cap, temp_cap); |
|---|
| 1265 | UT_TRACE1("utm_SetStreamFontDirect()"); |
|---|
| 1266 | UT_TRACE_TAB_INC(); |
|---|
| 1267 | /*fc->face = 0;*/ |
|---|
| 1268 | gridFitBufferSize = FT_GetGridFitBufferSize(fc); |
|---|
| 1269 | if (gridFitBufferSize) |
|---|
| 1270 | { |
|---|
| 1271 | buffer = ut_AllocGridFitBuffer(fc->task, gridFitBufferSize); |
|---|
| 1272 | UT_TRACE2("ut_gridFitBufferSize = %d", gridFitBufferSize); |
|---|
| 1273 | FT_SetGridFitBuffer(fc, buffer); |
|---|
| 1274 | } |
|---|
| 1275 | else |
|---|
| 1276 | { |
|---|
| 1277 | gridFitBufferSize = ut_GetGridFitBufferSize(fc); |
|---|
| 1278 | buffer = ut_AllocGridFitBuffer(fc->task, gridFitBufferSize); |
|---|
| 1279 | UT_TRACE2("ut_gridFitBufferSize = %d", gridFitBufferSize); |
|---|
| 1280 | ut_SetGridFitBuffer(fc, buffer); |
|---|
| 1281 | } |
|---|
| 1282 | ut_AllocCmapBuffer(fc, fc->font.cmapLength); |
|---|
| 1283 | buffer = fc->cmapBuffer; |
|---|
| 1284 | for (stream=fc->stream; stream; stream=stream->next) |
|---|
| 1285 | { |
|---|
| 1286 | if (stream->Read) |
|---|
| 1287 | { |
|---|
| 1288 | UT_CMAP* cmap; |
|---|
| 1289 | int offset = ut_CMAP_OFFSET(); |
|---|
| 1290 | stream->cmap = (UT_CMAP*)buffer; |
|---|
| 1291 | stream->Read(stream->handle, ut_STREAM_OFFSET(stream,offset), cmapLength, stream->cmap); |
|---|
| 1292 | cmap = stream->cmap; |
|---|
| 1293 | while (cmap) |
|---|
| 1294 | { |
|---|
| 1295 | if (cmap->startCode == (UT_U16)0xffff) break; |
|---|
| 1296 | cmap->glyfOffset = offset + ut_SWAP_U32(cmap->glyfOffset); |
|---|
| 1297 | if (!cmap->length) break; |
|---|
| 1298 | offset += ut_SWAP_U32(cmap->length); |
|---|
| 1299 | cmap = ut_NEXT_CMAP(cmap); |
|---|
| 1300 | } |
|---|
| 1301 | } |
|---|
| 1302 | else |
|---|
| 1303 | { |
|---|
| 1304 | UT_FONT* font = (UT_FONT*)(((char*)stream->handle)+stream->basement); |
|---|
| 1305 | stream->cmap = ut_HEAD_CMAP(font); |
|---|
| 1306 | } |
|---|
| 1307 | buffer += ((cmapLength + 3) >> 2) << 2; |
|---|
| 1308 | if (!face) break; |
|---|
| 1309 | face = face->sameFont; |
|---|
| 1310 | if (!face) break; |
|---|
| 1311 | utm_GetFontInfo_2(stream, face, cap); |
|---|
| 1312 | cmapLength = cap->cmapLength; |
|---|
| 1313 | } |
|---|
| 1314 | if (fc->isFixedPitch) |
|---|
| 1315 | { |
|---|
| 1316 | utm_SetFixedPitch(fc, fc->isFixedPitch); |
|---|
| 1317 | } |
|---|
| 1318 | #if 1 |
|---|
| 1319 | fc->fontItalic = fc->font.info.isItalic; |
|---|
| 1320 | fc->fontWeight = fc->font.info.weight; |
|---|
| 1321 | #endif |
|---|
| 1322 | UT_TRACE_TAB_DEC(); |
|---|
| 1323 | return _UT_TRUE; |
|---|
| 1324 | } |
|---|
| 1325 | |
|---|
| 1326 | UT_STATIC_API void ut_SetLinkedFont(UT_FC* fc, UT_FACE* face) |
|---|
| 1327 | { |
|---|
| 1328 | if ((fc->stream->handle != face->stream.handle) || |
|---|
| 1329 | (fc->stream->basement != face->stream.basement)) |
|---|
| 1330 | { |
|---|
| 1331 | int i; |
|---|
| 1332 | UT_FACE* save = face; |
|---|
| 1333 | UT_DEFINE_FONT_INFO_2(cap, temp_cap); |
|---|
| 1334 | for (i=0; face && (i<_UT_MAX_LINKABLE_FONT); i++,face=face->sameFont) |
|---|
| 1335 | { |
|---|
| 1336 | utm_GetFontInfo_2(&face->stream, face, cap); |
|---|
| 1337 | fc->stream[i] = face->stream; |
|---|
| 1338 | fc->stream[i].next = &fc->stream[i+1]; |
|---|
| 1339 | if (i) |
|---|
| 1340 | { |
|---|
| 1341 | if (fc->font.info.maxDepth < cap->info.maxDepth) fc->font.info.maxDepth = cap->info.maxDepth; |
|---|
| 1342 | if (fc->font.info.maxPath < cap->info.maxPath) fc->font.info.maxPath = cap->info.maxPath; |
|---|
| 1343 | if (fc->font.info.maxPoint < cap->info.maxPoint) fc->font.info.maxPoint = cap->info.maxPoint; |
|---|
| 1344 | if (fc->font.maxGlyphLength < cap->maxGlyphLength) fc->font.maxGlyphLength = cap->maxGlyphLength; |
|---|
| 1345 | if (fc->font.maxTwilighitPoint < cap->maxTwilighitPoint) fc->font.maxTwilighitPoint = cap->maxTwilighitPoint; |
|---|
| 1346 | if (fc->font.maxStack < cap->maxStack) fc->font.maxStack = cap->maxStack; |
|---|
| 1347 | if (fc->font.maxStorage < cap->maxStorage) fc->font.maxStorage = cap->maxStorage; |
|---|
| 1348 | if (fc->font.maxCvt < cap->maxCvt) fc->font.maxCvt = cap->maxCvt; |
|---|
| 1349 | if (fc->font.maxFunction < cap->maxFunction) fc->font.maxFunction = cap->maxFunction; |
|---|
| 1350 | if (fc->font.maxInstruction < cap->maxInstruction) fc->font.maxInstruction = cap->maxInstruction; |
|---|
| 1351 | fc->font.cmapLength += ((cap->cmapLength + 3) >> 2) << 2; |
|---|
| 1352 | } |
|---|
| 1353 | else |
|---|
| 1354 | { |
|---|
| 1355 | fc->font = *cap; |
|---|
| 1356 | fc->font.cmapLength = ((cap->cmapLength + 3) >> 2) << 2; |
|---|
| 1357 | } |
|---|
| 1358 | } |
|---|
| 1359 | fc->stream[i-1].next = 0; |
|---|
| 1360 | if (!fc->stream->Read) |
|---|
| 1361 | { |
|---|
| 1362 | fc->font.maxGlyphLength = 0; |
|---|
| 1363 | fc->font.cmapLength = 0; |
|---|
| 1364 | } |
|---|
| 1365 | utm_SetStreamFontDirect_(fc, save); |
|---|
| 1366 | } |
|---|
| 1367 | } |
|---|
| 1368 | UT_STATIC_API void ut_AdjustFont(UT_FC* fc) |
|---|
| 1369 | { |
|---|
| 1370 | if (fc->face) |
|---|
| 1371 | { |
|---|
| 1372 | UT_DEFINE_FONT_INFO_1(cap, temp_cap); |
|---|
| 1373 | UT_FACE* face; |
|---|
| 1374 | int weight = fc->isBold ? _UT_FONT_WEIGHT_BOLD : _UT_FONT_WEIGHT_MEDIUM; |
|---|
| 1375 | int limit = fc->ySize; |
|---|
| 1376 | int xLimit = fc->xSize; |
|---|
| 1377 | #if 0 |
|---|
| 1378 | if(fc->ySize ==fc->xSize) |
|---|
| 1379 | { |
|---|
| 1380 | limit = fc->ySize; |
|---|
| 1381 | } |
|---|
| 1382 | else |
|---|
| 1383 | { |
|---|
| 1384 | fc->xSize = fc->ySize; |
|---|
| 1385 | xLimit = fc->ySize; |
|---|
| 1386 | } |
|---|
| 1387 | #endif |
|---|
| 1388 | |
|---|
| 1389 | |
|---|
| 1390 | if(limit == xLimit) |
|---|
| 1391 | { |
|---|
| 1392 | if (limit != 0 && limit < 13) limit = 13;//sjchang 040525 add |
|---|
| 1393 | else if (limit == 16) limit = 15; |
|---|
| 1394 | else if (limit == 18) limit = 17;//19; |
|---|
| 1395 | else if (limit == 20) limit = 19; |
|---|
| 1396 | else if (limit == 22) limit = 21;//23; |
|---|
| 1397 | else if (limit == 24) limit = 23; |
|---|
| 1398 | // else if (limit == 25) limit = 26; |
|---|
| 1399 | else if (limit == 27) limit = 26; |
|---|
| 1400 | else if (limit == 29) limit = 28;//30; |
|---|
| 1401 | else if (limit == 31) limit = 30; |
|---|
| 1402 | |
|---|
| 1403 | xLimit = limit; |
|---|
| 1404 | } |
|---|
| 1405 | |
|---|
| 1406 | |
|---|
| 1407 | /* Find In Bitmap Font */ |
|---|
| 1408 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1409 | { |
|---|
| 1410 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1411 | if (cap->limit != limit) continue; |
|---|
| 1412 | if (cap->xLimit && (cap->xLimit != xLimit)) continue; |
|---|
| 1413 | |
|---|
| 1414 | if(1) //fc->isItalic == 0) |
|---|
| 1415 | { |
|---|
| 1416 | if(cap->isItalic != fc->isItalic) |
|---|
| 1417 | continue; |
|---|
| 1418 | } |
|---|
| 1419 | |
|---|
| 1420 | if (cap->weight != weight) continue; |
|---|
| 1421 | |
|---|
| 1422 | ut_SetLinkedFont(fc, face); |
|---|
| 1423 | return; |
|---|
| 1424 | } |
|---|
| 1425 | if (weight && fc->isItalic) |
|---|
| 1426 | { |
|---|
| 1427 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1428 | { |
|---|
| 1429 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1430 | if (cap->limit != limit) continue; |
|---|
| 1431 | if (cap->xLimit != xLimit) continue; |
|---|
| 1432 | if (cap->weight != weight) continue; |
|---|
| 1433 | ut_SetLinkedFont(fc, face); |
|---|
| 1434 | return; |
|---|
| 1435 | } |
|---|
| 1436 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1437 | { |
|---|
| 1438 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1439 | if (cap->limit != limit) continue; |
|---|
| 1440 | if (cap->xLimit != xLimit) continue; |
|---|
| 1441 | if (cap->isItalic != fc->isItalic) continue; |
|---|
| 1442 | ut_SetLinkedFont(fc, face); |
|---|
| 1443 | return; |
|---|
| 1444 | } |
|---|
| 1445 | } |
|---|
| 1446 | if (weight) |
|---|
| 1447 | { |
|---|
| 1448 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1449 | { |
|---|
| 1450 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1451 | if (cap->limit != limit) continue; |
|---|
| 1452 | if (cap->xLimit != xLimit) continue; |
|---|
| 1453 | if (cap->weight != weight) continue; |
|---|
| 1454 | ut_SetLinkedFont(fc, face); |
|---|
| 1455 | return; |
|---|
| 1456 | } |
|---|
| 1457 | } |
|---|
| 1458 | if (fc->isItalic) |
|---|
| 1459 | { |
|---|
| 1460 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1461 | { |
|---|
| 1462 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1463 | if (cap->limit != limit) continue; |
|---|
| 1464 | if (cap->xLimit != xLimit) continue; |
|---|
| 1465 | if (cap->isItalic != fc->isItalic) continue; |
|---|
| 1466 | ut_SetLinkedFont(fc, face); |
|---|
| 1467 | return; |
|---|
| 1468 | } |
|---|
| 1469 | } |
|---|
| 1470 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1471 | { |
|---|
| 1472 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1473 | if (cap->limit != limit) continue; |
|---|
| 1474 | if (cap->xLimit != xLimit) continue; |
|---|
| 1475 | #if 0 |
|---|
| 1476 | //¾Æ·¡ÀÇ ÄÚµå´Â ÀÌÅŸ¯ÀÌ ¾ø´Â ÆùÆ®(style 5,6,7)¿¡¼ |
|---|
| 1477 | //ÀÌÅŸ¯À¸·Î ÁöÁ¤À» ÇÏ¿´À» °æ¿ì ÀÌÅŸ¯ÀÌ ±×·ÁÁö°í ÀÖ´Ù. |
|---|
| 1478 | //ù¹øÂ° for¹®(¸ÇÀ§): ÀÌÅŸ¯ ÆùÆ®°¡ Á¸ÀçÇÏ´Â °æ¿ì ±×°÷¿¡¼ 󸮵ȴÙ. |
|---|
| 1479 | //6¹øÂ° for¹®(¿©±â): ÀÌ·¢¸¯ ÆùÆ®°¡ ¾øÀº °æ¿ì normalÆùÆ®¸¦ À̰÷¿¡¼ ²ª´Â´Ù°í ÃßÁ¤ |
|---|
| 1480 | //¾Æ·¡ÀÇ ÄÚµå´Â ÀÌÅŸ¯ÀÌ ¾øÀ¸¸é ·çÇÁÅ»Ãâ ÄÚµå |
|---|
| 1481 | //Äڵ带 »ðÀÔÀ» ÇØ º» °á°ú outlineÆùÆ®·Î À̵¿µÇ¾î ÀÌÅŸ¯À» |
|---|
| 1482 | //Ç¥½ÃÇÔ-->µð¹ö±× È®ÀÎÇÏ¿´´Ù. |
|---|
| 1483 | if(1) //fc->isItalic == 0) |
|---|
| 1484 | { |
|---|
| 1485 | if(cap->isItalic != fc->isItalic) |
|---|
| 1486 | continue; |
|---|
| 1487 | } |
|---|
| 1488 | #endif |
|---|
| 1489 | if (cap->weight) continue; |
|---|
| 1490 | if (cap->isItalic) continue; |
|---|
| 1491 | ut_SetLinkedFont(fc, face); |
|---|
| 1492 | return; |
|---|
| 1493 | } |
|---|
| 1494 | /* Find In Outline Font */ |
|---|
| 1495 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1496 | { |
|---|
| 1497 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1498 | if (cap->limit) continue; |
|---|
| 1499 | if (cap->isItalic != fc->isItalic) continue; |
|---|
| 1500 | if (cap->weight != weight) continue; |
|---|
| 1501 | ut_SetLinkedFont(fc, face); |
|---|
| 1502 | return; |
|---|
| 1503 | } |
|---|
| 1504 | if (weight && fc->isItalic) |
|---|
| 1505 | { |
|---|
| 1506 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1507 | { |
|---|
| 1508 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1509 | if (cap->limit) continue; |
|---|
| 1510 | if (cap->weight != weight) continue; |
|---|
| 1511 | ut_SetLinkedFont(fc, face); |
|---|
| 1512 | return; |
|---|
| 1513 | } |
|---|
| 1514 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1515 | { |
|---|
| 1516 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1517 | if (cap->limit) continue; |
|---|
| 1518 | if (cap->isItalic != fc->isItalic) continue; |
|---|
| 1519 | ut_SetLinkedFont(fc, face); |
|---|
| 1520 | return; |
|---|
| 1521 | } |
|---|
| 1522 | } |
|---|
| 1523 | if (weight) |
|---|
| 1524 | { |
|---|
| 1525 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1526 | { |
|---|
| 1527 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1528 | if (cap->limit) continue; |
|---|
| 1529 | if (cap->weight != weight) continue; |
|---|
| 1530 | ut_SetLinkedFont(fc, face); |
|---|
| 1531 | return; |
|---|
| 1532 | } |
|---|
| 1533 | } |
|---|
| 1534 | if (fc->isItalic) |
|---|
| 1535 | { |
|---|
| 1536 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1537 | { |
|---|
| 1538 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1539 | if (cap->limit) continue; |
|---|
| 1540 | if (cap->isItalic != fc->isItalic) continue; |
|---|
| 1541 | ut_SetLinkedFont(fc, face); |
|---|
| 1542 | return; |
|---|
| 1543 | } |
|---|
| 1544 | } |
|---|
| 1545 | for (face=fc->face; face; face=face->nextFont) |
|---|
| 1546 | { |
|---|
| 1547 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 1548 | if (cap->limit) continue; |
|---|
| 1549 | if (cap->weight) continue; |
|---|
| 1550 | if (cap->isItalic) continue; |
|---|
| 1551 | ut_SetLinkedFont(fc, face); |
|---|
| 1552 | return; |
|---|
| 1553 | } |
|---|
| 1554 | ut_SetLinkedFont(fc, fc->face); |
|---|
| 1555 | } |
|---|
| 1556 | } |
|---|
| 1557 | |
|---|
| 1558 | #ifdef _UT_USE_BITMAP_FONT |
|---|
| 1559 | |
|---|
| 1560 | UT_STATIC_API void ut_GetImageBbox(UT_FC* fc, UT_IMAGE* image) |
|---|
| 1561 | { |
|---|
| 1562 | UT_GLYPH* glyph = fc->task->glyph; |
|---|
| 1563 | UT_DATA* data = glyph->data; |
|---|
| 1564 | int i; |
|---|
| 1565 | int xmin, x_min = data->bbox.ox; |
|---|
| 1566 | int ymin, y_min = data->bbox.oy; |
|---|
| 1567 | int xmax, x_max = data->bbox.sx + x_min; |
|---|
| 1568 | int ymax, y_max = data->bbox.sy + y_min; |
|---|
| 1569 | UT_TRACE1("ut_GetImageBbox()"); |
|---|
| 1570 | UT_TRACE_TAB_INC(); |
|---|
| 1571 | for (i=glyph->count-1; i; i--) |
|---|
| 1572 | { |
|---|
| 1573 | data++; |
|---|
| 1574 | data->bbox.ox += data->xOffset; |
|---|
| 1575 | data->xOffset = 0; |
|---|
| 1576 | xmin = data->bbox.ox; |
|---|
| 1577 | ymin = data->bbox.oy; |
|---|
| 1578 | xmax = data->bbox.sx + xmin; |
|---|
| 1579 | ymax = data->bbox.sy + ymin; |
|---|
| 1580 | if (x_min > xmin) x_min = xmin; |
|---|
| 1581 | if (y_min > ymin) y_min = ymin; |
|---|
| 1582 | if (x_max < xmax) x_max = xmax; |
|---|
| 1583 | if (y_max < ymax) y_max = ymax; |
|---|
| 1584 | } |
|---|
| 1585 | image->bbox.ox = x_min; |
|---|
| 1586 | image->bbox.oy = y_min; |
|---|
| 1587 | image->bbox.sx = x_max - x_min; |
|---|
| 1588 | image->bbox.sy = y_max - y_min; |
|---|
| 1589 | UT_TRACE2("bbox.ox = %d", image->bbox.ox); |
|---|
| 1590 | UT_TRACE2("bbox.oy = %d", image->bbox.oy); |
|---|
| 1591 | UT_TRACE2("bbox.sx = %d", image->bbox.sx); |
|---|
| 1592 | UT_TRACE2("bbox.sy = %d", image->bbox.sy); |
|---|
| 1593 | UT_TRACE_TAB_DEC(); |
|---|
| 1594 | } |
|---|
| 1595 | |
|---|
| 1596 | UT_STATIC_API void ut_PrepareRasterBitmapHasFixedBbox(UT_FC* fc, UT_IMAGE* image, int bSize, int rSize) |
|---|
| 1597 | { |
|---|
| 1598 | UT_DATA* data = fc->task->glyph->data; |
|---|
| 1599 | UT_TRACE1("ut_PrepareRasterBitmapHasFixedBbox()"); |
|---|
| 1600 | UT_TRACE_TAB_INC(); |
|---|
| 1601 | image->bbox.ox = data->bbox.ox; |
|---|
| 1602 | image->bbox.oy = data->bbox.oy; |
|---|
| 1603 | image->bbox.sx = data->bbox.sx; |
|---|
| 1604 | image->bbox.sy = data->bbox.sy; |
|---|
| 1605 | image->bSize = bSize; |
|---|
| 1606 | image->lSize = bSize * rSize; |
|---|
| 1607 | UT_TRACE_TAB_DEC(); |
|---|
| 1608 | } |
|---|
| 1609 | |
|---|
| 1610 | UT_STATIC_API void ut_MakeRasterBitmapHasFixedBbox(UT_FC* fc, UT_IMAGE* image) |
|---|
| 1611 | { |
|---|
| 1612 | int i, b; |
|---|
| 1613 | unsigned char* s, *d; |
|---|
| 1614 | UT_DATA* data = fc->task->glyph->data; |
|---|
| 1615 | UT_TRACE1("ut_MakeRasterBitmapHasFixedBbox()"); |
|---|
| 1616 | UT_TRACE_TAB_INC(); |
|---|
| 1617 | ut_AllocScanBuffer(fc->task, image, 0); |
|---|
| 1618 | UT_MEMSET(image->data, 0, image->lSize); |
|---|
| 1619 | for (i=fc->task->glyph->count; i; i--,data++) |
|---|
| 1620 | { |
|---|
| 1621 | d = image->data; |
|---|
| 1622 | s = data->p.u8; |
|---|
| 1623 | for (b=image->lSize; b; b--) *d++ |= *s++; |
|---|
| 1624 | } |
|---|
| 1625 | UT_TRACE_TAB_DEC(); |
|---|
| 1626 | } |
|---|
| 1627 | |
|---|
| 1628 | UT_STATIC_API void ut_MakeRasterBitmapHasOneGlyph(UT_FC* fc, UT_IMAGE* image) |
|---|
| 1629 | { |
|---|
| 1630 | UT_DATA* data = fc->task->glyph->data; |
|---|
| 1631 | UT_TRACE1("ut_MakeRasterBitmapHasOneGlyph()"); |
|---|
| 1632 | UT_TRACE_TAB_INC(); |
|---|
| 1633 | image->data = data->p.u8; |
|---|
| 1634 | UT_TRACE_TAB_DEC(); |
|---|
| 1635 | } |
|---|
| 1636 | |
|---|
| 1637 | /***************************************************************************/ |
|---|
| 1638 | |
|---|
| 1639 | UT_STATIC_API void ut_CopySBM(UT_IMAGE* image, UT_DATA* data) |
|---|
| 1640 | { |
|---|
| 1641 | int y, b; |
|---|
| 1642 | int s_bSize = ut_BSIZE8(data->bbox.sx); |
|---|
| 1643 | int ox = data->bbox.ox-image->bbox.ox; |
|---|
| 1644 | int oy = data->bbox.oy-image->bbox.oy; |
|---|
| 1645 | int oxBit = ox & 7; |
|---|
| 1646 | unsigned char* p; |
|---|
| 1647 | unsigned char* s = data->p.u8; |
|---|
| 1648 | unsigned char* d = image->data + oy*image->bSize + (ox >> 3); |
|---|
| 1649 | UT_TRACE1("ut_CopySBM()"); |
|---|
| 1650 | UT_TRACE_TAB_INC(); |
|---|
| 1651 | if (oxBit) |
|---|
| 1652 | { |
|---|
| 1653 | unsigned short w; |
|---|
| 1654 | for (y=data->bbox.sy; y; y--) |
|---|
| 1655 | { |
|---|
| 1656 | p = d; |
|---|
| 1657 | w = 0; |
|---|
| 1658 | for (b=s_bSize; b; b--) |
|---|
| 1659 | { |
|---|
| 1660 | w |= *s++; |
|---|
| 1661 | *p++ |= (w >> oxBit) & 255; |
|---|
| 1662 | w <<= 8; |
|---|
| 1663 | } |
|---|
| 1664 | *p |= (w >> oxBit) & 255; |
|---|
| 1665 | d += image->bSize; |
|---|
| 1666 | } |
|---|
| 1667 | } |
|---|
| 1668 | else |
|---|
| 1669 | { |
|---|
| 1670 | for (y=data->bbox.sy; y; y--) |
|---|
| 1671 | { |
|---|
| 1672 | p = d; |
|---|
| 1673 | for (b=s_bSize; b; b--) *p++ |= *s++; |
|---|
| 1674 | d += image->bSize; |
|---|
| 1675 | } |
|---|
| 1676 | } |
|---|
| 1677 | UT_TRACE_TAB_DEC(); |
|---|
| 1678 | } |
|---|
| 1679 | |
|---|
| 1680 | UT_STATIC_API void ut_CopySBMP(UT_IMAGE* image, UT_DATA* data) |
|---|
| 1681 | { |
|---|
| 1682 | int y, sx, start, stop; |
|---|
| 1683 | // int s_bSize = ut_BSIZE8(data->bbox.sx); |
|---|
| 1684 | int ox = data->bbox.ox-image->bbox.ox; |
|---|
| 1685 | int oy = data->bbox.oy-image->bbox.oy; |
|---|
| 1686 | int oxBit = ox & 7; |
|---|
| 1687 | unsigned char* p; |
|---|
| 1688 | unsigned char* s = data->p.u8; |
|---|
| 1689 | unsigned char* d = image->data + oy*image->bSize + (ox >> 3); |
|---|
| 1690 | unsigned short w = 0; |
|---|
| 1691 | unsigned short f = 0; |
|---|
| 1692 | UT_TRACE1("ut_CopySBMP()"); |
|---|
| 1693 | UT_TRACE_TAB_INC(); |
|---|
| 1694 | for (y=data->bbox.sy; y; y--) |
|---|
| 1695 | { |
|---|
| 1696 | p = d; |
|---|
| 1697 | sx = data->bbox.sx; |
|---|
| 1698 | start = oxBit; |
|---|
| 1699 | stop = 8; |
|---|
| 1700 | while (sx > 0) |
|---|
| 1701 | { |
|---|
| 1702 | if (f < 8) |
|---|
| 1703 | { |
|---|
| 1704 | w <<= 8; |
|---|
| 1705 | w |= *s++; |
|---|
| 1706 | f += 8; |
|---|
| 1707 | } |
|---|
| 1708 | if (stop > sx + start) stop = start + sx; |
|---|
| 1709 | *p++ |= (w>>(f+start-8)) & (0xff>>start) & (~(0xff>>stop)); |
|---|
| 1710 | f -= stop - start; |
|---|
| 1711 | sx -= stop - start; |
|---|
| 1712 | start = 0; |
|---|
| 1713 | } |
|---|
| 1714 | d += image->bSize; |
|---|
| 1715 | } |
|---|
| 1716 | UT_TRACE_TAB_DEC(); |
|---|
| 1717 | } |
|---|
| 1718 | |
|---|
| 1719 | #ifdef _UT_USE_BITMAP_IMG |
|---|
| 1720 | #include "_utfBitmapIMG.cxx" |
|---|
| 1721 | #else |
|---|
| 1722 | #define ut_PrepareRasterBitmapGlyphIMG 0 |
|---|
| 1723 | #define ut_MakeRasterBitmapGlyphIMG 0 |
|---|
| 1724 | #endif |
|---|
| 1725 | |
|---|
| 1726 | #ifdef _UT_USE_BITMAP_IMGP |
|---|
| 1727 | #include "_utfBitmapIMGP.cxx" |
|---|
| 1728 | #else |
|---|
| 1729 | #define ut_PrepareRasterBitmapGlyphIMGP 0 |
|---|
| 1730 | #define ut_MakeRasterBitmapGlyphIMGP 0 |
|---|
| 1731 | #endif |
|---|
| 1732 | |
|---|
| 1733 | #ifdef _UT_USE_BITMAP_SBM |
|---|
| 1734 | #include "_utfBitmapSBM.cxx" |
|---|
| 1735 | #else |
|---|
| 1736 | #define ut_PrepareRasterBitmapGlyphSBM 0 |
|---|
| 1737 | #define ut_MakeRasterBitmapGlyphSBM 0 |
|---|
| 1738 | #endif |
|---|
| 1739 | |
|---|
| 1740 | #ifdef _UT_USE_BITMAP_SBMP |
|---|
| 1741 | #include "_utfBitmapSBMP.cxx" |
|---|
| 1742 | #else |
|---|
| 1743 | #define ut_PrepareRasterBitmapGlyphSBMP 0 |
|---|
| 1744 | #define ut_MakeRasterBitmapGlyphSBMP 0 |
|---|
| 1745 | #endif |
|---|
| 1746 | |
|---|
| 1747 | #ifdef _UT_USE_BITMAP_LCD |
|---|
| 1748 | #include "_utfBitmapLCD.cxx" |
|---|
| 1749 | #else |
|---|
| 1750 | #define ut_PrepareRasterBitmapGlyphLCD 0 |
|---|
| 1751 | #define ut_MakeRasterBitmapGlyphLCD 0 |
|---|
| 1752 | #endif |
|---|
| 1753 | |
|---|
| 1754 | #ifdef _UT_USE_BITMAP_LCDR |
|---|
| 1755 | #include "_utfBitmapLCDR.cxx" |
|---|
| 1756 | #else |
|---|
| 1757 | #define ut_PrepareRasterBitmapGlyphLCDR 0 |
|---|
| 1758 | #define ut_MakeRasterBitmapGlyphLCDR 0 |
|---|
| 1759 | #endif |
|---|
| 1760 | |
|---|
| 1761 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 1762 | #define ut_PrepareRasterBitmapGlyphFnt fontManager->PrepareRasterBitmapGlyphFnt |
|---|
| 1763 | #define SET_VALUE(index, value) ut_PrepareRasterBitmapGlyphFnt[index] = value |
|---|
| 1764 | UT_STATIC_API void ut_InitPrepareRasterBitmapGlyphFnt(UT_FONT_MANAGER* fontManager) |
|---|
| 1765 | { |
|---|
| 1766 | #else |
|---|
| 1767 | #define SET_VALUE(index, value) value |
|---|
| 1768 | #define ut_InitPrepareRasterBitmapGlyphFnt(fontManager) |
|---|
| 1769 | static UT_BOOL (*ut_PrepareRasterBitmapGlyphFnt[])(UT_FC* fc, UT_IMAGE* image) = |
|---|
| 1770 | { |
|---|
| 1771 | #endif |
|---|
| 1772 | SET_VALUE(0, 0), |
|---|
| 1773 | SET_VALUE(1, ut_PrepareRasterBitmapGlyphIMG), |
|---|
| 1774 | SET_VALUE(2, ut_PrepareRasterBitmapGlyphSBM), |
|---|
| 1775 | SET_VALUE(3, ut_PrepareRasterBitmapGlyphLCD), |
|---|
| 1776 | SET_VALUE(4, ut_PrepareRasterBitmapGlyphIMGP), |
|---|
| 1777 | SET_VALUE(5, ut_PrepareRasterBitmapGlyphSBMP), |
|---|
| 1778 | SET_VALUE(6, ut_PrepareRasterBitmapGlyphLCDR) |
|---|
| 1779 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 1780 | ;} |
|---|
| 1781 | #else |
|---|
| 1782 | }; |
|---|
| 1783 | #endif |
|---|
| 1784 | #undef SET_VALUE |
|---|
| 1785 | |
|---|
| 1786 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 1787 | #define ut_MakeRasterBitmapGlyphFnt fontManager->MakeRasterBitmapGlyphFnt |
|---|
| 1788 | #define SET_VALUE(index, value) ut_MakeRasterBitmapGlyphFnt[index] = value |
|---|
| 1789 | UT_STATIC_API void ut_InitMakeRasterBitmapGlyphFnt(UT_FONT_MANAGER* fontManager) |
|---|
| 1790 | { |
|---|
| 1791 | #else |
|---|
| 1792 | #define SET_VALUE(index, value) value |
|---|
| 1793 | #define ut_InitMakeRasterBitmapGlyphFnt(fontManager) |
|---|
| 1794 | static UT_BOOL (*ut_MakeRasterBitmapGlyphFnt[])(UT_FC* fc, UT_IMAGE* image) = |
|---|
| 1795 | { |
|---|
| 1796 | #endif |
|---|
| 1797 | SET_VALUE(0, 0), |
|---|
| 1798 | SET_VALUE(1, ut_MakeRasterBitmapGlyphIMG), |
|---|
| 1799 | SET_VALUE(2, ut_MakeRasterBitmapGlyphSBM), |
|---|
| 1800 | SET_VALUE(3, ut_MakeRasterBitmapGlyphLCD), |
|---|
| 1801 | SET_VALUE(4, ut_MakeRasterBitmapGlyphIMGP), |
|---|
| 1802 | SET_VALUE(5, ut_MakeRasterBitmapGlyphSBMP), |
|---|
| 1803 | SET_VALUE(6, ut_MakeRasterBitmapGlyphLCDR) |
|---|
| 1804 | #ifdef _UT_NO_DATA_SEGMENT |
|---|
| 1805 | ;} |
|---|
| 1806 | #else |
|---|
| 1807 | }; |
|---|
| 1808 | #endif |
|---|
| 1809 | #undef SET_VALUE |
|---|
| 1810 | |
|---|
| 1811 | #endif /*#ifdef _UT_USE_BITMAP_FONT*/ |
|---|
| 1812 | |
|---|
| 1813 | /***************************************************************************/ |
|---|
| 1814 | |
|---|
| 1815 | void ut_BitmapEffect(UT_FC* fc, UT_IMAGE* image) |
|---|
| 1816 | { |
|---|
| 1817 | UT_FONT_TASK* task = fc->task; |
|---|
| 1818 | int x, y; |
|---|
| 1819 | int i_xSize = image->bbox.sx; |
|---|
| 1820 | int i_ySize = image->bbox.sy; |
|---|
| 1821 | int d_bSize = image->bSize; |
|---|
| 1822 | unsigned char* s; |
|---|
| 1823 | unsigned char* d; |
|---|
| 1824 | if (task->emulItalic) |
|---|
| 1825 | { |
|---|
| 1826 | d = image->data; |
|---|
| 1827 | for (y=0; y<image->bbox.sy; y++) |
|---|
| 1828 | { |
|---|
| 1829 | int dx = ut_ItalicY((y<<_UT_PIXEL_SHIFT)>>_UT_PIXEL_SHIFT); |
|---|
| 1830 | if (dx) |
|---|
| 1831 | { |
|---|
| 1832 | for (x=image->bbox.sx-dx-1; x>=0; x--) |
|---|
| 1833 | { |
|---|
| 1834 | d[x+dx] = d[x]; |
|---|
| 1835 | d[x] = 0; |
|---|
| 1836 | } |
|---|
| 1837 | } |
|---|
| 1838 | d += image->bSize; |
|---|
| 1839 | } |
|---|
| 1840 | image->bbox.ox += ut_ItalicY((image->bbox.oy<<_UT_PIXEL_SHIFT)>>_UT_PIXEL_SHIFT); |
|---|
| 1841 | task->emulItalic = 0; |
|---|
| 1842 | } |
|---|
| 1843 | if (task->emulBold) |
|---|
| 1844 | { |
|---|
| 1845 | d = image->data; |
|---|
| 1846 | for (y=0; y<image->bbox.sy; y++) |
|---|
| 1847 | { |
|---|
| 1848 | for (x=image->bbox.sx; x; x--) |
|---|
| 1849 | d[x] |= d[x-1]; |
|---|
| 1850 | d += image->bSize; |
|---|
| 1851 | } |
|---|
| 1852 | if (image->width) if (!fc->isFixedPitch) image->width += ut_BoldExtra(fc->xSize); |
|---|
| 1853 | task->emulBold = 0; |
|---|
| 1854 | } |
|---|
| 1855 | //s; |
|---|
| 1856 | #ifdef _UT_USE_BITMAP_EFFECT |
|---|
| 1857 | #include "_utfBitmapEffect.cxx" |
|---|
| 1858 | #endif |
|---|
| 1859 | } |
|---|
| 1860 | |
|---|
| 1861 | #ifdef _UT_USE_BITMAP_FONT |
|---|
| 1862 | |
|---|
| 1863 | #ifdef _UT_USE_BITMAP_SCALE |
|---|
| 1864 | #include "_utfBitmapScale.cxx" |
|---|
| 1865 | #endif |
|---|
| 1866 | |
|---|
| 1867 | UT_BOOL ut_PrepareRasterGlyphBitmap(UT_FC* fc, UT_IMAGE* image) |
|---|
| 1868 | { |
|---|
| 1869 | // UT_FONT_MANAGER* fontManager = fc->task->fontManager; |
|---|
| 1870 | UT_GLYPH* glyph = fc->task->glyph; |
|---|
| 1871 | UT_BOOL result; |
|---|
| 1872 | image->width = glyph->width; |
|---|
| 1873 | image->height = glyph->height; |
|---|
| 1874 | image->xAdvance = image->width; |
|---|
| 1875 | image->yAdvance = 0; |
|---|
| 1876 | if (fc->rasterType != _UT_RASTER_TYPE_BITMAP) |
|---|
| 1877 | { |
|---|
| 1878 | if ((glyph->cmap->glyphType == _UT_BITMAP_TYPE_IMG) || |
|---|
| 1879 | (glyph->cmap->glyphType == _UT_BITMAP_TYPE_IMGP)) |
|---|
| 1880 | { |
|---|
| 1881 | int dd = 0; |
|---|
| 1882 | UT_TRACE_TAB_INC(); |
|---|
| 1883 | if (!glyph->count) |
|---|
| 1884 | { |
|---|
| 1885 | image->type = _UT_IMAGE_TYPE_NULL; |
|---|
| 1886 | image->bbox.ox = 0; |
|---|
| 1887 | image->bbox.oy = 0; |
|---|
| 1888 | image->bbox.sx = 0; |
|---|
| 1889 | image->bbox.sy = 0; |
|---|
| 1890 | image->bSize = 0; |
|---|
| 1891 | image->lSize = 0; |
|---|
| 1892 | UT_TRACE_TAB_DEC(); |
|---|
| 1893 | return _UT_TRUE; |
|---|
| 1894 | } |
|---|
| 1895 | if ((glyph->count == 1) || (glyph->cmap->glyphBBoxType == _UT_GLYPH_BBOX_FIXED)) |
|---|
| 1896 | { |
|---|
| 1897 | UT_DATA* data = glyph->data; |
|---|
| 1898 | UT_TRACE1("if (FIXED_BBOX)"); |
|---|
| 1899 | data->bbox.ox += data->xOffset; |
|---|
| 1900 | data->xOffset = 0; |
|---|
| 1901 | image->bbox.ox = data->bbox.ox; |
|---|
| 1902 | image->bbox.oy = data->bbox.oy; |
|---|
| 1903 | image->bbox.sx = data->bbox.sx; |
|---|
| 1904 | image->bbox.sy = data->bbox.sy; |
|---|
| 1905 | } |
|---|
| 1906 | else |
|---|
| 1907 | { |
|---|
| 1908 | UT_TRACE1("else"); |
|---|
| 1909 | ut_GetImageBbox(fc, image); |
|---|
| 1910 | } |
|---|
| 1911 | if (fc->task->emulItalic) |
|---|
| 1912 | { |
|---|
| 1913 | image->bbox.sx += ut_ItalicY((image->bbox.sy<<_UT_PIXEL_SHIFT)>>_UT_PIXEL_SHIFT); |
|---|
| 1914 | } |
|---|
| 1915 | image->bbox.sx += fc->task->emulBold << 1; |
|---|
| 1916 | #ifdef _UT_USE_BITMAP_SCALE |
|---|
| 1917 | if (fc->bitmapScaleType >= _UT_BITMAP_SCALE_HN) |
|---|
| 1918 | { |
|---|
| 1919 | if (image->bbox.ox & 1) image->bbox.sx++; |
|---|
| 1920 | if (image->bbox.oy & 1) image->bbox.sy++; |
|---|
| 1921 | image->bbox.sx += image->bbox.sx & 1; |
|---|
| 1922 | image->bbox.sy += image->bbox.sy & 1; |
|---|
| 1923 | if (image->bbox.ox < 0) image->bbox.ox += image->bbox.ox & 1; |
|---|
| 1924 | else image->bbox.ox -= image->bbox.ox & 1; |
|---|
| 1925 | if (image->bbox.oy < 0) image->bbox.oy += image->bbox.oy & 1; |
|---|
| 1926 | else image->bbox.oy -= image->bbox.oy & 1; |
|---|
| 1927 | } |
|---|
| 1928 | #endif |
|---|
| 1929 | #ifdef _UT_USE_BITMAP_EFFECT |
|---|
| 1930 | if (!fc->bitmapScaleType) |
|---|
| 1931 | { |
|---|
| 1932 | if (fc->task->emulOutline) dd += 1; |
|---|
| 1933 | else { |
|---|
| 1934 | if (fc->task->emulEdge){ |
|---|
| 1935 | if (fc->task->emulEdge == _UT_EDGE_TYPE_BORDER) |
|---|
| 1936 | dd += ut_GetExtraSizeEdge(fc->ySize) << 2; |
|---|
| 1937 | else |
|---|
| 1938 | dd += ut_GetExtraSizeEdge(fc->ySize) << 1; |
|---|
| 1939 | } |
|---|
| 1940 | } |
|---|
| 1941 | if (fc->task->emulSmooth && !fc->task->emulEdge) dd += 2; |
|---|
| 1942 | } |
|---|
| 1943 | #endif |
|---|
| 1944 | image->bbox.ox -= dd; |
|---|
| 1945 | image->bbox.oy -= dd; |
|---|
| 1946 | image->bbox.sx += dd+dd; |
|---|
| 1947 | image->bbox.sy += dd+dd; |
|---|
| 1948 | image->type = _UT_IMAGE_TYPE_BITMAP_65; |
|---|
| 1949 | image->bSize = ut_BALIGN(image->bbox.sx); |
|---|
| 1950 | image->lSize = image->bSize * image->bbox.sy; |
|---|
| 1951 | UT_TRACE2("image->bbox.ox = %d", image->bbox.ox); |
|---|
| 1952 | UT_TRACE2("image->bbox.oy = %d", image->bbox.oy); |
|---|
| 1953 | UT_TRACE2("image->bbox.sx = %d", image->bbox.sx); |
|---|
| 1954 | UT_TRACE2("image->bbox.sy = %d", image->bbox.sy); |
|---|
| 1955 | UT_TRACE2("image->bSize = %d", image->bSize); |
|---|
| 1956 | UT_TRACE2("image->lSize = %d", image->lSize); |
|---|
| 1957 | UT_TRACE_TAB_DEC(); |
|---|
| 1958 | return _UT_TRUE; |
|---|
| 1959 | } |
|---|
| 1960 | } |
|---|
| 1961 | UT_TRACE1("ut_PrepareRasterGlyphBitmap()"); |
|---|
| 1962 | UT_TRACE_TAB_INC(); |
|---|
| 1963 | if (!glyph->count) |
|---|
| 1964 | { |
|---|
| 1965 | image->type = _UT_IMAGE_TYPE_NULL; |
|---|
| 1966 | image->bbox.ox = 0; |
|---|
| 1967 | image->bbox.oy = 0; |
|---|
| 1968 | image->bbox.sx = 0; |
|---|
| 1969 | image->bbox.sy = 0; |
|---|
| 1970 | image->bSize = 0; |
|---|
| 1971 | image->lSize = 0; |
|---|
| 1972 | UT_TRACE1("image->type = _UT_IMAGE_TYPE_NULL"); |
|---|
| 1973 | UT_TRACE_TAB_DEC(); |
|---|
| 1974 | return _UT_TRUE; |
|---|
| 1975 | } |
|---|
| 1976 | result = ut_PrepareRasterBitmapGlyphFnt[glyph->cmap->glyphType](fc, image); |
|---|
| 1977 | UT_TRACE_TAB_DEC(); |
|---|
| 1978 | return result; |
|---|
| 1979 | } |
|---|
| 1980 | |
|---|
| 1981 | UT_BOOL utm_MakeImageOfBitmapFont(UT_FC* fc, UT_IMAGE* image) |
|---|
| 1982 | { |
|---|
| 1983 | UT_FONT_MANAGER* fontManager = fc->task->fontManager; |
|---|
| 1984 | UT_GLYPH* glyph = fc->task->glyph; |
|---|
| 1985 | UT_BOOL result; |
|---|
| 1986 | if (image->type == _UT_IMAGE_TYPE_NULL_GLYPH) return _UT_TRUE; |
|---|
| 1987 | if (image->type == _UT_IMAGE_TYPE_NULL) |
|---|
| 1988 | { |
|---|
| 1989 | #ifdef _UT_USE_BITMAP_SCALE |
|---|
| 1990 | #if defined(_UT_USE_BITMAP_IMG) || defined(_UT_USE_BITMAP_IMGP) |
|---|
| 1991 | if (fc->bitmapScaleType) ut_ScaleImage(image, image, fc); |
|---|
| 1992 | #endif |
|---|
| 1993 | #endif |
|---|
| 1994 | return _UT_TRUE; |
|---|
| 1995 | } |
|---|
| 1996 | if (fc->rasterType != _UT_RASTER_TYPE_BITMAP) |
|---|
| 1997 | { |
|---|
| 1998 | int scaledImageDataSize = 0; |
|---|
| 1999 | unsigned char* scaledImageData = 0; |
|---|
| 2000 | #ifdef _UT_USE_BITMAP_IMG |
|---|
| 2001 | if (fc->bitmapScaleType) scaledImageDataSize = ut_BALIGN(image->bbox.sx*2) * (image->bbox.sy*2); |
|---|
| 2002 | if (glyph->cmap->glyphType == _UT_BITMAP_TYPE_IMG) |
|---|
| 2003 | { |
|---|
| 2004 | int i = glyph->count; |
|---|
| 2005 | UT_DATA* data = glyph->data; |
|---|
| 2006 | UT_TRACE1("utm_MakeImageOfBitmapFont(_UT_BITMAP_TYPE_IMG)"); |
|---|
| 2007 | UT_TRACE_TAB_INC(); |
|---|
| 2008 | scaledImageData = (unsigned char*)ut_AllocScanBuffer(fc->task, image, scaledImageDataSize); |
|---|
| 2009 | UT_MEMSET(image->data, 0, image->lSize); |
|---|
| 2010 | for (; i; i--,data++) |
|---|
| 2011 | { |
|---|
| 2012 | ut_Bit2ByteImage(fontManager, data->p.u8, ut_BSIZE8(data->bbox.sx), |
|---|
| 2013 | image->data, image->bSize, |
|---|
| 2014 | data->bbox.sx, data->bbox.sy, |
|---|
| 2015 | data->bbox.ox-image->bbox.ox, data->bbox.oy-image->bbox.oy); |
|---|
| 2016 | } |
|---|
| 2017 | #ifdef _UT_USE_BITMAP_SCALE |
|---|
| 2018 | if (fc->bitmapScaleType) |
|---|
| 2019 | { |
|---|
| 2020 | UT_IMAGE scaled; |
|---|
| 2021 | scaled.data = scaledImageData; |
|---|
| 2022 | ut_ScaleImage(image, &scaled, fc); |
|---|
| 2023 | *image = scaled; |
|---|
| 2024 | } |
|---|
| 2025 | #endif |
|---|
| 2026 | ut_BitmapEffect(fc, image); |
|---|
| 2027 | UT_TRACE_TAB_DEC(); |
|---|
| 2028 | return _UT_TRUE; |
|---|
| 2029 | } |
|---|
| 2030 | #endif |
|---|
| 2031 | #ifdef _UT_USE_BITMAP_IMGP |
|---|
| 2032 | if (glyph->cmap->glyphType == _UT_BITMAP_TYPE_IMGP) |
|---|
| 2033 | { |
|---|
| 2034 | int i = glyph->count; |
|---|
| 2035 | UT_DATA* data = glyph->data; |
|---|
| 2036 | UT_TRACE1("RasterBitmapGlyph(_UT_BITMAP_TYPE_IMGP)"); |
|---|
| 2037 | UT_TRACE_TAB_INC(); |
|---|
| 2038 | scaledImageData = (unsigned char*)ut_AllocScanBuffer(fc->task, image, scaledImageDataSize); |
|---|
| 2039 | UT_MEMSET(image->data, 0, image->lSize); |
|---|
| 2040 | for (; i; i--,data++) |
|---|
| 2041 | { |
|---|
| 2042 | ut_Bit2ByteImageP(fontManager, data->p.u8, |
|---|
| 2043 | image->data, image->bSize, |
|---|
| 2044 | data->bbox.sx, data->bbox.sy, |
|---|
| 2045 | data->bbox.ox-image->bbox.ox, data->bbox.oy-image->bbox.oy); |
|---|
| 2046 | } |
|---|
| 2047 | #ifdef _UT_USE_BITMAP_SCALE |
|---|
| 2048 | if (fc->bitmapScaleType) |
|---|
| 2049 | { |
|---|
| 2050 | UT_IMAGE scaled; |
|---|
| 2051 | scaled.data = scaledImageData; |
|---|
| 2052 | ut_ScaleImage(image, &scaled, fc); |
|---|
| 2053 | *image = scaled; |
|---|
| 2054 | } |
|---|
| 2055 | #endif |
|---|
| 2056 | ut_BitmapEffect(fc, image); |
|---|
| 2057 | UT_TRACE_TAB_DEC(); |
|---|
| 2058 | return _UT_TRUE; |
|---|
| 2059 | } |
|---|
| 2060 | #endif |
|---|
| 2061 | } |
|---|
| 2062 | UT_TRACE1("utm_MakeImageOfBitmapFont()"); |
|---|
| 2063 | UT_TRACE_TAB_INC(); |
|---|
| 2064 | result = ut_MakeRasterBitmapGlyphFnt[glyph->cmap->glyphType](fc, image); |
|---|
| 2065 | UT_TRACE_TAB_DEC(); |
|---|
| 2066 | return result; |
|---|
| 2067 | } |
|---|
| 2068 | |
|---|
| 2069 | #else /*#ifdef _UT_USE_BITMAP_FONT*/ |
|---|
| 2070 | |
|---|
| 2071 | #define ut_InitPrepareRasterBitmapGlyphFnt(fontManager) |
|---|
| 2072 | #define ut_InitMakeRasterBitmapGlyphFnt(fontManager) |
|---|
| 2073 | |
|---|
| 2074 | #endif /*#ifdef _UT_USE_BITMAP_FONT*/ |
|---|
| 2075 | |
|---|
| 2076 | /***************************************************************************/ |
|---|
| 2077 | |
|---|
| 2078 | void utm_InitFontStream(UT_FONT_STREAM* stream, void* fontAddress) |
|---|
| 2079 | { |
|---|
| 2080 | char* p = (char*)fontAddress; |
|---|
| 2081 | if ((p[0] == 'W') && (p[1] == 'T') && (p[2] == 'F')) stream->basement = _WT_VIRTUAL_HEADER_SIZE; |
|---|
| 2082 | else stream->basement = 0; |
|---|
| 2083 | stream->handle = fontAddress; |
|---|
| 2084 | stream->Read = 0; |
|---|
| 2085 | stream->next = 0; |
|---|
| 2086 | } |
|---|
| 2087 | |
|---|
| 2088 | void utm_InitFileFontStream(UT_FONT_STREAM* stream, void* fileHandle, |
|---|
| 2089 | int (*Read)(void* handle, int offset, int length, void* buffer)) |
|---|
| 2090 | { |
|---|
| 2091 | char p[4]; |
|---|
| 2092 | Read(fileHandle, 0, 4, p); |
|---|
| 2093 | if ((p[0] == 'W') && (p[1] == 'T') && (p[2] == 'F')) stream->basement = _WT_VIRTUAL_HEADER_SIZE; |
|---|
| 2094 | else stream->basement = 0; |
|---|
| 2095 | stream->handle = fileHandle; |
|---|
| 2096 | stream->Read = Read; |
|---|
| 2097 | stream->next = 0; |
|---|
| 2098 | } |
|---|
| 2099 | |
|---|
| 2100 | /***************************************************************************/ |
|---|
| 2101 | |
|---|
| 2102 | #ifdef _UT_USE_OUTLINE_FONT |
|---|
| 2103 | void ut_InitMono2GrayLevel(UT_FONT_MANAGER* fontManager); |
|---|
| 2104 | #else /*#ifdef _UT_USE_OUTLINE_FONT*/ |
|---|
| 2105 | #define ut_InitMono2GrayLevel(fontManager) |
|---|
| 2106 | #endif /*#ifdef _UT_USE_OUTLINE_FONT*/ |
|---|
| 2107 | UT_STATIC_API void ut_InitBit2ByteImageFnt(UT_FONT_MANAGER* fontManager); |
|---|
| 2108 | |
|---|
| 2109 | void utm_InitFontManager(UT_FONT_MANAGER* fontManager, |
|---|
| 2110 | void* (*AllocMemory)(unsigned int), void (*FreeMemory)(void*), |
|---|
| 2111 | UT_FACE* staticFontBuffer, int staticFontBufferCount) |
|---|
| 2112 | { |
|---|
| 2113 | UT_TRACE1("utm_InitFontManager()"); |
|---|
| 2114 | UT_TRACE_TAB_INC(); |
|---|
| 2115 | UT_MEMSET(fontManager, 0, sizeof(UT_FONT_MANAGER)); |
|---|
| 2116 | fontManager->AllocMemory = AllocMemory; |
|---|
| 2117 | fontManager->FreeMemory = FreeMemory; |
|---|
| 2118 | fontManager->staticFontBuffer = staticFontBuffer; |
|---|
| 2119 | fontManager->staticFontBufferCount = staticFontBufferCount; |
|---|
| 2120 | ut_InitGetGlyphMetricFnt(fontManager); |
|---|
| 2121 | ut_InitGetGlyphBboxFnt(fontManager); |
|---|
| 2122 | ut_InitGetGlyphDataFnt(fontManager); |
|---|
| 2123 | ut_InitGetGlyphFnt(fontManager); |
|---|
| 2124 | ut_InitPrepareRasterBitmapGlyphFnt(fontManager); |
|---|
| 2125 | ut_InitMakeRasterBitmapGlyphFnt(fontManager); |
|---|
| 2126 | ut_InitBit2ByteImageFnt(fontManager); |
|---|
| 2127 | ut_InitJohap3JungsungMap0(fontManager); |
|---|
| 2128 | ut_InitJohap3JungsungMap1(fontManager); |
|---|
| 2129 | ut_InitJohap3JungsungMap1(fontManager); |
|---|
| 2130 | ut_InitKsToUniCode(fontManager); |
|---|
| 2131 | ut_InitMono2GrayLevel(fontManager); |
|---|
| 2132 | UT_TRACE_TAB_DEC(); |
|---|
| 2133 | } |
|---|
| 2134 | |
|---|
| 2135 | void utm_TermFontManager(UT_FONT_MANAGER* fontManager) |
|---|
| 2136 | { |
|---|
| 2137 | UT_FACE* face = fontManager->headFace; |
|---|
| 2138 | UT_TRACE1("utm_TermFontManager()"); |
|---|
| 2139 | UT_TRACE_TAB_INC(); |
|---|
| 2140 | utm_CacheTerm(fontManager); |
|---|
| 2141 | while (face) |
|---|
| 2142 | { |
|---|
| 2143 | UT_FACE* nextFace = face->nextFace; |
|---|
| 2144 | UT_FACE* font = face; |
|---|
| 2145 | while (font) |
|---|
| 2146 | { |
|---|
| 2147 | UT_FACE* nextFont = font->nextFont; |
|---|
| 2148 | while (font) |
|---|
| 2149 | { |
|---|
| 2150 | UT_FACE* sameFont = font->sameFont; |
|---|
| 2151 | ut_FreeFace(fontManager, font); |
|---|
| 2152 | font = sameFont; |
|---|
| 2153 | } |
|---|
| 2154 | font = nextFont; |
|---|
| 2155 | } |
|---|
| 2156 | face = nextFace; |
|---|
| 2157 | } |
|---|
| 2158 | fontManager->headFace = 0; |
|---|
| 2159 | fontManager->defaultFace = 0; |
|---|
| 2160 | UT_TRACE_TAB_DEC(); |
|---|
| 2161 | } |
|---|
| 2162 | |
|---|
| 2163 | UT_STATIC_API UT_FACE* utm_FindFace(UT_FONT_MANAGER* fontManager, UT_U32 fontID) |
|---|
| 2164 | { |
|---|
| 2165 | UT_DEFINE_FONT_INFO_1(cap, temp_cap); |
|---|
| 2166 | UT_FACE* face = fontManager->headFace; |
|---|
| 2167 | for (; face; face=face->nextFace) |
|---|
| 2168 | { |
|---|
| 2169 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 2170 | if (cap->id == fontID) return face; |
|---|
| 2171 | } |
|---|
| 2172 | return 0; |
|---|
| 2173 | } |
|---|
| 2174 | |
|---|
| 2175 | UT_BOOL utm_GetTypefaceList(UT_FONT_MANAGER* fontManager, void* param, |
|---|
| 2176 | void (*Callback)(void* param, UT_CODE* typefaceName, UT_U32 id)) |
|---|
| 2177 | { |
|---|
| 2178 | UT_DEFINE_FONT_INFO_2(cap, temp_cap); |
|---|
| 2179 | UT_FACE* face = fontManager->headFace; |
|---|
| 2180 | if (!Callback) return _UT_FALSE; |
|---|
| 2181 | for (; face; face=face->nextFace) |
|---|
| 2182 | { |
|---|
| 2183 | utm_GetFontInfo_2(&face->stream, face, cap); |
|---|
| 2184 | Callback(param, cap->typefaceName, cap->info.id); |
|---|
| 2185 | } |
|---|
| 2186 | return _UT_TRUE; |
|---|
| 2187 | } |
|---|
| 2188 | |
|---|
| 2189 | UT_BOOL utm_GetFontList(UT_FONT_MANAGER* fontManager, void* param, |
|---|
| 2190 | void (*Callback)(void* param, UT_CODE* typefaceName, UT_U32 id, |
|---|
| 2191 | UT_CODE* fontName, int fontHeight, int fontWidth, int weight, UT_BOOL isItalic)) |
|---|
| 2192 | { |
|---|
| 2193 | UT_DEFINE_FONT_INFO_2(cap, temp_cap); |
|---|
| 2194 | UT_FACE* face = fontManager->headFace; |
|---|
| 2195 | if (!Callback) return _UT_FALSE; |
|---|
| 2196 | for (; face; face=face->nextFace) |
|---|
| 2197 | { |
|---|
| 2198 | UT_FACE* pos = face; |
|---|
| 2199 | for (; pos; pos=pos->nextFont) |
|---|
| 2200 | { |
|---|
| 2201 | utm_GetFontInfo_2(&pos->stream, pos, cap); |
|---|
| 2202 | Callback(param, cap->typefaceName, cap->info.id, cap->fontName, |
|---|
| 2203 | cap->info.limit, cap->info.xLimit, cap->info.weight, cap->info.isItalic); |
|---|
| 2204 | } |
|---|
| 2205 | } |
|---|
| 2206 | return _UT_TRUE; |
|---|
| 2207 | } |
|---|
| 2208 | |
|---|
| 2209 | #ifdef _UT_USING_CMAP_CACHE |
|---|
| 2210 | UT_STATIC_API int ut_ReadMemory(void* handle, int offset, int length, void* buffer) |
|---|
| 2211 | { |
|---|
| 2212 | UT_MEMCPY(buffer, ((char*)handle)+offset, length); |
|---|
| 2213 | return length; |
|---|
| 2214 | } |
|---|
| 2215 | #endif |
|---|
| 2216 | |
|---|
| 2217 | UT_BOOL utm_AddFont(UT_FONT_MANAGER* fontManager, void* fontAddress) |
|---|
| 2218 | { |
|---|
| 2219 | UT_FONT_STREAM stream; |
|---|
| 2220 | UT_TRACE2("utm_AddFont(%d)", (unsigned long)fontAddress); |
|---|
| 2221 | #ifdef _UT_USING_CMAP_CACHE |
|---|
| 2222 | utm_InitFileFontStream(&stream, fontAddress, ut_ReadMemory); |
|---|
| 2223 | #else |
|---|
| 2224 | utm_InitFontStream(&stream, fontAddress); |
|---|
| 2225 | #endif |
|---|
| 2226 | return utm_AddStreamFont(fontManager, &stream); |
|---|
| 2227 | } |
|---|
| 2228 | |
|---|
| 2229 | UT_STATIC_API UT_FACE* utm_FindFont(UT_FACE* face, UT_FONT* find) |
|---|
| 2230 | { |
|---|
| 2231 | UT_DEFINE_FONT_INFO_1(cap, temp_cap); |
|---|
| 2232 | for (; face; face=face->nextFont) |
|---|
| 2233 | { |
|---|
| 2234 | utm_GetFontInfo_1(&face->stream, face, cap); |
|---|
| 2235 | if (cap->limit != find->limit) continue; |
|---|
| 2236 | if (cap->isItalic != find->isItalic) continue; |
|---|
| 2237 | if (cap->weight != find->weight) continue; |
|---|
| 2238 | return face; |
|---|
| 2239 | } |
|---|
| 2240 | return 0; |
|---|
| 2241 | } |
|---|
| 2242 | |
|---|
| 2243 | UT_BOOL utm_AddStreamFont(UT_FONT_MANAGER* fontManager, UT_FONT_STREAM* stream) |
|---|
| 2244 | { |
|---|
| 2245 | UT_FACE* face; |
|---|
| 2246 | UT_FACE* add; |
|---|
| 2247 | UT_FONT_CAP cap; |
|---|
| 2248 | UT_FONT* font = &cap.info; |
|---|
| 2249 | UT_TRACE1("utm_AddStreamFont()"); |
|---|
| 2250 | UT_TRACE_TAB_INC(); |
|---|
| 2251 | for (;;) |
|---|
| 2252 | { |
|---|
| 2253 | if (!utm_GetFontCap(stream, &cap, sizeof(cap))) break; |
|---|
| 2254 | UT_TRACE2("identifier = 0x%08x", font->identifier); |
|---|
| 2255 | face = utm_FindFace(fontManager, font->id); |
|---|
| 2256 | if (font->identifier != _UT_IDENTIFIER) break; |
|---|
| 2257 | UT_TRACE1("FONT()"); |
|---|
| 2258 | UT_TRACE_TAB_INC(); |
|---|
| 2259 | UT_TRACE2("id = %d", font->id); |
|---|
| 2260 | UT_TRACE2("italic = %d", font->isItalic); |
|---|
| 2261 | UT_TRACE2("weight = %d", font->weight); |
|---|
| 2262 | UT_TRACE2("limit = %d", font->limit); |
|---|
| 2263 | add = ut_AllocFace(fontManager); |
|---|
| 2264 | if (!add) |
|---|
| 2265 | { |
|---|
| 2266 | return _UT_FALSE; |
|---|
| 2267 | } |
|---|
| 2268 | if (face) |
|---|
| 2269 | { |
|---|
| 2270 | UT_FACE* sameFont = utm_FindFont(face, font); |
|---|
| 2271 | if (sameFont) |
|---|
| 2272 | { |
|---|
| 2273 | UT_FACE temp = *sameFont; |
|---|
| 2274 | sameFont->isVolatile = add->isVolatile; |
|---|
| 2275 | sameFont->stream = *stream; |
|---|
| 2276 | sameFont->sameFont = add; |
|---|
| 2277 | #ifdef _UT_USE_FONT_INFO_CACHE |
|---|
| 2278 | sameFont->font = cap; |
|---|
| 2279 | #endif |
|---|
| 2280 | *add = temp; |
|---|
| 2281 | } |
|---|
| 2282 | else |
|---|
| 2283 | { |
|---|
| 2284 | UT_FACE temp = *face; |
|---|
| 2285 | face->isVolatile = add->isVolatile; |
|---|
| 2286 | face->stream = *stream; |
|---|
| 2287 | face->sameFont = 0; |
|---|
| 2288 | face->nextFont = add; |
|---|
| 2289 | #ifdef _UT_USE_FONT_INFO_CACHE |
|---|
| 2290 | face->font = cap; |
|---|
| 2291 | #endif |
|---|
| 2292 | *add = temp; |
|---|
| 2293 | } |
|---|
| 2294 | } |
|---|
| 2295 | else |
|---|
| 2296 | { |
|---|
| 2297 | add->stream = *stream; |
|---|
| 2298 | add->sameFont = 0; |
|---|
| 2299 | add->nextFont = 0; |
|---|
| 2300 | #ifdef _UT_USE_FONT_INFO_CACHE |
|---|
| 2301 | add->font = cap; |
|---|
| 2302 | #endif |
|---|
| 2303 | if (fontManager->headFace) add->nextFace = fontManager->headFace; |
|---|
| 2304 | else add->nextFace = 0; |
|---|
| 2305 | fontManager->headFace = add; |
|---|
| 2306 | if (!fontManager->defaultFace) fontManager->defaultFace = add; |
|---|
| 2307 | } |
|---|
| 2308 | stream->basement += font->fileSize; |
|---|
| 2309 | UT_TRACE_TAB_DEC(); |
|---|
| 2310 | } |
|---|
| 2311 | UT_TRACE_TAB_DEC(); |
|---|
| 2312 | return _UT_TRUE; |
|---|
| 2313 | } |
|---|
| 2314 | |
|---|
| 2315 | void* utm_GetNthFontData(void* fontAddress, int index) |
|---|
| 2316 | { |
|---|
| 2317 | char* p = (char*)fontAddress; |
|---|
| 2318 | for (; index; index--) |
|---|
| 2319 | { |
|---|
| 2320 | UT_FONT* font = (UT_FONT*)p; |
|---|
| 2321 | if (ut_SWAP_U32(font->identifier) != _UT_IDENTIFIER) return 0; |
|---|
| 2322 | p += ut_SWAP_U32(font->fileSize); |
|---|
| 2323 | } |
|---|
| 2324 | return p; |
|---|
| 2325 | } |
|---|
| 2326 | |
|---|
| 2327 | /***************************************************************************/ |
|---|
| 2328 | |
|---|
| 2329 | void utm_InitFontTask(UT_FONT_TASK* task, UT_FONT_MANAGER* fontManager, |
|---|
| 2330 | char* staticRasterBuffer, int staticRasterBufferSize) |
|---|
| 2331 | { |
|---|
| 2332 | unsigned long align = ((unsigned long)staticRasterBuffer) & 3; |
|---|
| 2333 | if (align) {staticRasterBuffer += 4 - align; staticRasterBufferSize -= 4 - align;} |
|---|
| 2334 | UT_TRACE1("utm_InitFontTask()"); |
|---|
| 2335 | UT_TRACE_TAB_INC(); |
|---|
| 2336 | UT_MEMSET(task, 0, sizeof(UT_FONT_TASK)); |
|---|
| 2337 | task->fontManager = fontManager; |
|---|
| 2338 | task->staticRasterBuffer = staticRasterBuffer; |
|---|
| 2339 | task->staticRasterBufferSize = staticRasterBufferSize; |
|---|
| 2340 | UT_TRACE_TAB_DEC(); |
|---|
| 2341 | } |
|---|
| 2342 | |
|---|
| 2343 | void utm_TermFontTask(UT_FONT_TASK* task) |
|---|
| 2344 | { |
|---|
| 2345 | UT_TRACE1("utm_TermFontTask()"); |
|---|
| 2346 | UT_TRACE_TAB_INC(); |
|---|
| 2347 | ut_FreeGridFitBuffer(task); |
|---|
| 2348 | utm_FreeScanBuffer(task); |
|---|
| 2349 | UT_TRACE_TAB_DEC(); |
|---|
| 2350 | } |
|---|
| 2351 | |
|---|
| 2352 | /***************************************************************************/ |
|---|
| 2353 | |
|---|
| 2354 | void utm_InitFontContext(UT_FC* fc, UT_FONT_TASK* task, |
|---|
| 2355 | char* staticCmapBuffer, int staticCmapBufferSize) |
|---|
| 2356 | { |
|---|
| 2357 | unsigned long align = ((unsigned long)staticCmapBuffer) & 3; |
|---|
| 2358 | if (align) {staticCmapBuffer += 4 - align; staticCmapBufferSize -= 4 - align;} |
|---|
| 2359 | UT_TRACE1("utm_InitFontContext()"); |
|---|
| 2360 | UT_TRACE_TAB_INC(); |
|---|
| 2361 | UT_MEMSET(fc, 0, sizeof(UT_FC)); |
|---|
| 2362 | fc->task = task; |
|---|
| 2363 | fc->staticCmapBuffer = staticCmapBuffer; |
|---|
| 2364 | fc->staticCmapBufferSize = staticCmapBufferSize; |
|---|
| 2365 | UT_TRACE_TAB_DEC(); |
|---|
| 2366 | } |
|---|
| 2367 | |
|---|
| 2368 | void utm_TermFontContext(UT_FC* fc) |
|---|
| 2369 | { |
|---|
| 2370 | UT_TRACE1("utm_TermFontContext()"); |
|---|
| 2371 | UT_TRACE_TAB_INC(); |
|---|
| 2372 | ut_FreeCmapBuffer(fc); |
|---|
| 2373 | UT_TRACE_TAB_DEC(); |
|---|
| 2374 | } |
|---|
| 2375 | |
|---|
| 2376 | void utm_SetRasterType(UT_FC* fc, int rasterType) |
|---|
| 2377 | { |
|---|
| 2378 | UT_TRACE2("utm_SetRasterType(rasterType = %d)", rasterType); |
|---|
| 2379 | UT_TRACE_TAB_INC(); |
|---|
| 2380 | fc->rasterType = rasterType; |
|---|
| 2381 | UT_TRACE_TAB_DEC(); |
|---|
| 2382 | } |
|---|
| 2383 | |
|---|
| 2384 | UT_BOOL utm_SetFont(UT_FC* fc, UT_U32 fontID) |
|---|
| 2385 | { |
|---|
| 2386 | UT_U32 id = fontID; //jjk updated by jjk |
|---|
| 2387 | UT_FONT_MANAGER* fontManager = fc->task->fontManager; |
|---|
| 2388 | |
|---|
| 2389 | if( id == 0 ) id = 3; //default font style (0)ÀÏ °æ¿ì sytle 3À¸·Î |
|---|
| 2390 | |
|---|
| 2391 | UT_TRACE2("utm_SetFont(fontID = %d)", fontID); |
|---|
| 2392 | UT_TRACE_TAB_INC(); |
|---|
| 2393 | fc->face = utm_FindFace(fontManager, id/*fontID*/); |
|---|
| 2394 | if (!fc->face) fc->face = fontManager->defaultFace; |
|---|
| 2395 | if (!fc->face) |
|---|
| 2396 | { |
|---|
| 2397 | UT_TRACE_TAB_DEC(); |
|---|
| 2398 | return _UT_FALSE; |
|---|
| 2399 | } |
|---|
| 2400 | ut_AdjustFont(fc); |
|---|
| 2401 | UT_TRACE_TAB_DEC(); |
|---|
| 2402 | return _UT_TRUE; |
|---|
| 2403 | } |
|---|
| 2404 | |
|---|
| 2405 | UT_BOOL utm_SetFontDirect(UT_FC* fc, void* fontAddress) |
|---|
| 2406 | { |
|---|
| 2407 | UT_FONT_STREAM stream; |
|---|
| 2408 | utm_InitFontStream(&stream, fontAddress); |
|---|
| 2409 | UT_TRACE1("utm_SetFontDirect()"); |
|---|
| 2410 | UT_TRACE_TAB_INC(); |
|---|
| 2411 | fc->face = 0; |
|---|
| 2412 | utm_SetStreamFontDirect(fc, &stream); |
|---|
| 2413 | ut_AdjustFont(fc); |
|---|
| 2414 | UT_TRACE_TAB_DEC(); |
|---|
| 2415 | return _UT_TRUE; |
|---|
| 2416 | } |
|---|
| 2417 | |
|---|
| 2418 | UT_BOOL utm_SetStreamFontDirect(UT_FC* fc, UT_FONT_STREAM* stream) |
|---|
| 2419 | { |
|---|
| 2420 | *fc->stream = *stream; |
|---|
| 2421 | utm_GetFontCap(stream, &fc->font, sizeof(UT_FONT_CAP)); |
|---|
| 2422 | fc->face = 0; |
|---|
| 2423 | return utm_SetStreamFontDirect_(fc, 0); |
|---|
| 2424 | } |
|---|
| 2425 | |
|---|
| 2426 | void utm_SetSize(UT_FC* fc, int xSize, int ySize) |
|---|
| 2427 | { |
|---|
| 2428 | UT_TRACE2("utm_SetSize(xSize = %d)", xSize); |
|---|
| 2429 | UT_TRACE2(" ySize = %d", ySize); |
|---|
| 2430 | UT_TRACE_TAB_INC(); |
|---|
| 2431 | fc->xSize = xSize; |
|---|
| 2432 | fc->ySize = ySize; |
|---|
| 2433 | UT_TRACE_TAB_DEC(); |
|---|
| 2434 | ut_AdjustFont(fc); |
|---|
| 2435 | } |
|---|
| 2436 | |
|---|
| 2437 | void utm_SetItalic(UT_FC* fc, int allow) |
|---|
| 2438 | { |
|---|
| 2439 | UT_TRACE2("utm_SetItalic(allow = %d)", allow); |
|---|
| 2440 | UT_TRACE_TAB_INC(); |
|---|
| 2441 | fc->isItalic = allow; |
|---|
| 2442 | ut_AdjustFont(fc); |
|---|
| 2443 | UT_TRACE_TAB_DEC(); |
|---|
| 2444 | } |
|---|
| 2445 | |
|---|
| 2446 | void utm_SetBold(UT_FC* fc, int allow) |
|---|
| 2447 | { |
|---|
| 2448 | UT_TRACE2("utm_SetBold(allow = %d)", allow); |
|---|
| 2449 | UT_TRACE_TAB_INC(); |
|---|
| 2450 | fc->isBold = allow; |
|---|
| 2451 | ut_AdjustFont(fc); |
|---|
| 2452 | UT_TRACE_TAB_DEC(); |
|---|
| 2453 | } |
|---|
| 2454 | |
|---|
| 2455 | void utm_SetRotate(UT_FC* fc, int degree) |
|---|
| 2456 | { |
|---|
| 2457 | UT_TRACE2("utm_SetRotate(degree = %d)", degree); |
|---|
| 2458 | UT_TRACE_TAB_INC(); |
|---|
| 2459 | while (degree < 0) degree += 360; |
|---|
| 2460 | while (degree >= 360) degree -= 360; |
|---|
| 2461 | fc->rotateDegree = degree; |
|---|
| 2462 | UT_TRACE_TAB_DEC(); |
|---|
| 2463 | } |
|---|
| 2464 | |
|---|
| 2465 | void utm_SetEdgeType(UT_FC* fc, int edgeType) |
|---|
| 2466 | { |
|---|
| 2467 | UT_TRACE2("utm_SetEdgeType(edgeType = %d)", edgeType); |
|---|
| 2468 | UT_TRACE_TAB_INC(); |
|---|
| 2469 | fc->edgeType = edgeType; |
|---|
| 2470 | UT_TRACE_TAB_DEC(); |
|---|
| 2471 | } |
|---|
| 2472 | |
|---|
| 2473 | void utm_SetSmoothType(UT_FC* fc, int smoothType) |
|---|
| 2474 | { |
|---|
| 2475 | UT_TRACE2("utm_SetSmoothType(smoothType = %d)", smoothType); |
|---|
| 2476 | UT_TRACE_TAB_INC(); |
|---|
| 2477 | fc->smoothType = smoothType; |
|---|
| 2478 | UT_TRACE_TAB_DEC(); |
|---|
| 2479 | } |
|---|
| 2480 | |
|---|
| 2481 | void utm_SetBitmapScaleType(UT_FC* fc, int scaleType) |
|---|
| 2482 | { |
|---|
| 2483 | UT_TRACE2("utm_SetBitmapScaleType(scaleType = %d)", scaleType); |
|---|
| 2484 | UT_TRACE_TAB_INC(); |
|---|
| 2485 | fc->bitmapScaleType = scaleType; |
|---|
| 2486 | UT_TRACE_TAB_DEC(); |
|---|
| 2487 | } |
|---|
| 2488 | |
|---|
| 2489 | void utm_SetGrayStyle(UT_FC* fc, int xGrayType, int yGrayType, int grayAdjust, int grayAdjustValue) |
|---|
| 2490 | { |
|---|
| 2491 | UT_TRACE2("utm_SetGrayType(xGrayType = %d)", xGrayType); |
|---|
| 2492 | UT_TRACE2(" yGrayType = %d", yGrayType); |
|---|
| 2493 | UT_TRACE_TAB_INC(); |
|---|
| 2494 | fc->xGrayType = xGrayType; |
|---|
| 2495 | fc->yGrayType = yGrayType; |
|---|
| 2496 | fc->grayAdjust = grayAdjust; |
|---|
| 2497 | fc->grayAdjustValue = grayAdjustValue; |
|---|
| 2498 | UT_TRACE_TAB_DEC(); |
|---|
| 2499 | } |
|---|
| 2500 | |
|---|
| 2501 | void utm_SetSubPixelType(UT_FC* fc, int subPixelType) |
|---|
| 2502 | { |
|---|
| 2503 | UT_TRACE2("utm_SetSubPixelType(subPixelType = %d)", subPixelType); |
|---|
| 2504 | UT_TRACE_TAB_INC(); |
|---|
| 2505 | fc->subPixelType = subPixelType; |
|---|
| 2506 | UT_TRACE_TAB_DEC(); |
|---|
| 2507 | } |
|---|
| 2508 | |
|---|
| 2509 | void utm_SetFixedPitch(UT_FC* fc, UT_BOOL isFixedPitch) |
|---|
| 2510 | { |
|---|
| 2511 | UT_TRACE2("utm_SetFixedPitch(isFixedPitch = %d)", isFixedPitch); |
|---|
| 2512 | UT_TRACE_TAB_INC(); |
|---|
| 2513 | fc->isFixedPitch = isFixedPitch; |
|---|
| 2514 | fc->fixedWidth = 0; |
|---|
| 2515 | if (isFixedPitch > 1) |
|---|
| 2516 | { |
|---|
| 2517 | fc->fixedWidth = utm_GetCharWidth(fc, (UT_CODE)isFixedPitch); |
|---|
| 2518 | } |
|---|
| 2519 | UT_TRACE_TAB_DEC(); |
|---|
| 2520 | } |
|---|
| 2521 | |
|---|
| 2522 | void utm_SetApplyHint(UT_FC* fc, UT_BOOL allow) |
|---|
| 2523 | { |
|---|
| 2524 | UT_TRACE2("utm_SetApplyHint(allow = %d)", allow); |
|---|
| 2525 | UT_TRACE_TAB_INC(); |
|---|
| 2526 | fc->preventHint = !allow; |
|---|
| 2527 | UT_TRACE_TAB_DEC(); |
|---|
| 2528 | } |
|---|
| 2529 | |
|---|
| 2530 | void utm_SetApplyDropout(UT_FC* fc, UT_BOOL allow) |
|---|
| 2531 | { |
|---|
| 2532 | UT_TRACE2("utm_SetItalic(allow = %d)", allow); |
|---|
| 2533 | UT_TRACE_TAB_INC(); |
|---|
| 2534 | fc->preventDropout = !allow; |
|---|
| 2535 | UT_TRACE_TAB_DEC(); |
|---|
| 2536 | } |
|---|
| 2537 | |
|---|
| 2538 | UT_BOOL utm_GetGlyphFromCmap(UT_FONT_MANAGER* fontManager, UT_CMAP* cmap, UT_CODE code, UT_GLYPH* glyph) |
|---|
| 2539 | { |
|---|
| 2540 | UT_FONT_STREAM stream; |
|---|
| 2541 | utm_InitFontStream(&stream, 0); |
|---|
| 2542 | glyph->cmap = cmap; |
|---|
| 2543 | return ut_GetGlyphFnt[cmap->cmapFormat](fontManager, &stream, cmap, code, glyph); |
|---|
| 2544 | } |
|---|
| 2545 | |
|---|
| 2546 | UT_BOOL utm_GetGlyph(UT_FC* fc, UT_CODE code, UT_GLYPH* glyph) |
|---|
| 2547 | { |
|---|
| 2548 | UT_BOOL is_exist = _UT_FALSE; |
|---|
| 2549 | int saved_width=0, saved_height=0; |
|---|
| 2550 | UT_FONT_MANAGER* fontManager = fc->task->fontManager; |
|---|
| 2551 | UT_FONT_STREAM* stream = fc->stream; |
|---|
| 2552 | UT_TRACE2("utm_GetGlyph(code = 0x%04x)", code); |
|---|
| 2553 | UT_TRACE_TAB_INC(); |
|---|
| 2554 | if (glyph == NULL) |
|---|
| 2555 | return _UT_FALSE; |
|---|
| 2556 | glyph->count = 0; |
|---|
| 2557 | glyph->width = 0; |
|---|
| 2558 | glyph->height = 0; |
|---|
| 2559 | while (stream) |
|---|
| 2560 | { |
|---|
| 2561 | UT_CMAP* cmap = stream->cmap; |
|---|
| 2562 | while (cmap) |
|---|
| 2563 | { |
|---|
| 2564 | if (cmap->startCode == (UT_U16)0xffff) break; |
|---|
| 2565 | UT_TRACE2("cmap->startCode = 0x%04x", ut_SWAP_U16(cmap->startCode)); |
|---|
| 2566 | UT_TRACE2("cmap->endCode = 0x%04x", ut_SWAP_U16(cmap->endCode)); |
|---|
| 2567 | if ((code >= ut_SWAP_U16(cmap->startCode)) && (code <= ut_SWAP_U16(cmap->endCode))) |
|---|
| 2568 | { |
|---|
| 2569 | glyph->cmap = cmap; |
|---|
| 2570 | glyph->stream = stream; |
|---|
| 2571 | if (ut_GetGlyphFnt[cmap->cmapFormat](fontManager, stream, cmap, code, glyph)) |
|---|
| 2572 | { |
|---|
| 2573 | if (glyph->count) |
|---|
| 2574 | { |
|---|
| 2575 | UT_TRACE_TAB_DEC(); |
|---|
| 2576 | return _UT_TRUE; |
|---|
| 2577 | } |
|---|
| 2578 | } |
|---|
| 2579 | if (!is_exist) |
|---|
| 2580 | { |
|---|
| 2581 | is_exist = _UT_TRUE; |
|---|
| 2582 | saved_width = glyph->width; |
|---|
| 2583 | saved_height = glyph->height; |
|---|
| 2584 | } |
|---|
| 2585 | } |
|---|
| 2586 | if (!cmap->length) break; |
|---|
| 2587 | cmap = ut_NEXT_CMAP(cmap); |
|---|
| 2588 | } |
|---|
| 2589 | stream = stream->next; |
|---|
| 2590 | } |
|---|
| 2591 | if (is_exist) |
|---|
| 2592 | { |
|---|
| 2593 | glyph->width = saved_width; |
|---|
| 2594 | glyph->height = saved_height; |
|---|
| 2595 | } |
|---|
| 2596 | UT_TRACE_TAB_DEC(); |
|---|
| 2597 | return is_exist; |
|---|
| 2598 | } |
|---|
| 2599 | |
|---|
| 2600 | #ifdef _UT_USE_BITMAP_FONT |
|---|
| 2601 | |
|---|
| 2602 | UT_BOOL utm_PrepareCharImageFromBitmapFont(UT_FC* fc, UT_CODE code, UT_IMAGE* image) |
|---|
| 2603 | { |
|---|
| 2604 | UT_BOOL result; |
|---|
| 2605 | UT_FONT_TASK* task = fc->task; |
|---|
| 2606 | UT_TRACE2("utm_GetCharImageFromBitmapFont(code = 0x%04x)", code); |
|---|
| 2607 | UT_TRACE_TAB_INC(); |
|---|
| 2608 | if (code == _UT_INVALID_CODE) |
|---|
| 2609 | { |
|---|
| 2610 | UT_TRACE1("image->type = _UT_INVALID_CODE"); |
|---|
| 2611 | image->type = _UT_IMAGE_TYPE_NULL_GLYPH; |
|---|
| 2612 | UT_TRACE_TAB_DEC(); |
|---|
| 2613 | return _UT_FALSE; |
|---|
| 2614 | } |
|---|
| 2615 | if (!utm_GetGlyph(fc, code, fc->task->glyph)) |
|---|
| 2616 | { |
|---|
| 2617 | UT_TRACE1("image->type = _UT_IMAGE_TYPE_NULL_GLYPH"); |
|---|
| 2618 | image->type = _UT_IMAGE_TYPE_NULL_GLYPH; |
|---|
| 2619 | UT_TRACE_TAB_DEC(); |
|---|
| 2620 | return _UT_FALSE; |
|---|
| 2621 | } |
|---|
| 2622 | task->emulItalic = fc->isItalic && !fc->fontItalic; |
|---|
| 2623 | task->emulBold = fc->isBold && (fc->fontWeight < _UT_FONT_WEIGHT_BOLD); |
|---|
| 2624 | #ifdef _UT_USE_BITMAP_EFFECT |
|---|
| 2625 | task->emulEdge = fc->edgeType; |
|---|
| 2626 | task->emulSmooth = fc->smoothType; |
|---|
| 2627 | if ((fc->edgeType == _UT_EDGE_TYPE_OUTLINE) || (fc->edgeType == _UT_EDGE_TYPE_OUTLINE1)) task->emulOutline = fc->edgeType; |
|---|
| 2628 | else if (fc->edgeType == _UT_EDGE_TYPE_INLINE) task->emulOutline = -1; |
|---|
| 2629 | else task->emulOutline = 0; |
|---|
| 2630 | #endif |
|---|
| 2631 | result = ut_PrepareRasterGlyphBitmap(fc, image); |
|---|
| 2632 | UT_TRACE_TAB_DEC(); |
|---|
| 2633 | return result; |
|---|
| 2634 | } |
|---|
| 2635 | |
|---|
| 2636 | UT_BOOL utm_GetCharImageFromBitmapFont(UT_FC* fc, UT_CODE code, UT_IMAGE* image) |
|---|
| 2637 | { |
|---|
| 2638 | if (!utm_PrepareCharImageFromBitmapFont(fc, code, image)) return _UT_FALSE; |
|---|
| 2639 | return utm_MakeImageOfBitmapFont(fc, image); |
|---|
| 2640 | } |
|---|
| 2641 | |
|---|
| 2642 | #else /*#ifdef _UT_USE_BITMAP_FONT*/ |
|---|
| 2643 | |
|---|
| 2644 | #include "_utfBit2Byte.cxx" |
|---|
| 2645 | |
|---|
| 2646 | #endif /*#ifdef _UT_USE_BITMAP_FONT*/ |
|---|
| 2647 | |
|---|
| 2648 | #ifdef _UT_USE_OUTLINE_FONT |
|---|
| 2649 | |
|---|
| 2650 | #include "_utfBit2Byte.cxx" |
|---|
| 2651 | |
|---|
| 2652 | #endif /*#ifdef _UT_USE_OUTLINE_FONT*/ |
|---|
| 2653 | |
|---|
| 2654 | #ifndef _INCLUDED_BITMAP_BIT2_BYTE |
|---|
| 2655 | |
|---|
| 2656 | UT_STATIC_API void ut_InitBit2ByteImageFnt(UT_FONT_MANAGER* fontManager) {} |
|---|
| 2657 | |
|---|
| 2658 | #endif /*#ifndef _INCLUDED_BITMAP_BIT2_BYTE*/ |
|---|
| 2659 | |
|---|
| 2660 | int utm_GetCharWidth(UT_FC* fc, UT_CODE code) |
|---|
| 2661 | { |
|---|
| 2662 | UT_GLYPH* glyph = fc->task->glyph; |
|---|
| 2663 | UT_TRACE2("utm_GetCharWidth(code = 0x%04x)", code); |
|---|
| 2664 | UT_TRACE_TAB_INC(); |
|---|
| 2665 | if (utm_GetGlyph(fc, code, glyph)) |
|---|
| 2666 | { |
|---|
| 2667 | int emulBold = fc->isBold && (fc->fontWeight < _UT_FONT_WEIGHT_BOLD); |
|---|
| 2668 | int d = 0; |
|---|
| 2669 | if (emulBold) if (!fc->isFixedPitch) d = ut_BoldExtra(fc->xSize); |
|---|
| 2670 | if (glyph->cmap->glyphType < 0) |
|---|
| 2671 | { |
|---|
| 2672 | int emSize = ut_SWAP_U16(glyph->cmap->depend.emSize); |
|---|
| 2673 | int width = (glyph->width * fc->xSize + (emSize>>1)) / emSize; |
|---|
| 2674 | if (fc->fixedWidth) |
|---|
| 2675 | { |
|---|
| 2676 | int n = (width + (fc->fixedWidth>>1)) / fc->fixedWidth; |
|---|
| 2677 | width = fc->fixedWidth * n; |
|---|
| 2678 | } |
|---|
| 2679 | UT_TRACE2("Outline width = %d", width); |
|---|
| 2680 | UT_TRACE_TAB_DEC(); |
|---|
| 2681 | return width + d; |
|---|
| 2682 | } |
|---|
| 2683 | else |
|---|
| 2684 | { |
|---|
| 2685 | UT_TRACE2("Bitmap width = %d", glyph->width); |
|---|
| 2686 | UT_TRACE_TAB_DEC(); |
|---|
| 2687 | return glyph->width + d; |
|---|
| 2688 | } |
|---|
| 2689 | } |
|---|
| 2690 | else |
|---|
| 2691 | { |
|---|
| 2692 | UT_TRACE1("_UT_IMAGE_TYPE_NULL_GLYPH"); |
|---|
| 2693 | UT_TRACE_TAB_DEC(); |
|---|
| 2694 | return 0; |
|---|
| 2695 | } |
|---|
| 2696 | } |
|---|
| 2697 | |
|---|
| 2698 | int utm_GetAverageCharWidth(UT_FC* fc) |
|---|
| 2699 | { |
|---|
| 2700 | return fc->xSize; |
|---|
| 2701 | } |
|---|
| 2702 | |
|---|
| 2703 | int utm_GetMaxCharWidth(UT_FC* fc) |
|---|
| 2704 | { |
|---|
| 2705 | return fc->xSize; |
|---|
| 2706 | } |
|---|
| 2707 | |
|---|
| 2708 | int utm_GetAscent(UT_FC* fc) |
|---|
| 2709 | { |
|---|
| 2710 | if (!fc->font.ascent) return fc->ySize; |
|---|
| 2711 | return (fc->font.ascent*fc->ySize+5000) / 10000; |
|---|
| 2712 | } |
|---|
| 2713 | |
|---|
| 2714 | int utm_GetDescent(UT_FC* fc) |
|---|
| 2715 | { |
|---|
| 2716 | if (!fc->font.descent) return 0; |
|---|
| 2717 | if (fc->font.descent<0) return -((-fc->font.descent*fc->ySize+5000) / 10000); |
|---|
| 2718 | else return (fc->font.descent*fc->ySize+5000) / 10000; |
|---|
| 2719 | } |
|---|
| 2720 | |
|---|
| 2721 | int utm_GetKerning(UT_FC* fc, UT_CODE leftCode, UT_CODE rightCode) |
|---|
| 2722 | { |
|---|
| 2723 | int adjust = 0; |
|---|
| 2724 | // UT_FONT_MANAGER* fontManager = fc->task->fontManager; |
|---|
| 2725 | UT_FONT_STREAM* stream = fc->stream; |
|---|
| 2726 | UT_KERN* kern = (UT_KERN*)stream->cmap; |
|---|
| 2727 | UT_TRACE2("utm_GetKerning(leftCode = 0x%04x)", leftCode); |
|---|
| 2728 | UT_TRACE2(" (rightCode = 0x%04x)", rightCode); |
|---|
| 2729 | UT_TRACE_TAB_INC(); |
|---|
| 2730 | if (!kern->zero && (ut_SWAP_U16(kern->identifier) == 1)) |
|---|
| 2731 | { |
|---|
| 2732 | UT_KERN_SUBTABLE_0* subTable = (UT_KERN_SUBTABLE_0*)(kern + 1); |
|---|
| 2733 | switch (subTable->format) |
|---|
| 2734 | { |
|---|
| 2735 | case _UT_KERN_BYTE: |
|---|
| 2736 | { |
|---|
| 2737 | UT_U32* value = (UT_U32*)(subTable + 1); |
|---|
| 2738 | int count = ut_SWAP_U16(subTable->count); |
|---|
| 2739 | int i = utm_SbinarySearch_U32(value, count, (leftCode << 16) | rightCode); |
|---|
| 2740 | if (i >= 0) |
|---|
| 2741 | { |
|---|
| 2742 | UT_I8* p = (UT_I8*)(value + count); |
|---|
| 2743 | adjust = p[i]; |
|---|
| 2744 | } |
|---|
| 2745 | break; |
|---|
| 2746 | } |
|---|
| 2747 | case _UT_KERN_SHORT: |
|---|
| 2748 | { |
|---|
| 2749 | UT_U32* value = (UT_U32*)(subTable + 1); |
|---|
| 2750 | int count = ut_SWAP_U16(subTable->count); |
|---|
| 2751 | int i = utm_SbinarySearch_U32(value, count, (leftCode << 16) | rightCode); |
|---|
| 2752 | if (i >= 0) |
|---|
| 2753 | { |
|---|
| 2754 | UT_I16* p = (UT_I16*)(value + count); |
|---|
| 2755 | adjust = ut_SWAP_I16(p[i]); |
|---|
| 2756 | } |
|---|
| 2757 | break; |
|---|
| 2758 | } |
|---|
| 2759 | } |
|---|
| 2760 | if (adjust) |
|---|
| 2761 | { |
|---|
| 2762 | UT_GLYPH* glyph = fc->task->glyph; |
|---|
| 2763 | if (utm_GetGlyph(fc, leftCode, glyph)) |
|---|
| 2764 | { |
|---|
| 2765 | int emulBold = fc->isBold && (fc->fontWeight < _UT_FONT_WEIGHT_BOLD); |
|---|
| 2766 | int d = 0; |
|---|
| 2767 | if (emulBold) if (!fc->isFixedPitch) d = ut_BoldExtra(fc->xSize); |
|---|
| 2768 | if (glyph->cmap->glyphType < 0) |
|---|
| 2769 | { |
|---|
| 2770 | int emSize = ut_SWAP_U16(glyph->cmap->depend.emSize); |
|---|
| 2771 | int width_old = (glyph->width * fc->xSize + (emSize>>1)) / emSize; |
|---|
| 2772 | int width_new = ((glyph->width+adjust) * fc->xSize + (emSize>>1)) / emSize; |
|---|
| 2773 | adjust = width_new - width_old; |
|---|
| 2774 | } |
|---|
| 2775 | } |
|---|
| 2776 | else |
|---|
| 2777 | { |
|---|
| 2778 | adjust = 0; |
|---|
| 2779 | } |
|---|
| 2780 | } |
|---|
| 2781 | } |
|---|
| 2782 | UT_TRACE_TAB_DEC(); |
|---|
| 2783 | return adjust; |
|---|
| 2784 | } |
|---|
| 2785 | |
|---|
| 2786 | int utm_GetCharHeight(UT_FC* fc, UT_CODE code) |
|---|
| 2787 | { |
|---|
| 2788 | UT_GLYPH* glyph = fc->task->glyph; |
|---|
| 2789 | UT_TRACE2("utm_GetCharHeight(code = 0x%04x)", code); |
|---|
| 2790 | UT_TRACE_TAB_INC(); |
|---|
| 2791 | if (utm_GetGlyph(fc, code, glyph)) |
|---|
| 2792 | { |
|---|
| 2793 | if (glyph->cmap->glyphType < 0) |
|---|
| 2794 | { |
|---|
| 2795 | int emSize = ut_SWAP_U16(glyph->cmap->depend.emSize); |
|---|
| 2796 | int height = (glyph->height * fc->ySize + (emSize>>1)) / emSize; |
|---|
| 2797 | UT_TRACE2("Outline height = %d", height); |
|---|
| 2798 | UT_TRACE_TAB_DEC(); |
|---|
| 2799 | return height; |
|---|
| 2800 | } |
|---|
| 2801 | else |
|---|
| 2802 | { |
|---|
| 2803 | UT_TRACE2("Bitmap height = %d", glyph->height); |
|---|
| 2804 | UT_TRACE_TAB_DEC(); |
|---|
| 2805 | return glyph->height; |
|---|
| 2806 | } |
|---|
| 2807 | } |
|---|
| 2808 | else |
|---|
| 2809 | { |
|---|
| 2810 | UT_TRACE1("_UT_IMAGE_TYPE_NULL_GLYPH"); |
|---|
| 2811 | UT_TRACE_TAB_DEC(); |
|---|
| 2812 | return 0; |
|---|
| 2813 | } |
|---|
| 2814 | } |
|---|
| 2815 | |
|---|
| 2816 | int utm_GetAverageCharHeight(UT_FC* fc) |
|---|
| 2817 | { |
|---|
| 2818 | return fc->ySize; |
|---|
| 2819 | } |
|---|
| 2820 | |
|---|
| 2821 | int utm_GetMaxCharHeight(UT_FC* fc) |
|---|
| 2822 | { |
|---|
| 2823 | return fc->ySize; |
|---|
| 2824 | } |
|---|
| 2825 | |
|---|
| 2826 | int utm_GetVerticalAscent(UT_FC* fc) |
|---|
| 2827 | { |
|---|
| 2828 | return fc->xSize; |
|---|
| 2829 | } |
|---|
| 2830 | |
|---|
| 2831 | int utm_GetVerticalDescent(UT_FC* fc) |
|---|
| 2832 | { |
|---|
| 2833 | return 0; |
|---|
| 2834 | } |
|---|
| 2835 | |
|---|
| 2836 | int utm_GetVerticalKerning(UT_FC* fc, UT_CODE leftCode, UT_CODE rightCode) |
|---|
| 2837 | { |
|---|
| 2838 | return 0; |
|---|
| 2839 | } |
|---|
| 2840 | |
|---|
| 2841 | void utm_InitPalette(UT_FC* fc, unsigned long* palette, unsigned long foregroundColor, unsigned long backgroundColor, unsigned long shadowColor) |
|---|
| 2842 | { |
|---|
| 2843 | int i; |
|---|
| 2844 | unsigned long l, d, a, r, g, b; |
|---|
| 2845 | palette[_UT_IMAGE_TYPE_BITMAP_65_BACKGROUND_COLOR] = backgroundColor; |
|---|
| 2846 | palette[_UT_IMAGE_TYPE_BITMAP_65_COLOR] = foregroundColor; |
|---|
| 2847 | if (fc) |
|---|
| 2848 | { |
|---|
| 2849 | if (fc->edgeType) |
|---|
| 2850 | { |
|---|
| 2851 | if ((fc->edgeType != _UT_EDGE_TYPE_OUTLINE) && |
|---|
| 2852 | (fc->edgeType != _UT_EDGE_TYPE_OUTLINE1) && |
|---|
| 2853 | (fc->edgeType != _UT_EDGE_TYPE_INLINE)) backgroundColor = shadowColor; |
|---|
| 2854 | } |
|---|
| 2855 | } |
|---|
| 2856 | a = ut_RGB_A(foregroundColor); |
|---|
| 2857 | for (i=_UT_IMAGE_TYPE_BITMAP_65_COLOR_1; i<_UT_IMAGE_TYPE_BITMAP_65_COLOR_64; i++) |
|---|
| 2858 | { |
|---|
| 2859 | l = (i * 255 + 32) >> 6; |
|---|
| 2860 | d = ut_RGB_A(backgroundColor); |
|---|
| 2861 | a = ((((ut_RGB_A(foregroundColor)-d)*l)>>8)+d) & 255; |
|---|
| 2862 | d = ut_RGB_R(backgroundColor); |
|---|
| 2863 | r = ((((ut_RGB_R(foregroundColor)-d)*l)>>8)+d) & 255; |
|---|
| 2864 | d = ut_RGB_G(backgroundColor); |
|---|
| 2865 | g = ((((ut_RGB_G(foregroundColor)-d)*l)>>8)+d) & 255; |
|---|
| 2866 | d = ut_RGB_B(backgroundColor); |
|---|
| 2867 | b = ((((ut_RGB_B(foregroundColor)-d)*l)>>8)+d) & 255; |
|---|
| 2868 | palette[i] = ut_ARGB(a, r, g, b); |
|---|
| 2869 | } |
|---|
| 2870 | palette[_UT_IMAGE_TYPE_BITMAP_65_SHADOW_COLOR] = shadowColor; |
|---|
| 2871 | palette[_UT_IMAGE_TYPE_BITMAP_65_SMOOTH_COLOR_CORNER] = palette[12]; |
|---|
| 2872 | palette[_UT_IMAGE_TYPE_BITMAP_65_SMOOTH_COLOR_EDGE] = palette[4]; |
|---|
| 2873 | } |
|---|
| 2874 | |
|---|
| 2875 | void utm_InitPalette_RGB565(UT_FC* fc, unsigned short* palette, unsigned short foregroundColor, unsigned short backgroundColor, unsigned short shadowColor) |
|---|
| 2876 | { |
|---|
| 2877 | int i; |
|---|
| 2878 | unsigned long r, g, b; |
|---|
| 2879 | unsigned long l_palette[_UT_IMAGE_TYPE_BITMAP_65_MAX_COLOR]; |
|---|
| 2880 | unsigned long l_foregroundColor, l_backgroundColor, l_shadowColor; |
|---|
| 2881 | r = (foregroundColor >> 11) & 31; r = (r * 255 + 15) / 31; |
|---|
| 2882 | g = (foregroundColor >> 5) & 63; g = (g * 255 + 31) / 63; |
|---|
| 2883 | b = (foregroundColor ) & 31; b = (b * 255 + 15) / 31; |
|---|
| 2884 | l_foregroundColor = ut_RGB(r, g, b); |
|---|
| 2885 | r = (backgroundColor >> 11) & 31; r = (r * 255 + 15) / 31; |
|---|
| 2886 | g = (backgroundColor >> 5) & 63; g = (g * 255 + 31) / 63; |
|---|
| 2887 | b = (backgroundColor ) & 31; b = (b * 255 + 15) / 31; |
|---|
| 2888 | l_backgroundColor = ut_RGB(r, g, b); |
|---|
| 2889 | r = (shadowColor >> 11) & 31; r = (r * 255 + 15) / 31; |
|---|
| 2890 | g = (shadowColor >> 5) & 63; g = (g * 255 + 31) / 63; |
|---|
| 2891 | b = (shadowColor ) & 31; b = (b * 255 + 15) / 31; |
|---|
| 2892 | l_shadowColor = ut_RGB(r, g, b); |
|---|
| 2893 | utm_InitPalette(fc, l_palette, l_foregroundColor, l_backgroundColor, l_shadowColor); |
|---|
| 2894 | for (i=0; i<_UT_IMAGE_TYPE_BITMAP_65_MAX_COLOR; i++) |
|---|
| 2895 | { |
|---|
| 2896 | r = ut_RGB_R(l_palette[i]); r = (r * 31 + 127) / 255; |
|---|
| 2897 | g = ut_RGB_G(l_palette[i]); g = (g * 63 + 127) / 255; |
|---|
| 2898 | b = ut_RGB_B(l_palette[i]); b = (b * 31 + 127) / 255; |
|---|
| 2899 | palette[i] = (unsigned short)((r << 11) | (g << 5) | b); |
|---|
| 2900 | } |
|---|
| 2901 | } |
|---|
| 2902 | |
|---|
| 2903 | void utm_InitPalette_RGB444(UT_FC* fc, unsigned short* palette, unsigned short foregroundColor, unsigned short backgroundColor, unsigned short shadowColor) |
|---|
| 2904 | { |
|---|
| 2905 | int i; |
|---|
| 2906 | unsigned long a, r, g, b; |
|---|
| 2907 | unsigned long l_palette[_UT_IMAGE_TYPE_BITMAP_65_MAX_COLOR]; |
|---|
| 2908 | unsigned long l_foregroundColor, l_backgroundColor, l_shadowColor; |
|---|
| 2909 | a = (foregroundColor >> 12) & 15; a |= a << 4; |
|---|
| 2910 | r = (foregroundColor >> 8) & 15; r |= r << 4; |
|---|
| 2911 | g = (foregroundColor >> 4) & 15; g |= g << 4; |
|---|
| 2912 | b = (foregroundColor ) & 15; b |= b << 4; |
|---|
| 2913 | l_foregroundColor = ut_ARGB(a, r, g, b); |
|---|
| 2914 | a = (backgroundColor >> 12) & 15; a |= a << 4; |
|---|
| 2915 | r = (backgroundColor >> 8) & 15; r |= r << 4; |
|---|
| 2916 | g = (backgroundColor >> 4) & 15; g |= g << 4; |
|---|
| 2917 | b = (backgroundColor ) & 15; b |= b << 4; |
|---|
| 2918 | l_backgroundColor = ut_ARGB(a, r, g, b); |
|---|
| 2919 | a = (shadowColor >> 12) & 15; a |= a << 4; |
|---|
| 2920 | r = (shadowColor >> 8) & 15; r |= r << 4; |
|---|
| 2921 | g = (shadowColor >> 4) & 15; g |= g << 4; |
|---|
| 2922 | b = (shadowColor ) & 15; b |= b << 4; |
|---|
| 2923 | l_shadowColor = ut_ARGB(a, r, g, b); |
|---|
| 2924 | utm_InitPalette(fc, l_palette, l_foregroundColor, l_backgroundColor, l_shadowColor); |
|---|
| 2925 | for (i=0; i<_UT_IMAGE_TYPE_BITMAP_65_MAX_COLOR; i++) |
|---|
| 2926 | { |
|---|
| 2927 | a = ut_RGB_A(l_palette[i]); a = (a * 15 + 127) / 255; |
|---|
| 2928 | r = ut_RGB_R(l_palette[i]); r = (r * 15 + 127) / 255; |
|---|
| 2929 | g = ut_RGB_G(l_palette[i]); g = (g * 15 + 127) / 255; |
|---|
| 2930 | b = ut_RGB_B(l_palette[i]); b = (b * 15 + 127) / 255; |
|---|
| 2931 | palette[i] = (unsigned short)((a << 12) | (r << 8) | (g << 4) | b); |
|---|
| 2932 | } |
|---|
| 2933 | } |
|---|
| 2934 | |
|---|
| 2935 | void utm_InitPalette_RGB666(UT_FC* fc, unsigned long* palette, unsigned long foregroundColor, unsigned long backgroundColor, unsigned long shadowColor) |
|---|
| 2936 | { |
|---|
| 2937 | int i; |
|---|
| 2938 | unsigned long a, r, g, b; |
|---|
| 2939 | unsigned long l_palette[_UT_IMAGE_TYPE_BITMAP_65_MAX_COLOR]; |
|---|
| 2940 | unsigned long l_foregroundColor, l_backgroundColor, l_shadowColor; |
|---|
| 2941 | a = (foregroundColor >> 18) & 63; a = (a * 255 + 31) / 63; |
|---|
| 2942 | r = (foregroundColor >> 12) & 63; r = (r * 255 + 31) / 63; |
|---|
| 2943 | g = (foregroundColor >> 6) & 63; g = (g * 255 + 31) / 63; |
|---|
| 2944 | b = (foregroundColor ) & 63; b = (b * 255 + 31) / 63; |
|---|
| 2945 | l_foregroundColor = ut_ARGB(a, r, g, b); |
|---|
| 2946 | a = (backgroundColor >> 18) & 63; a = (a * 255 + 31) / 63; |
|---|
| 2947 | r = (backgroundColor >> 12) & 63; r = (r * 255 + 31) / 63; |
|---|
| 2948 | g = (backgroundColor >> 6) & 63; g = (g * 255 + 31) / 63; |
|---|
| 2949 | b = (backgroundColor ) & 63; b = (b * 255 + 31) / 63; |
|---|
| 2950 | l_backgroundColor = ut_ARGB(a, r, g, b); |
|---|
| 2951 | a = (shadowColor >> 18) & 63; a = (a * 255 + 31) / 63; |
|---|
| 2952 | r = (shadowColor >> 12) & 63; r = (r * 255 + 31) / 63; |
|---|
| 2953 | g = (shadowColor >> 6) & 63; g = (g * 255 + 31) / 63; |
|---|
| 2954 | b = (shadowColor ) & 63; b = (b * 255 + 31) / 63; |
|---|
| 2955 | l_shadowColor = ut_ARGB(a, r, g, b); |
|---|
| 2956 | utm_InitPalette(fc, l_palette, l_foregroundColor, l_backgroundColor, l_shadowColor); |
|---|
| 2957 | for (i=0; i<_UT_IMAGE_TYPE_BITMAP_65_MAX_COLOR; i++) |
|---|
| 2958 | { |
|---|
| 2959 | a = ut_RGB_A(l_palette[i]); a = (a * 63 + 127) / 255; |
|---|
| 2960 | r = ut_RGB_R(l_palette[i]); r = (r * 63 + 127) / 255; |
|---|
| 2961 | g = ut_RGB_G(l_palette[i]); g = (g * 63 + 127) / 255; |
|---|
| 2962 | b = ut_RGB_B(l_palette[i]); b = (b * 63 + 127) / 255; |
|---|
| 2963 | palette[i] = (a << 18) | (r << 12) | (g << 6) | b; |
|---|
| 2964 | } |
|---|
| 2965 | } |
|---|
| 2966 | |
|---|
| 2967 | unsigned long utm_RGB565_2_RGB(unsigned short color) |
|---|
| 2968 | { |
|---|
| 2969 | unsigned long r = (color >> 11) & 31; |
|---|
| 2970 | unsigned long g = (color >> 5) & 63; |
|---|
| 2971 | unsigned long b = (color ) & 31; |
|---|
| 2972 | r = (r * 255 + 15) / 31; |
|---|
| 2973 | g = (g * 255 + 31) / 63; |
|---|
| 2974 | b = (b * 255 + 15) / 31; |
|---|
| 2975 | return ut_RGB(r, g, b); |
|---|
| 2976 | } |
|---|
| 2977 | |
|---|
| 2978 | unsigned short utm_RGB_2_RGB565(unsigned long color) |
|---|
| 2979 | { |
|---|
| 2980 | unsigned long r = ut_RGB_R(color); |
|---|
| 2981 | unsigned long g = ut_RGB_G(color); |
|---|
| 2982 | unsigned long b = ut_RGB_B(color); |
|---|
| 2983 | r = (r * 31 + 127) / 255; |
|---|
| 2984 | g = (g * 63 + 127) / 255; |
|---|
| 2985 | b = (b * 31 + 127) / 255; |
|---|
| 2986 | return (unsigned short)((r << 11) | (g << 5) | b); |
|---|
| 2987 | } |
|---|
| 2988 | |
|---|
| 2989 | unsigned long utm_RGB444_2_RGB(unsigned short color) |
|---|
| 2990 | { |
|---|
| 2991 | unsigned long a = (color >> 12) & 15; |
|---|
| 2992 | unsigned long r = (color >> 8) & 15; |
|---|
| 2993 | unsigned long g = (color >> 4) & 15; |
|---|
| 2994 | unsigned long b = (color ) & 15; |
|---|
| 2995 | a |= a << 4; |
|---|
| 2996 | r |= r << 4; |
|---|
| 2997 | g |= g << 4; |
|---|
| 2998 | b |= b << 4; |
|---|
| 2999 | return ut_ARGB(a, r, g, b); |
|---|
| 3000 | } |
|---|
| 3001 | |
|---|
| 3002 | unsigned short utm_RGB_2_RGB444(unsigned long color) |
|---|
| 3003 | { |
|---|
| 3004 | unsigned long a = ut_RGB_A(color); |
|---|
| 3005 | unsigned long r = ut_RGB_R(color); |
|---|
| 3006 | unsigned long g = ut_RGB_G(color); |
|---|
| 3007 | unsigned long b = ut_RGB_B(color); |
|---|
| 3008 | a = (a * 15 + 127) / 255; |
|---|
| 3009 | r = (r * 15 + 127) / 255; |
|---|
| 3010 | g = (g * 15 + 127) / 255; |
|---|
| 3011 | b = (b * 15 + 127) / 255; |
|---|
| 3012 | return (unsigned short)((a << 12) | (r << 8) | (g << 4) | b); |
|---|
| 3013 | } |
|---|
| 3014 | |
|---|
| 3015 | unsigned long utm_RGB666_2_RGB(unsigned long color) |
|---|
| 3016 | { |
|---|
| 3017 | unsigned long a = (color >> 18) & 63; |
|---|
| 3018 | unsigned long r = (color >> 12) & 63; |
|---|
| 3019 | unsigned long g = (color >> 6) & 63; |
|---|
| 3020 | unsigned long b = (color ) & 63; |
|---|
| 3021 | a = (a * 255 + 31) / 63; |
|---|
| 3022 | r = (r * 255 + 31) / 63; |
|---|
| 3023 | g = (g * 255 + 31) / 63; |
|---|
| 3024 | b = (b * 255 + 31) / 63; |
|---|
| 3025 | return ut_ARGB(a, r, g, b); |
|---|
| 3026 | } |
|---|
| 3027 | |
|---|
| 3028 | unsigned long utm_RGB_2_RGB666(unsigned long color) |
|---|
| 3029 | { |
|---|
| 3030 | unsigned long a = ut_RGB_A(color); |
|---|
| 3031 | unsigned long r = ut_RGB_R(color); |
|---|
| 3032 | unsigned long g = ut_RGB_G(color); |
|---|
| 3033 | unsigned long b = ut_RGB_B(color); |
|---|
| 3034 | a = (a * 63 + 127) / 255; |
|---|
| 3035 | r = (r * 63 + 127) / 255; |
|---|
| 3036 | g = (g * 63 + 127) / 255; |
|---|
| 3037 | b = (b * 63 + 127) / 255; |
|---|
| 3038 | return (a << 18) | (r << 12) | (g << 6) | b; |
|---|
| 3039 | } |
|---|
| 3040 | |
|---|
| 3041 | /***************************************************************************/ |
|---|
| 3042 | |
|---|
| 3043 | #if defined(_UT_USE_SINGLE_TASK) && !defined(_UT_NO_DATA_SEGMENT) |
|---|
| 3044 | |
|---|
| 3045 | static UT_FONT_MANAGER ut_single_font_manager; |
|---|
| 3046 | static UT_FONT_TASK ut_single_font_task; |
|---|
| 3047 | |
|---|
| 3048 | void ut_InitFontManager(void* (*AllocMemory)(unsigned int), void (*FreeMemory)(void*), |
|---|
| 3049 | UT_FACE* staticFontBuffer, int staticFontBufferCount, |
|---|
| 3050 | char* staticRasterBuffer, int staticRasterBufferSize) |
|---|
| 3051 | { |
|---|
| 3052 | utm_InitFontManager(&ut_single_font_manager, AllocMemory, FreeMemory, staticFontBuffer, staticFontBufferCount); |
|---|
| 3053 | utm_InitFontTask(&ut_single_font_task, &ut_single_font_manager, staticRasterBuffer, staticRasterBufferSize); |
|---|
| 3054 | } |
|---|
| 3055 | |
|---|
| 3056 | void ut_TermFontManager() |
|---|
| 3057 | { |
|---|
| 3058 | utm_TermFontTask(&ut_single_font_task); |
|---|
| 3059 | utm_TermFontManager(&ut_single_font_manager); |
|---|
| 3060 | } |
|---|
| 3061 | |
|---|
| 3062 | UT_BOOL ut_AddFont(void* fontAddress) |
|---|
| 3063 | { |
|---|
| 3064 | return utm_AddFont(&ut_single_font_manager, fontAddress); |
|---|
| 3065 | } |
|---|
| 3066 | |
|---|
| 3067 | UT_BOOL ut_AddStreamFont(UT_FONT_STREAM* stream) |
|---|
| 3068 | { |
|---|
| 3069 | return utm_AddStreamFont(&ut_single_font_manager, stream); |
|---|
| 3070 | } |
|---|
| 3071 | |
|---|
| 3072 | void ut_InitFontContext(UT_FC* fc, |
|---|
| 3073 | char* staticCmapBuffer, int staticCmapBufferSize) |
|---|
| 3074 | { |
|---|
| 3075 | utm_InitFontContext(fc, &ut_single_font_task, staticCmapBuffer, staticCmapBufferSize); |
|---|
| 3076 | } |
|---|
| 3077 | |
|---|
| 3078 | void ut_FreeScanBuffer() |
|---|
| 3079 | { |
|---|
| 3080 | utm_FreeScanBuffer(&ut_single_font_task); |
|---|
| 3081 | } |
|---|
| 3082 | |
|---|
| 3083 | UT_BOOL ut_GetTypefaceList(void* param, |
|---|
| 3084 | void (*Callback)(void* param, UT_CODE* typefaceName, UT_U32 id)) |
|---|
| 3085 | { |
|---|
| 3086 | return utm_GetTypefaceList(&ut_single_font_manager, param, Callback); |
|---|
| 3087 | } |
|---|
| 3088 | |
|---|
| 3089 | UT_BOOL ut_GetFontList(void* param, |
|---|
| 3090 | void (*Callback)(void* param, UT_CODE* typefaceName, UT_U32 id, |
|---|
| 3091 | UT_CODE* fontName, int fontHeight, int fontWidth, int weight, UT_BOOL isItalic)) |
|---|
| 3092 | { |
|---|
| 3093 | return utm_GetFontList(&ut_single_font_manager, param, Callback); |
|---|
| 3094 | } |
|---|
| 3095 | |
|---|
| 3096 | #endif /*#if defined(_UT_USE_SINGLE_TASK) && !defined(_UT_NO_DATA_SEGMENT)*/ |
|---|
| 3097 | |
|---|
| 3098 | /***************************************************************************/ |
|---|
| 3099 | |
|---|
| 3100 | #include "_utfDebugOn.hxx" |
|---|
| 3101 | |
|---|
| 3102 | #if defined(_UT_DEBUG) && !defined(ut_DispImage) |
|---|
| 3103 | |
|---|
| 3104 | UT_STATIC_API char DecimalToHexaChar(int hex) |
|---|
| 3105 | { |
|---|
| 3106 | if (hex < 10 ) return '0' + hex; |
|---|
| 3107 | return 'a' + hex - 10; |
|---|
| 3108 | } |
|---|
| 3109 | |
|---|
| 3110 | void ut_DispImage(UT_IMAGE* image) |
|---|
| 3111 | { |
|---|
| 3112 | int x, y; |
|---|
| 3113 | unsigned char* p = image->data; |
|---|
| 3114 | char line[1024]; |
|---|
| 3115 | UT_TRACE1("DispImage()"); |
|---|
| 3116 | UT_TRACE_TAB_INC(); |
|---|
| 3117 | if (image->type == _UT_IMAGE_TYPE_BITMAP_65) |
|---|
| 3118 | { |
|---|
| 3119 | UT_TRACE2("image->type = %d(_UT_IMAGE_TYPE_BITMAP_65)", image->type); |
|---|
| 3120 | UT_TRACE2("image->bbox.ox = %d", image->bbox.ox); |
|---|
| 3121 | UT_TRACE2("image->bbox.oy = %d", image->bbox.oy); |
|---|
| 3122 | UT_TRACE2("image->bbox.sx = %d", image->bbox.sx); |
|---|
| 3123 | UT_TRACE2("image->bbox.sy = %d", image->bbox.sy); |
|---|
| 3124 | UT_TRACE2("image->width = %d", image->width); |
|---|
| 3125 | UT_TRACE2("image->height = %d", image->height); |
|---|
| 3126 | UT_TRACE2("image->bSize = %d", image->bSize); |
|---|
| 3127 | UT_TRACE2("image->lSize = %d", image->lSize); |
|---|
| 3128 | for (y=0; y<image->bbox.sy; y++,p+=image->bSize) |
|---|
| 3129 | { |
|---|
| 3130 | for (x=0; x<image->bbox.sx; x++) |
|---|
| 3131 | { |
|---|
| 3132 | if (p[x]) {line[x*2] = DecimalToHexaChar((p[x]>>4)&15); line[x*2+1] = DecimalToHexaChar(p[x]&15);} |
|---|
| 3133 | else line[x*2] = line[x*2+1] = '.'; |
|---|
| 3134 | } |
|---|
| 3135 | line[x*2] = 0; |
|---|
| 3136 | UT_TRACE1(line); |
|---|
| 3137 | } |
|---|
| 3138 | } |
|---|
| 3139 | else if (image->type == _UT_IMAGE_TYPE_BITMAP) |
|---|
| 3140 | { |
|---|
| 3141 | UT_TRACE2("image->type = %d(_UT_IMAGE_TYPE_BITMAP)", image->type); |
|---|
| 3142 | UT_TRACE2("image->bbox.ox = %d", image->bbox.ox); |
|---|
| 3143 | UT_TRACE2("image->bbox.oy = %d", image->bbox.oy); |
|---|
| 3144 | UT_TRACE2("image->bbox.sx = %d", image->bbox.sx); |
|---|
| 3145 | UT_TRACE2("image->bbox.sy = %d", image->bbox.sy); |
|---|
| 3146 | UT_TRACE2("image->width = %d", image->width); |
|---|
| 3147 | UT_TRACE2("image->height = %d", image->height); |
|---|
| 3148 | UT_TRACE2("image->bSize = %d", image->bSize); |
|---|
| 3149 | UT_TRACE2("image->lSize = %d", image->lSize); |
|---|
| 3150 | for (y=0; y<image->bbox.sy; y++,p+=image->bSize) |
|---|
| 3151 | { |
|---|
| 3152 | for (x=0; x<image->bbox.sx; x++) |
|---|
| 3153 | { |
|---|
| 3154 | if (p[x>>3] & (0x80 >> (x&7))) line[x] = '*'; |
|---|
| 3155 | else line[x] = '.'; |
|---|
| 3156 | } |
|---|
| 3157 | line[x] = 0; |
|---|
| 3158 | UT_TRACE1(line); |
|---|
| 3159 | } |
|---|
| 3160 | } |
|---|
| 3161 | else if (image->type == _UT_IMAGE_TYPE_SBM) |
|---|
| 3162 | { |
|---|
| 3163 | UT_TRACE2("image->type = %d(_UT_IMAGE_TYPE_SBM)", image->type); |
|---|
| 3164 | UT_TRACE2("image->bbox.ox = %d", image->bbox.ox); |
|---|
| 3165 | UT_TRACE2("image->bbox.oy = %d", image->bbox.oy); |
|---|
| 3166 | UT_TRACE2("image->bbox.sx = %d", image->bbox.sx); |
|---|
| 3167 | UT_TRACE2("image->bbox.sy = %d", image->bbox.sy); |
|---|
| 3168 | UT_TRACE2("image->width = %d", image->width); |
|---|
| 3169 | UT_TRACE2("image->height = %d", image->height); |
|---|
| 3170 | UT_TRACE2("image->bSize = %d", image->bSize); |
|---|
| 3171 | UT_TRACE2("image->lSize = %d", image->lSize); |
|---|
| 3172 | for (y=0; y<image->bbox.sy; y++,p+=image->bSize) |
|---|
| 3173 | { |
|---|
| 3174 | for (x=0; x<image->bbox.sx; x++) |
|---|
| 3175 | { |
|---|
| 3176 | if (p[x>>3] & (0x80 >> (x&7))) line[x] = '*'; |
|---|
| 3177 | else line[x] = '.'; |
|---|
| 3178 | } |
|---|
| 3179 | line[x] = 0; |
|---|
| 3180 | UT_TRACE1(line); |
|---|
| 3181 | } |
|---|
| 3182 | } |
|---|
| 3183 | else if (image->type == _UT_IMAGE_TYPE_LCD) |
|---|
| 3184 | { |
|---|
| 3185 | UT_TRACE2("image->type = %d(_UT_IMAGE_TYPE_LCD)", image->type); |
|---|
| 3186 | UT_TRACE2("image->bbox.ox = %d", image->bbox.ox); |
|---|
| 3187 | UT_TRACE2("image->bbox.oy = %d", image->bbox.oy); |
|---|
| 3188 | UT_TRACE2("image->bbox.sx = %d", image->bbox.sx); |
|---|
| 3189 | UT_TRACE2("image->bbox.sy = %d", image->bbox.sy); |
|---|
| 3190 | UT_TRACE2("image->width = %d", image->width); |
|---|
| 3191 | UT_TRACE2("image->height = %d", image->height); |
|---|
| 3192 | UT_TRACE2("image->bSize = %d", image->bSize); |
|---|
| 3193 | UT_TRACE2("image->lSize = %d", image->lSize); |
|---|
| 3194 | for (y=0; y<image->bbox.sy; y++) |
|---|
| 3195 | { |
|---|
| 3196 | for (x=0; x<image->bbox.sx; x++) |
|---|
| 3197 | { |
|---|
| 3198 | if (p[(y>>3)*image->bbox.sx+x] & (1<<(y&7))) line[x] = '*'; |
|---|
| 3199 | else line[x] = '.'; |
|---|
| 3200 | } |
|---|
| 3201 | line[x] = 0; |
|---|
| 3202 | UT_TRACE1(line); |
|---|
| 3203 | } |
|---|
| 3204 | } |
|---|
| 3205 | else if (image->type == _UT_IMAGE_TYPE_LCD_R) |
|---|
| 3206 | { |
|---|
| 3207 | UT_TRACE2("image->type = %d(_UT_IMAGE_TYPE_LCD_R)", image->type); |
|---|
| 3208 | UT_TRACE2("image->bbox.ox = %d", image->bbox.ox); |
|---|
| 3209 | UT_TRACE2("image->bbox.oy = %d", image->bbox.oy); |
|---|
| 3210 | UT_TRACE2("image->bbox.sx = %d", image->bbox.sx); |
|---|
| 3211 | UT_TRACE2("image->bbox.sy = %d", image->bbox.sy); |
|---|
| 3212 | UT_TRACE2("image->width = %d", image->width); |
|---|
| 3213 | UT_TRACE2("image->height = %d", image->height); |
|---|
| 3214 | UT_TRACE2("image->bSize = %d", image->bSize); |
|---|
| 3215 | UT_TRACE2("image->lSize = %d", image->lSize); |
|---|
| 3216 | for (y=0; y<image->bbox.sy; y++) |
|---|
| 3217 | { |
|---|
| 3218 | for (x=0; x<image->bbox.sx; x++) |
|---|
| 3219 | { |
|---|
| 3220 | if (p[(y>>3)*image->bbox.sx+x] & (0x80>>(y&7))) line[x] = '*'; |
|---|
| 3221 | else line[x] = '.'; |
|---|
| 3222 | } |
|---|
| 3223 | line[x] = 0; |
|---|
| 3224 | UT_TRACE1(line); |
|---|
| 3225 | } |
|---|
| 3226 | } |
|---|
| 3227 | UT_TRACE_TAB_DEC(); |
|---|
| 3228 | } |
|---|
| 3229 | |
|---|
| 3230 | #endif |
|---|