|
Lines 1-5
a/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp_sec1
|
| 1 |
/* |
1 |
/* |
| 2 |
* Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
2 |
* Copyright (C) 2008, 2009 Apple Inc. All rights reserved. |
|
|
3 |
* Copyright (C) 2009 Torch Mobile, Inc. |
| 3 |
* |
4 |
* |
| 4 |
* Redistribution and use in source and binary forms, with or without |
5 |
* Redistribution and use in source and binary forms, with or without |
| 5 |
* modification, are permitted provided that the following conditions |
6 |
* modification, are permitted provided that the following conditions |
|
Lines 69-75
struct TableDirectoryEntry {
a/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp_sec2
|
| 69 |
BigEndianULong length; |
70 |
BigEndianULong length; |
| 70 |
}; |
71 |
}; |
| 71 |
|
72 |
|
| 72 |
#if !PLATFORM(CG) |
73 |
#if PLATFORM(WINCE) |
|
|
74 |
// Need to use #define instead of typedef due to conflict |
| 75 |
#define Fixed int32_t |
| 76 |
#elif !PLATFORM(CG) |
| 73 |
// Fixed type is not defined on non-CG platforms. |version| in sfntHeader |
77 |
// Fixed type is not defined on non-CG platforms. |version| in sfntHeader |
| 74 |
// and headTable and |fontRevision| in headTable are of Fixed, but they're |
78 |
// and headTable and |fontRevision| in headTable are of Fixed, but they're |
| 75 |
// not actually refered to anywhere. Therefore, we just have to match |
79 |
// not actually refered to anywhere. Therefore, we just have to match |
|
Lines 339-344
bool getEOTHeader(SharedBuffer* fontData, EOTHeader& eotHeader, size_t& overlayD
a/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp_sec3
|
| 339 |
return true; |
343 |
return true; |
| 340 |
} |
344 |
} |
| 341 |
|
345 |
|
|
|
346 |
#if PLATFORM(WINCE) |
| 347 |
bool renameFont(SharedBuffer* fontData, const String& fontName) |
| 348 |
{ |
| 349 |
size_t originalDataSize = fontData->size(); |
| 350 |
if (originalDataSize < offsetof(sfntHeader, tables)) |
| 351 |
return false; |
| 352 |
|
| 353 |
const sfntHeader* sfnt = reinterpret_cast<const sfntHeader*>(fontData->data()); |
| 354 |
|
| 355 |
if (originalDataSize < offsetof(sfntHeader, tables) + sfnt->numTables * sizeof(TableDirectoryEntry)) |
| 356 |
return false; |
| 357 |
|
| 358 |
unsigned t; |
| 359 |
for (t = 0; t < sfnt->numTables; ++t) { |
| 360 |
if (sfnt->tables[t].tag == 'name') |
| 361 |
break; |
| 362 |
} |
| 363 |
if (t == sfnt->numTables) |
| 364 |
return false; |
| 365 |
|
| 366 |
const int nameRecordCount = 5; |
| 367 |
|
| 368 |
// Rounded up to a multiple of 4 to simplify the checksum calculation. |
| 369 |
size_t nameTableSize = ((offsetof(nameTable, nameRecords) + nameRecordCount * sizeof(nameRecord) + fontName.length() * sizeof(UChar)) & ~3) + 4; |
| 370 |
|
| 371 |
Vector<char> rewrittenFontData(fontData->size() + nameTableSize); |
| 372 |
char* data = rewrittenFontData.data(); |
| 373 |
memcpy(data, fontData->data(), originalDataSize); |
| 374 |
|
| 375 |
// Make the table directory entry point to the new 'name' table. |
| 376 |
sfntHeader* rewrittenSfnt = reinterpret_cast<sfntHeader*>(data); |
| 377 |
rewrittenSfnt->tables[t].length = nameTableSize; |
| 378 |
rewrittenSfnt->tables[t].offset = originalDataSize; |
| 379 |
|
| 380 |
// Write the new 'name' table after the original font data. |
| 381 |
nameTable* name = reinterpret_cast<nameTable*>(data + originalDataSize); |
| 382 |
name->format = 0; |
| 383 |
name->count = nameRecordCount; |
| 384 |
name->stringOffset = offsetof(nameTable, nameRecords) + nameRecordCount * sizeof(nameRecord); |
| 385 |
for (unsigned i = 0; i < nameRecordCount; ++i) { |
| 386 |
name->nameRecords[i].platformID = 3; |
| 387 |
name->nameRecords[i].encodingID = 1; |
| 388 |
name->nameRecords[i].languageID = 0x0409; |
| 389 |
name->nameRecords[i].offset = 0; |
| 390 |
name->nameRecords[i].length = fontName.length() * sizeof(UChar); |
| 391 |
} |
| 392 |
|
| 393 |
// The required 'name' record types: Family, Style, Unique, Full and PostScript. |
| 394 |
name->nameRecords[0].nameID = 1; |
| 395 |
name->nameRecords[1].nameID = 2; |
| 396 |
name->nameRecords[2].nameID = 3; |
| 397 |
name->nameRecords[3].nameID = 4; |
| 398 |
name->nameRecords[4].nameID = 6; |
| 399 |
|
| 400 |
for (unsigned i = 0; i < fontName.length(); ++i) |
| 401 |
reinterpret_cast<BigEndianUShort*>(data + originalDataSize + name->stringOffset)[i] = fontName[i]; |
| 402 |
|
| 403 |
// Update the table checksum in the directory entry. |
| 404 |
rewrittenSfnt->tables[t].checkSum = 0; |
| 405 |
for (unsigned i = 0; i * sizeof(BigEndianULong) < nameTableSize; ++i) |
| 406 |
rewrittenSfnt->tables[t].checkSum = rewrittenSfnt->tables[t].checkSum + reinterpret_cast<BigEndianULong*>(name)[i]; |
| 407 |
|
| 408 |
fontData->clear(); |
| 409 |
fontData->append(rewrittenFontData.data(), rewrittenFontData.size()); |
| 410 |
return true; |
| 411 |
} |
| 412 |
#else |
| 342 |
HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName) |
413 |
HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName) |
| 343 |
{ |
414 |
{ |
| 344 |
size_t originalDataSize = fontData->size(); |
415 |
size_t originalDataSize = fontData->size(); |
|
Lines 404-408
HANDLE renameAndActivateFont(SharedBuffer* fontData, const String& fontName)
a/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp_sec4
|
| 404 |
|
475 |
|
| 405 |
return fontHandle; |
476 |
return fontHandle; |
| 406 |
} |
477 |
} |
|
|
478 |
#endif |
| 407 |
|
479 |
|
| 408 |
} |
480 |
} |