OLD | NEW |
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 "SkPDFDevice.h" | 8 #include "SkPDFDevice.h" |
9 | 9 |
10 #include "SkAnnotationKeys.h" | 10 #include "SkAnnotationKeys.h" |
(...skipping 1005 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1016 if (!typeface) { | 1016 if (!typeface) { |
1017 SkDebugf("SkPDF: SkTypeface::MakeDefault() returned nullptr.\n"); | 1017 SkDebugf("SkPDF: SkTypeface::MakeDefault() returned nullptr.\n"); |
1018 return; | 1018 return; |
1019 } | 1019 } |
1020 | 1020 |
1021 const SkAdvancedTypefaceMetrics* metrics = | 1021 const SkAdvancedTypefaceMetrics* metrics = |
1022 SkPDFFont::GetMetrics(typeface, fDocument->canon()); | 1022 SkPDFFont::GetMetrics(typeface, fDocument->canon()); |
1023 if (!metrics) { | 1023 if (!metrics) { |
1024 return; | 1024 return; |
1025 } | 1025 } |
| 1026 int glyphCount = paint.textToGlyphs(sourceText, sourceByteCount, nullptr); |
| 1027 if (glyphCount <= 0) { |
| 1028 return; |
| 1029 } |
1026 // TODO(halcanary): use metrics->fGlyphToUnicode to check Unicode mapping. | 1030 // TODO(halcanary): use metrics->fGlyphToUnicode to check Unicode mapping. |
1027 const SkGlyphID maxGlyphID = metrics->fLastGlyphID; | 1031 const SkGlyphID maxGlyphID = metrics->fLastGlyphID; |
1028 if (!SkPDFFont::CanEmbedTypeface(typeface, fDocument->canon())) { | 1032 if (!SkPDFFont::CanEmbedTypeface(typeface, fDocument->canon())) { |
1029 SkPath path; // https://bug.skia.org/3866 | 1033 SkPath path; // https://bug.skia.org/3866 |
1030 paint.getTextPath(sourceText, sourceByteCount, | 1034 switch (positioning) { |
1031 offset.x(), offset.y(), &path); | 1035 case SkTextBlob::kDefault_Positioning: |
| 1036 srcPaint.getTextPath(sourceText, sourceByteCount, |
| 1037 offset.x(), offset.y(), &path); |
| 1038 break; |
| 1039 case SkTextBlob::kHorizontal_Positioning: { |
| 1040 SkAutoTMalloc<SkPoint> positionsBuffer(glyphCount); |
| 1041 for (int i = 0; i < glyphCount; ++i) { |
| 1042 positionsBuffer[i] = offset + SkPoint{pos[i], 0}; |
| 1043 } |
| 1044 srcPaint.getPosTextPath(sourceText, sourceByteCount, |
| 1045 &positionsBuffer[0], &path); |
| 1046 break; |
| 1047 } |
| 1048 case SkTextBlob::kFull_Positioning: { |
| 1049 SkAutoTMalloc<SkPoint> positionsBuffer(glyphCount); |
| 1050 for (int i = 0; i < glyphCount; ++i) { |
| 1051 positionsBuffer[i] = offset + SkPoint{pos[2 * i], pos[2 * i
+ 1]}; |
| 1052 } |
| 1053 srcPaint.getPosTextPath(sourceText, sourceByteCount, |
| 1054 &positionsBuffer[0], &path); |
| 1055 break; |
| 1056 } |
| 1057 } |
1032 this->drawPath(d, path, srcPaint, &SkMatrix::I(), true); | 1058 this->drawPath(d, path, srcPaint, &SkMatrix::I(), true); |
1033 // Draw text transparently to make it copyable/searchable/accessable. | 1059 // Draw text transparently to make it copyable/searchable/accessable. |
1034 draw_transparent_text(this, d, sourceText, sourceByteCount, | 1060 draw_transparent_text(this, d, sourceText, sourceByteCount, |
1035 offset.x(), offset.y(), paint); | 1061 offset.x(), offset.y(), paint); |
1036 return; | 1062 return; |
1037 } | 1063 } |
1038 int glyphCount = paint.textToGlyphs(sourceText, sourceByteCount, nullptr); | |
1039 if (glyphCount <= 0) { | |
1040 return; | |
1041 } | |
1042 SkAutoSTMalloc<128, SkGlyphID> glyphStorage; | 1064 SkAutoSTMalloc<128, SkGlyphID> glyphStorage; |
1043 const SkGlyphID* glyphs = nullptr; | 1065 const SkGlyphID* glyphs = nullptr; |
1044 if (paint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding) { | 1066 if (paint.getTextEncoding() == SkPaint::kGlyphID_TextEncoding) { |
1045 glyphs = (const SkGlyphID*)sourceText; | 1067 glyphs = (const SkGlyphID*)sourceText; |
1046 // validate input later. | 1068 // validate input later. |
1047 } else { | 1069 } else { |
1048 glyphStorage.reset(SkToSizeT(glyphCount)); | 1070 glyphStorage.reset(SkToSizeT(glyphCount)); |
1049 (void)paint.textToGlyphs(sourceText, sourceByteCount, glyphStorage.get()
); | 1071 (void)paint.textToGlyphs(sourceText, sourceByteCount, glyphStorage.get()
); |
1050 glyphs = glyphStorage.get(); | 1072 glyphs = glyphStorage.get(); |
1051 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); | 1073 paint.setTextEncoding(SkPaint::kGlyphID_TextEncoding); |
(...skipping 987 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2039 } | 2061 } |
2040 | 2062 |
2041 sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkImage* image) { | 2063 sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkImage* image) { |
2042 return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->
height()), | 2064 return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->
height()), |
2043 image->makeNonTextureImage()); | 2065 image->makeNonTextureImage()); |
2044 } | 2066 } |
2045 | 2067 |
2046 sk_sp<SkSpecialImage> SkPDFDevice::snapSpecial() { | 2068 sk_sp<SkSpecialImage> SkPDFDevice::snapSpecial() { |
2047 return nullptr; | 2069 return nullptr; |
2048 } | 2070 } |
OLD | NEW |