Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(129)

Side by Side Diff: src/pdf/SkPDFFont.cpp

Issue 2120533002: SkPDF: Fix encoding of unichr outside of basic plane (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | src/pdf/SkPDFUtils.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2011 Google Inc. 2 * Copyright 2011 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include <ctype.h> 8 #include <ctype.h>
9 9
10 #include "SkData.h" 10 #include "SkData.h"
(...skipping 403 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 uint16_t fGlyphId; 414 uint16_t fGlyphId;
415 SkUnichar fUnicode; 415 SkUnichar fUnicode;
416 }; 416 };
417 417
418 struct BFRange { 418 struct BFRange {
419 uint16_t fStart; 419 uint16_t fStart;
420 uint16_t fEnd; 420 uint16_t fEnd;
421 SkUnichar fUnicode; 421 SkUnichar fUnicode;
422 }; 422 };
423 423
424 static void write_utf16be(SkDynamicMemoryWStream* wStream, SkUnichar utf32) {
425 uint16_t utf16[2] = {0, 0};
426 size_t len = SkUTF16_FromUnichar(utf32, utf16);
427 SkASSERT(len == 1 || len == 2);
428 SkPDFUtils::WriteUInt16BE(wStream, utf16[0]);
429 if (len == 2) {
430 SkPDFUtils::WriteUInt16BE(wStream, utf16[1]);
431 }
432 }
433
424 static void append_bfchar_section(const SkTDArray<BFChar>& bfchar, 434 static void append_bfchar_section(const SkTDArray<BFChar>& bfchar,
425 SkDynamicMemoryWStream* cmap) { 435 SkDynamicMemoryWStream* cmap) {
426 // PDF spec defines that every bf* list can have at most 100 entries. 436 // PDF spec defines that every bf* list can have at most 100 entries.
427 for (int i = 0; i < bfchar.count(); i += 100) { 437 for (int i = 0; i < bfchar.count(); i += 100) {
428 int count = bfchar.count() - i; 438 int count = bfchar.count() - i;
429 count = SkMin32(count, 100); 439 count = SkMin32(count, 100);
430 cmap->writeDecAsText(count); 440 cmap->writeDecAsText(count);
431 cmap->writeText(" beginbfchar\n"); 441 cmap->writeText(" beginbfchar\n");
432 for (int j = 0; j < count; ++j) { 442 for (int j = 0; j < count; ++j) {
433 cmap->writeText("<"); 443 cmap->writeText("<");
434 cmap->writeHexAsText(bfchar[i + j].fGlyphId, 4); 444 SkPDFUtils::WriteUInt16BE(cmap, bfchar[i + j].fGlyphId);
435 cmap->writeText("> <"); 445 cmap->writeText("> <");
436 cmap->writeHexAsText(bfchar[i + j].fUnicode, 4); 446 write_utf16be(cmap, bfchar[i + j].fUnicode);
437 cmap->writeText(">\n"); 447 cmap->writeText(">\n");
438 } 448 }
439 cmap->writeText("endbfchar\n"); 449 cmap->writeText("endbfchar\n");
440 } 450 }
441 } 451 }
442 452
443 static void append_bfrange_section(const SkTDArray<BFRange>& bfrange, 453 static void append_bfrange_section(const SkTDArray<BFRange>& bfrange,
444 SkDynamicMemoryWStream* cmap) { 454 SkDynamicMemoryWStream* cmap) {
445 // PDF spec defines that every bf* list can have at most 100 entries. 455 // PDF spec defines that every bf* list can have at most 100 entries.
446 for (int i = 0; i < bfrange.count(); i += 100) { 456 for (int i = 0; i < bfrange.count(); i += 100) {
447 int count = bfrange.count() - i; 457 int count = bfrange.count() - i;
448 count = SkMin32(count, 100); 458 count = SkMin32(count, 100);
449 cmap->writeDecAsText(count); 459 cmap->writeDecAsText(count);
450 cmap->writeText(" beginbfrange\n"); 460 cmap->writeText(" beginbfrange\n");
451 for (int j = 0; j < count; ++j) { 461 for (int j = 0; j < count; ++j) {
452 cmap->writeText("<"); 462 cmap->writeText("<");
453 cmap->writeHexAsText(bfrange[i + j].fStart, 4); 463 SkPDFUtils::WriteUInt16BE(cmap, bfrange[i + j].fStart);
454 cmap->writeText("> <"); 464 cmap->writeText("> <");
455 cmap->writeHexAsText(bfrange[i + j].fEnd, 4); 465 SkPDFUtils::WriteUInt16BE(cmap, bfrange[i + j].fEnd);
456 cmap->writeText("> <"); 466 cmap->writeText("> <");
457 cmap->writeHexAsText(bfrange[i + j].fUnicode, 4); 467 write_utf16be(cmap, bfrange[i + j].fUnicode);
458 cmap->writeText(">\n"); 468 cmap->writeText(">\n");
459 } 469 }
460 cmap->writeText("endbfrange\n"); 470 cmap->writeText("endbfrange\n");
461 } 471 }
462 } 472 }
463 473
464 // Generate <bfchar> and <bfrange> table according to PDF spec 1.4 and Adobe 474 // Generate <bfchar> and <bfrange> table according to PDF spec 1.4 and Adobe
465 // Technote 5014. 475 // Technote 5014.
466 // The function is not static so we can test it in unit tests. 476 // The function is not static so we can test it in unit tests.
467 // 477 //
(...skipping 941 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 } 1419 }
1410 return *canon->fCanEmbedTypeface.set(id, canEmbed); 1420 return *canon->fCanEmbedTypeface.set(id, canEmbed);
1411 } 1421 }
1412 1422
1413 void SkPDFFont::drop() { 1423 void SkPDFFont::drop() {
1414 fTypeface = nullptr; 1424 fTypeface = nullptr;
1415 fFontInfo = nullptr; 1425 fFontInfo = nullptr;
1416 fDescriptor = nullptr; 1426 fDescriptor = nullptr;
1417 this->SkPDFDict::drop(); 1427 this->SkPDFDict::drop();
1418 } 1428 }
OLDNEW
« no previous file with comments | « src/pdf/SkPDFDevice.cpp ('k') | src/pdf/SkPDFUtils.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698