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 #include "SkAnnotationKeys.h" | 9 #include "SkAnnotationKeys.h" |
10 #include "SkBitmapDevice.h" | 10 #include "SkBitmapDevice.h" |
(...skipping 1135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 SkDebugf("SkPDF: Font error."); | 1146 SkDebugf("SkPDF: Font error."); |
1147 out->writeText("ET\n%SkPDF: Font error.\n"); | 1147 out->writeText("ET\n%SkPDF: Font error.\n"); |
1148 return; | 1148 return; |
1149 } | 1149 } |
1150 SkPDFFont* font = content.entry()->fState.fFont; | 1150 SkPDFFont* font = content.entry()->fState.fFont; |
1151 GlyphPositioner glyphPositioner(out, | 1151 GlyphPositioner glyphPositioner(out, |
1152 paint.getTextSkewX(), | 1152 paint.getTextSkewX(), |
1153 font->multiByteGlyphs(), | 1153 font->multiByteGlyphs(), |
1154 defaultPositioning, | 1154 defaultPositioning, |
1155 offset); | 1155 offset); |
1156 SkPDFGlyphSetMap* fontGlyphUsage = fDocument->getGlyphUsage(); | |
1157 const SkGlyphID* const glyphsEnd = glyphs + glyphCount; | 1156 const SkGlyphID* const glyphsEnd = glyphs + glyphCount; |
1158 | 1157 |
1159 while (glyphs < glyphsEnd) { | 1158 while (glyphs < glyphsEnd) { |
1160 font = content.entry()->fState.fFont; | 1159 font = content.entry()->fState.fFont; |
1161 int stretch = font->multiByteGlyphs() | 1160 int stretch = font->multiByteGlyphs() |
1162 ? SkToInt(glyphsEnd - glyphs) | 1161 ? SkToInt(glyphsEnd - glyphs) |
1163 : font->glyphsToPDFFontEncodingCount(glyphs, SkToInt(glyphsEnd - gly
phs)); | 1162 : font->glyphsToPDFFontEncodingCount(glyphs, SkToInt(glyphsEnd - gly
phs)); |
1164 SkASSERT(glyphs + stretch <= glyphsEnd); | 1163 SkASSERT(glyphs + stretch <= glyphsEnd); |
1165 if (stretch < 1) { | 1164 if (stretch < 1) { |
1166 SkASSERT(!font->multiByteGlyphs()); | 1165 SkASSERT(!font->multiByteGlyphs()); |
(...skipping 10 matching lines...) Expand all Loading... |
1177 // try again | 1176 // try again |
1178 stretch = font->glyphsToPDFFontEncodingCount(glyphs, | 1177 stretch = font->glyphsToPDFFontEncodingCount(glyphs, |
1179 SkToInt(glyphsEnd - gly
phs)); | 1178 SkToInt(glyphsEnd - gly
phs)); |
1180 if (stretch < 1) { | 1179 if (stretch < 1) { |
1181 SkDEBUGFAIL("PDF could not encode glyph."); | 1180 SkDEBUGFAIL("PDF could not encode glyph."); |
1182 glyphPositioner.flush(); | 1181 glyphPositioner.flush(); |
1183 out->writeText("ET\n%SkPDF: Font encoding error.\n"); | 1182 out->writeText("ET\n%SkPDF: Font encoding error.\n"); |
1184 return; | 1183 return; |
1185 } | 1184 } |
1186 } | 1185 } |
1187 fontGlyphUsage->noteGlyphUsage(font, glyphs, stretch); | 1186 font->noteGlyphUsage(glyphs, stretch); |
1188 if (defaultPositioning) { | 1187 if (defaultPositioning) { |
1189 (void)font->glyphsToPDFFontEncoding(glyphs, SkToInt(glyphsEnd - glyp
hs)); | 1188 (void)font->glyphsToPDFFontEncoding(glyphs, SkToInt(glyphsEnd - glyp
hs)); |
1190 while (stretch-- > 0) { | 1189 while (stretch-- > 0) { |
1191 glyphPositioner.writeGlyph(0, 0, 0, *glyphs); | 1190 glyphPositioner.writeGlyph(0, 0, 0, *glyphs); |
1192 ++glyphs; | 1191 ++glyphs; |
1193 } | 1192 } |
1194 } else { | 1193 } else { |
1195 while (stretch-- > 0) { | 1194 while (stretch-- > 0) { |
1196 SkScalar advance = glyphCache->getGlyphIDAdvance(*glyphs).fAdvan
ceX; | 1195 SkScalar advance = glyphCache->getGlyphIDAdvance(*glyphs).fAdvan
ceX; |
1197 SkScalar x = *pos++; | 1196 SkScalar x = *pos++; |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1311 for (SkPDFFont* font : fFontResources) { | 1310 for (SkPDFFont* font : fFontResources) { |
1312 fonts.push(font); | 1311 fonts.push(font); |
1313 } | 1312 } |
1314 return SkPDFResourceDict::Make( | 1313 return SkPDFResourceDict::Make( |
1315 &fGraphicStateResources, | 1314 &fGraphicStateResources, |
1316 &fShaderResources, | 1315 &fShaderResources, |
1317 &fXObjectResources, | 1316 &fXObjectResources, |
1318 &fonts); | 1317 &fonts); |
1319 } | 1318 } |
1320 | 1319 |
1321 const SkTDArray<SkPDFFont*>& SkPDFDevice::getFontResources() const { | |
1322 return fFontResources; | |
1323 } | |
1324 | |
1325 sk_sp<SkPDFArray> SkPDFDevice::copyMediaBox() const { | 1320 sk_sp<SkPDFArray> SkPDFDevice::copyMediaBox() const { |
1326 auto mediaBox = sk_make_sp<SkPDFArray>(); | 1321 auto mediaBox = sk_make_sp<SkPDFArray>(); |
1327 mediaBox->reserve(4); | 1322 mediaBox->reserve(4); |
1328 mediaBox->appendInt(0); | 1323 mediaBox->appendInt(0); |
1329 mediaBox->appendInt(0); | 1324 mediaBox->appendInt(0); |
1330 mediaBox->appendInt(fPageSize.width()); | 1325 mediaBox->appendInt(fPageSize.width()); |
1331 mediaBox->appendInt(fPageSize.height()); | 1326 mediaBox->appendInt(fPageSize.height()); |
1332 return mediaBox; | 1327 return mediaBox; |
1333 } | 1328 } |
1334 | 1329 |
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 } | 1936 } |
1942 | 1937 |
1943 int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) { | 1938 int SkPDFDevice::getFontResourceIndex(SkTypeface* typeface, uint16_t glyphID) { |
1944 sk_sp<SkPDFFont> newFont( | 1939 sk_sp<SkPDFFont> newFont( |
1945 SkPDFFont::GetFontResource(fDocument->canon(), typeface, glyphID)); | 1940 SkPDFFont::GetFontResource(fDocument->canon(), typeface, glyphID)); |
1946 if (!newFont) { | 1941 if (!newFont) { |
1947 return -1; | 1942 return -1; |
1948 } | 1943 } |
1949 int resourceIndex = fFontResources.find(newFont.get()); | 1944 int resourceIndex = fFontResources.find(newFont.get()); |
1950 if (resourceIndex < 0) { | 1945 if (resourceIndex < 0) { |
| 1946 fDocument->registerFont(newFont.get()); |
1951 resourceIndex = fFontResources.count(); | 1947 resourceIndex = fFontResources.count(); |
1952 fFontResources.push(newFont.get()); | 1948 fFontResources.push(newFont.release()); |
1953 newFont.get()->ref(); | |
1954 } | 1949 } |
1955 return resourceIndex; | 1950 return resourceIndex; |
1956 } | 1951 } |
1957 | 1952 |
1958 static SkSize rect_to_size(const SkRect& r) { | 1953 static SkSize rect_to_size(const SkRect& r) { |
1959 return SkSize::Make(r.width(), r.height()); | 1954 return SkSize::Make(r.width(), r.height()); |
1960 } | 1955 } |
1961 | 1956 |
1962 static sk_sp<SkImage> color_filter(const SkImageBitmap& imageBitmap, | 1957 static sk_sp<SkImage> color_filter(const SkImageBitmap& imageBitmap, |
1963 SkColorFilter* colorFilter) { | 1958 SkColorFilter* colorFilter) { |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2160 } | 2155 } |
2161 | 2156 |
2162 sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkImage* image) { | 2157 sk_sp<SkSpecialImage> SkPDFDevice::makeSpecial(const SkImage* image) { |
2163 return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->
height()), | 2158 return SkSpecialImage::MakeFromImage(SkIRect::MakeWH(image->width(), image->
height()), |
2164 image->makeNonTextureImage()); | 2159 image->makeNonTextureImage()); |
2165 } | 2160 } |
2166 | 2161 |
2167 sk_sp<SkSpecialImage> SkPDFDevice::snapSpecial() { | 2162 sk_sp<SkSpecialImage> SkPDFDevice::snapSpecial() { |
2168 return nullptr; | 2163 return nullptr; |
2169 } | 2164 } |
OLD | NEW |