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 #ifndef UNICODE | 8 #ifndef UNICODE |
9 #define UNICODE | 9 #define UNICODE |
10 #endif | 10 #endif |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "SkDraw.h" | 23 #include "SkDraw.h" |
24 #include "SkDrawProcs.h" | 24 #include "SkDrawProcs.h" |
25 #include "SkEndian.h" | 25 #include "SkEndian.h" |
26 #include "SkFontHost.h" | 26 #include "SkFontHost.h" |
27 #include "SkGlyphCache.h" | 27 #include "SkGlyphCache.h" |
28 #include "SkHRESULT.h" | 28 #include "SkHRESULT.h" |
29 #include "SkImageEncoder.h" | 29 #include "SkImageEncoder.h" |
30 #include "SkIStream.h" | 30 #include "SkIStream.h" |
31 #include "SkMaskFilter.h" | 31 #include "SkMaskFilter.h" |
32 #include "SkPaint.h" | 32 #include "SkPaint.h" |
| 33 #include "SkPathOps.h" |
33 #include "SkPoint.h" | 34 #include "SkPoint.h" |
34 #include "SkRasterizer.h" | 35 #include "SkRasterizer.h" |
35 #include "SkSFNTHeader.h" | 36 #include "SkSFNTHeader.h" |
36 #include "SkShader.h" | 37 #include "SkShader.h" |
37 #include "SkSize.h" | 38 #include "SkSize.h" |
38 #include "SkStream.h" | 39 #include "SkStream.h" |
39 #include "SkTDArray.h" | 40 #include "SkTDArray.h" |
40 #include "SkTLazy.h" | 41 #include "SkTLazy.h" |
41 #include "SkTScopedComPtr.h" | 42 #include "SkTScopedComPtr.h" |
42 #include "SkTTCFHeader.h" | 43 #include "SkTTCFHeader.h" |
43 #include "SkTypefacePriv.h" | 44 #include "SkTypefacePriv.h" |
44 #include "SkUtils.h" | 45 #include "SkUtils.h" |
45 #include "SkXPSDevice.h" | 46 #include "SkXPSDevice.h" |
46 | 47 |
47 //Windows defines a FLOAT type, | 48 //Windows defines a FLOAT type, |
48 //make it clear when converting a scalar that this is what is wanted. | 49 //make it clear when converting a scalar that this is what is wanted. |
49 #define SkScalarToFLOAT(n) SkScalarToFloat(n) | 50 #define SkScalarToFLOAT(n) SkScalarToFloat(n) |
50 | 51 |
51 //Dummy representation of a GUID from create_id. | 52 //Dummy representation of a GUID from createId. |
52 #define L_GUID_ID L"XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX" | 53 #define L_GUID_ID L"XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX" |
53 //Length of GUID representation from create_id, including NULL terminator. | 54 //Length of GUID representation from createId, including NULL terminator. |
54 #define GUID_ID_LEN SK_ARRAY_COUNT(L_GUID_ID) | 55 #define GUID_ID_LEN SK_ARRAY_COUNT(L_GUID_ID) |
55 | 56 |
56 /** | 57 /** |
57 Formats a GUID and places it into buffer. | 58 Formats a GUID and places it into buffer. |
58 buffer should have space for at least GUID_ID_LEN wide characters. | 59 buffer should have space for at least GUID_ID_LEN wide characters. |
59 The string will always be wchar null terminated. | 60 The string will always be wchar null terminated. |
60 XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX0 | 61 XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX0 |
61 @return -1 if there was an error, > 0 if success. | 62 @return -1 if there was an error, > 0 if success. |
62 */ | 63 */ |
63 static int format_guid(const GUID& guid, | 64 static int format_guid(const GUID& guid, |
(...skipping 13 matching lines...) Expand all Loading... |
77 guid.Data4[1], | 78 guid.Data4[1], |
78 sep, | 79 sep, |
79 guid.Data4[2], | 80 guid.Data4[2], |
80 guid.Data4[3], | 81 guid.Data4[3], |
81 guid.Data4[4], | 82 guid.Data4[4], |
82 guid.Data4[5], | 83 guid.Data4[5], |
83 guid.Data4[6], | 84 guid.Data4[6], |
84 guid.Data4[7]); | 85 guid.Data4[7]); |
85 } | 86 } |
86 | 87 |
87 /** | 88 HRESULT SkXPSDevice::createId(wchar_t* buffer, size_t bufferSize, wchar_t sep) { |
88 Creates a GUID based id and places it into buffer. | |
89 buffer should have space for at least GUID_ID_LEN wide characters. | |
90 The string will always be wchar null terminated. | |
91 XXXXXXXXsXXXXsXXXXsXXXXsXXXXXXXXXXXX0 | |
92 The string may begin with a digit, | |
93 and so may not be suitable as a bare resource key. | |
94 */ | |
95 static HRESULT create_id(wchar_t* buffer, size_t bufferSize, | |
96 wchar_t sep = '-') { | |
97 GUID guid = {}; | 89 GUID guid = {}; |
| 90 #ifdef SK_XPS_USE_DETERMINISTIC_IDS |
| 91 guid.Data1 = fNextId++; |
| 92 // The following make this a valid Type4 UUID. |
| 93 guid.Data3 = 0x4000; |
| 94 guid.Data4[0] = 0x80; |
| 95 #else |
98 HRM(CoCreateGuid(&guid), "Could not create GUID for id."); | 96 HRM(CoCreateGuid(&guid), "Could not create GUID for id."); |
| 97 #endif |
99 | 98 |
100 if (format_guid(guid, buffer, bufferSize, sep) == -1) { | 99 if (format_guid(guid, buffer, bufferSize, sep) == -1) { |
101 HRM(E_UNEXPECTED, "Could not format GUID into id."); | 100 HRM(E_UNEXPECTED, "Could not format GUID into id."); |
102 } | 101 } |
103 | 102 |
104 return S_OK; | 103 return S_OK; |
105 } | 104 } |
106 | 105 |
107 static SkBitmap make_fake_bitmap(int width, int height) { | 106 static SkBitmap make_fake_bitmap(int width, int height) { |
108 SkBitmap bitmap; | 107 SkBitmap bitmap; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 SkTScopedComPtr<IOpcPartUri> partUri; | 185 SkTScopedComPtr<IOpcPartUri> partUri; |
187 static const size_t size = SkTUMax< | 186 static const size_t size = SkTUMax< |
188 SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + SK_DIGITS_IN(pageNum), | 187 SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + SK_DIGITS_IN(pageNum), |
189 SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png") | 188 SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png") |
190 >::value; | 189 >::value; |
191 wchar_t buffer[size]; | 190 wchar_t buffer[size]; |
192 if (pageNum > 0) { | 191 if (pageNum > 0) { |
193 swprintf_s(buffer, size, L"/Documents/1/Metadata/%u.png", pageNum); | 192 swprintf_s(buffer, size, L"/Documents/1/Metadata/%u.png", pageNum); |
194 } else { | 193 } else { |
195 wchar_t id[GUID_ID_LEN]; | 194 wchar_t id[GUID_ID_LEN]; |
196 HR(create_id(id, GUID_ID_LEN)); | 195 HR(this->createId(id, GUID_ID_LEN)); |
197 swprintf_s(buffer, size, L"/Metadata/%s.png", id); | 196 swprintf_s(buffer, size, L"/Metadata/%s.png", id); |
198 } | 197 } |
199 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), | 198 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), |
200 "Could not create thumbnail part uri."); | 199 "Could not create thumbnail part uri."); |
201 | 200 |
202 HRM(thumbnailGenerator->GenerateThumbnail(page, | 201 HRM(thumbnailGenerator->GenerateThumbnail(page, |
203 XPS_IMAGE_TYPE_PNG, | 202 XPS_IMAGE_TYPE_PNG, |
204 XPS_THUMBNAIL_SIZE_LARGE, | 203 XPS_THUMBNAIL_SIZE_LARGE, |
205 partUri.get(), | 204 partUri.get(), |
206 image), | 205 image), |
(...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
640 SkMemoryStream* read = new SkMemoryStream; | 639 SkMemoryStream* read = new SkMemoryStream; |
641 read->setData(write.copyToData())->unref(); | 640 read->setData(write.copyToData())->unref(); |
642 SkTScopedComPtr<IStream> readWrapper; | 641 SkTScopedComPtr<IStream> readWrapper; |
643 HRM(SkIStream::CreateFromSkStream(read, true, &readWrapper), | 642 HRM(SkIStream::CreateFromSkStream(read, true, &readWrapper), |
644 "Could not create stream from png data."); | 643 "Could not create stream from png data."); |
645 | 644 |
646 const size_t size = | 645 const size_t size = |
647 SK_ARRAY_COUNT(L"/Documents/1/Resources/Images/" L_GUID_ID L".png"); | 646 SK_ARRAY_COUNT(L"/Documents/1/Resources/Images/" L_GUID_ID L".png"); |
648 wchar_t buffer[size]; | 647 wchar_t buffer[size]; |
649 wchar_t id[GUID_ID_LEN]; | 648 wchar_t id[GUID_ID_LEN]; |
650 HR(create_id(id, GUID_ID_LEN)); | 649 HR(this->createId(id, GUID_ID_LEN)); |
651 swprintf_s(buffer, size, L"/Documents/1/Resources/Images/%s.png", id); | 650 swprintf_s(buffer, size, L"/Documents/1/Resources/Images/%s.png", id); |
652 | 651 |
653 SkTScopedComPtr<IOpcPartUri> imagePartUri; | 652 SkTScopedComPtr<IOpcPartUri> imagePartUri; |
654 HRM(this->fXpsFactory->CreatePartUri(buffer, &imagePartUri), | 653 HRM(this->fXpsFactory->CreatePartUri(buffer, &imagePartUri), |
655 "Could not create image part uri."); | 654 "Could not create image part uri."); |
656 | 655 |
657 SkTScopedComPtr<IXpsOMImageResource> imageResource; | 656 SkTScopedComPtr<IXpsOMImageResource> imageResource; |
658 HRM(this->fXpsFactory->CreateImageResource( | 657 HRM(this->fXpsFactory->CreateImageResource( |
659 readWrapper.get(), | 658 readWrapper.get(), |
660 XPS_IMAGE_TYPE_PNG, | 659 XPS_IMAGE_TYPE_PNG, |
(...skipping 769 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1430 //Save the old canvas to a dictionary on the new canvas. | 1429 //Save the old canvas to a dictionary on the new canvas. |
1431 SkTScopedComPtr<IXpsOMDictionary> newDictionary; | 1430 SkTScopedComPtr<IXpsOMDictionary> newDictionary; |
1432 HRM(this->fXpsFactory->CreateDictionary(&newDictionary), | 1431 HRM(this->fXpsFactory->CreateDictionary(&newDictionary), |
1433 "Could not create inverse dictionary."); | 1432 "Could not create inverse dictionary."); |
1434 HRM(newCanvas->SetDictionaryLocal(newDictionary.get()), | 1433 HRM(newCanvas->SetDictionaryLocal(newDictionary.get()), |
1435 "Could not set inverse dictionary."); | 1434 "Could not set inverse dictionary."); |
1436 | 1435 |
1437 const size_t size = SK_ARRAY_COUNT(L"ID" L_GUID_ID); | 1436 const size_t size = SK_ARRAY_COUNT(L"ID" L_GUID_ID); |
1438 wchar_t buffer[size]; | 1437 wchar_t buffer[size]; |
1439 wchar_t id[GUID_ID_LEN]; | 1438 wchar_t id[GUID_ID_LEN]; |
1440 HR(create_id(id, GUID_ID_LEN, '_')); | 1439 HR(this->createId(id, GUID_ID_LEN, '_')); |
1441 swprintf_s(buffer, size, L"ID%s", id); | 1440 swprintf_s(buffer, size, L"ID%s", id); |
1442 HRM(newDictionary->Append(buffer, this->fCurrentXpsCanvas.get()), | 1441 HRM(newDictionary->Append(buffer, this->fCurrentXpsCanvas.get()), |
1443 "Could not add canvas to inverse dictionary."); | 1442 "Could not add canvas to inverse dictionary."); |
1444 | 1443 |
1445 //Start drawing | 1444 //Start drawing |
1446 SkTScopedComPtr<IXpsOMVisualCollection> newVisuals; | 1445 SkTScopedComPtr<IXpsOMVisualCollection> newVisuals; |
1447 HRM(newCanvas->GetVisuals(&newVisuals), | 1446 HRM(newCanvas->GetVisuals(&newVisuals), |
1448 "Could not get inverse canvas visuals."); | 1447 "Could not get inverse canvas visuals."); |
1449 | 1448 |
1450 //Draw old canvas from dictionary onto new canvas. | 1449 //Draw old canvas from dictionary onto new canvas. |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2051 int ttcIndex; | 2050 int ttcIndex; |
2052 SkStream* fontData = typeface->openStream(&ttcIndex); | 2051 SkStream* fontData = typeface->openStream(&ttcIndex); |
2053 //TODO: cannot handle FON fonts. | 2052 //TODO: cannot handle FON fonts. |
2054 HRM(SkIStream::CreateFromSkStream(fontData, true, &fontStream), | 2053 HRM(SkIStream::CreateFromSkStream(fontData, true, &fontStream), |
2055 "Could not create font stream."); | 2054 "Could not create font stream."); |
2056 | 2055 |
2057 const size_t size = | 2056 const size_t size = |
2058 SK_ARRAY_COUNT(L"/Resources/Fonts/" L_GUID_ID L".odttf"); | 2057 SK_ARRAY_COUNT(L"/Resources/Fonts/" L_GUID_ID L".odttf"); |
2059 wchar_t buffer[size]; | 2058 wchar_t buffer[size]; |
2060 wchar_t id[GUID_ID_LEN]; | 2059 wchar_t id[GUID_ID_LEN]; |
2061 HR(create_id(id, GUID_ID_LEN)); | 2060 HR(this->createId(id, GUID_ID_LEN)); |
2062 swprintf_s(buffer, size, L"/Resources/Fonts/%s.odttf", id); | 2061 swprintf_s(buffer, size, L"/Resources/Fonts/%s.odttf", id); |
2063 | 2062 |
2064 SkTScopedComPtr<IOpcPartUri> partUri; | 2063 SkTScopedComPtr<IOpcPartUri> partUri; |
2065 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), | 2064 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), |
2066 "Could not create font resource part uri."); | 2065 "Could not create font resource part uri."); |
2067 | 2066 |
2068 SkTScopedComPtr<IXpsOMFontResource> xpsFontResource; | 2067 SkTScopedComPtr<IXpsOMFontResource> xpsFontResource; |
2069 HRM(this->fXpsFactory->CreateFontResource(fontStream.get(), | 2068 HRM(this->fXpsFactory->CreateFontResource(fontStream.get(), |
2070 embedding, | 2069 embedding, |
2071 partUri.get(), | 2070 partUri.get(), |
(...skipping 359 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2431 IID_PPV_ARGS(&this->fXpsFactory)), | 2430 IID_PPV_ARGS(&this->fXpsFactory)), |
2432 "Could not create factory for layer."); | 2431 "Could not create factory for layer."); |
2433 | 2432 |
2434 HRVM(this->fXpsFactory->CreateCanvas(&this->fCurrentXpsCanvas), | 2433 HRVM(this->fXpsFactory->CreateCanvas(&this->fCurrentXpsCanvas), |
2435 "Could not create canvas for layer."); | 2434 "Could not create canvas for layer."); |
2436 } | 2435 } |
2437 | 2436 |
2438 bool SkXPSDevice::allowImageFilter(const SkImageFilter*) { | 2437 bool SkXPSDevice::allowImageFilter(const SkImageFilter*) { |
2439 return false; | 2438 return false; |
2440 } | 2439 } |
OLD | NEW |