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 "SkTypes.h" | 8 #include "SkTypes.h" |
9 #if defined(SK_BUILD_FOR_WIN32) | 9 #if defined(SK_BUILD_FOR_WIN32) |
10 | 10 |
11 #ifndef UNICODE | 11 #ifndef UNICODE |
12 #define UNICODE | 12 #define UNICODE |
13 #endif | 13 #endif |
14 #ifndef _UNICODE | 14 #ifndef _UNICODE |
15 #define _UNICODE | 15 #define _UNICODE |
16 #endif | 16 #endif |
17 #include <ObjBase.h> | 17 #include <ObjBase.h> |
18 #include <XpsObjectModel.h> | 18 #include <XpsObjectModel.h> |
19 #include <T2EmbApi.h> | 19 #include <T2EmbApi.h> |
20 #include <FontSub.h> | 20 #include <FontSub.h> |
21 #include <limits> | |
21 | 22 |
22 #include "SkColor.h" | 23 #include "SkColor.h" |
23 #include "SkConstexprMath.h" | |
24 #include "SkData.h" | 24 #include "SkData.h" |
25 #include "SkDraw.h" | 25 #include "SkDraw.h" |
26 #include "SkEndian.h" | 26 #include "SkEndian.h" |
27 #include "SkFindAndPlaceGlyph.h" | 27 #include "SkFindAndPlaceGlyph.h" |
28 #include "SkGeometry.h" | 28 #include "SkGeometry.h" |
29 #include "SkGlyphCache.h" | 29 #include "SkGlyphCache.h" |
30 #include "SkHRESULT.h" | 30 #include "SkHRESULT.h" |
31 #include "SkImageEncoder.h" | 31 #include "SkImageEncoder.h" |
32 #include "SkIStream.h" | 32 #include "SkIStream.h" |
33 #include "SkMaskFilter.h" | 33 #include "SkMaskFilter.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
183 this->fCurrentUnitsPerMeter = unitsPerMeter; | 183 this->fCurrentUnitsPerMeter = unitsPerMeter; |
184 this->fCurrentPixelsPerMeter = pixelsPerMeter; | 184 this->fCurrentPixelsPerMeter = pixelsPerMeter; |
185 | 185 |
186 this->fCurrentXpsCanvas.reset(); | 186 this->fCurrentXpsCanvas.reset(); |
187 HRBM(this->fXpsFactory->CreateCanvas(&this->fCurrentXpsCanvas), | 187 HRBM(this->fXpsFactory->CreateCanvas(&this->fCurrentXpsCanvas), |
188 "Could not create base canvas."); | 188 "Could not create base canvas."); |
189 | 189 |
190 return true; | 190 return true; |
191 } | 191 } |
192 | 192 |
193 template <typename T> static constexpr size_t sk_digits_in() { | |
194 return static_cast<size_t>(std::numeric_limits<T>::digits10 + 1); | |
195 } | |
196 | |
193 HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page, | 197 HRESULT SkXPSDevice::createXpsThumbnail(IXpsOMPage* page, |
194 const unsigned int pageNum, | 198 const unsigned int pageNum, |
195 IXpsOMImageResource** image) { | 199 IXpsOMImageResource** image) { |
196 SkTScopedComPtr<IXpsOMThumbnailGenerator> thumbnailGenerator; | 200 SkTScopedComPtr<IXpsOMThumbnailGenerator> thumbnailGenerator; |
197 HRM(CoCreateInstance( | 201 HRM(CoCreateInstance( |
198 CLSID_XpsOMThumbnailGenerator, | 202 CLSID_XpsOMThumbnailGenerator, |
199 nullptr, | 203 nullptr, |
200 CLSCTX_INPROC_SERVER, | 204 CLSCTX_INPROC_SERVER, |
201 IID_PPV_ARGS(&thumbnailGenerator)), | 205 IID_PPV_ARGS(&thumbnailGenerator)), |
202 "Could not create thumbnail generator."); | 206 "Could not create thumbnail generator."); |
203 | 207 |
204 SkTScopedComPtr<IOpcPartUri> partUri; | 208 SkTScopedComPtr<IOpcPartUri> partUri; |
205 static const size_t size = SkTUMax< | 209 constexpr size_t size = SkTMax( |
bungeman-skia
2016/05/31 18:07:17
I've gone back and forth now trying to figure out
| |
206 SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + SK_DIGITS_IN(pageNum), | 210 SK_ARRAY_COUNT(L"/Documents/1/Metadata/.png") + sk_digits_in<decltyp e(pageNum)>(), |
207 SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png") | 211 SK_ARRAY_COUNT(L"/Metadata/" L_GUID_ID L".png")); |
208 >::value; | |
209 wchar_t buffer[size]; | 212 wchar_t buffer[size]; |
210 if (pageNum > 0) { | 213 if (pageNum > 0) { |
211 swprintf_s(buffer, size, L"/Documents/1/Metadata/%u.png", pageNum); | 214 swprintf_s(buffer, size, L"/Documents/1/Metadata/%u.png", pageNum); |
212 } else { | 215 } else { |
213 wchar_t id[GUID_ID_LEN]; | 216 wchar_t id[GUID_ID_LEN]; |
214 HR(this->createId(id, GUID_ID_LEN)); | 217 HR(this->createId(id, GUID_ID_LEN)); |
215 swprintf_s(buffer, size, L"/Metadata/%s.png", id); | 218 swprintf_s(buffer, size, L"/Metadata/%s.png", id); |
216 } | 219 } |
217 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), | 220 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), |
218 "Could not create thumbnail part uri."); | 221 "Could not create thumbnail part uri."); |
219 | 222 |
220 HRM(thumbnailGenerator->GenerateThumbnail(page, | 223 HRM(thumbnailGenerator->GenerateThumbnail(page, |
221 XPS_IMAGE_TYPE_PNG, | 224 XPS_IMAGE_TYPE_PNG, |
222 XPS_THUMBNAIL_SIZE_LARGE, | 225 XPS_THUMBNAIL_SIZE_LARGE, |
223 partUri.get(), | 226 partUri.get(), |
224 image), | 227 image), |
225 "Could not generate thumbnail."); | 228 "Could not generate thumbnail."); |
226 | 229 |
227 return S_OK; | 230 return S_OK; |
228 } | 231 } |
229 | 232 |
230 HRESULT SkXPSDevice::createXpsPage(const XPS_SIZE& pageSize, | 233 HRESULT SkXPSDevice::createXpsPage(const XPS_SIZE& pageSize, |
231 IXpsOMPage** page) { | 234 IXpsOMPage** page) { |
232 static const size_t size = SK_ARRAY_COUNT(L"/Documents/1/Pages/.fpage") | 235 constexpr size_t size = |
233 + SK_DIGITS_IN(fCurrentPage); | 236 SK_ARRAY_COUNT(L"/Documents/1/Pages/.fpage") |
237 + sk_digits_in<decltype(fCurrentPage)>(); | |
234 wchar_t buffer[size]; | 238 wchar_t buffer[size]; |
235 swprintf_s(buffer, size, L"/Documents/1/Pages/%u.fpage", | 239 swprintf_s(buffer, size, L"/Documents/1/Pages/%u.fpage", |
236 this->fCurrentPage); | 240 this->fCurrentPage); |
237 SkTScopedComPtr<IOpcPartUri> partUri; | 241 SkTScopedComPtr<IOpcPartUri> partUri; |
238 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), | 242 HRM(this->fXpsFactory->CreatePartUri(buffer, &partUri), |
239 "Could not create page part uri."); | 243 "Could not create page part uri."); |
240 | 244 |
241 //If the language is unknown, use "und" (XPS Spec 2.3.5.1). | 245 //If the language is unknown, use "und" (XPS Spec 2.3.5.1). |
242 HRM(this->fXpsFactory->CreatePage(&pageSize, | 246 HRM(this->fXpsFactory->CreatePage(&pageSize, |
243 L"und", | 247 L"und", |
(...skipping 2027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2271 //SkXPSDevice* dev = new SkXPSDevice(this); | 2275 //SkXPSDevice* dev = new SkXPSDevice(this); |
2272 //SkSize s = SkSize::Make(width, height); | 2276 //SkSize s = SkSize::Make(width, height); |
2273 //dev->BeginCanvas(s, s, SkMatrix::I()); | 2277 //dev->BeginCanvas(s, s, SkMatrix::I()); |
2274 //return dev; | 2278 //return dev; |
2275 } | 2279 } |
2276 #endif | 2280 #endif |
2277 return new SkXPSDevice(this->fXpsFactory.get()); | 2281 return new SkXPSDevice(this->fXpsFactory.get()); |
2278 } | 2282 } |
2279 | 2283 |
2280 #endif//defined(SK_BUILD_FOR_WIN32) | 2284 #endif//defined(SK_BUILD_FOR_WIN32) |
OLD | NEW |