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

Side by Side Diff: src/ports/SkRemotableFontMgr_win_dw.cpp

Issue 1037793002: C++11 override should now be supported by all of {bots,Chrome,Android,Mozilla} (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: git cl web Created 5 years, 8 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/ports/SkImageGenerator_skia.cpp ('k') | src/ports/SkScalerContext_win_dw.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 2014 Google Inc. 2 * Copyright 2014 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 "SkDataTable.h" 8 #include "SkDataTable.h"
9 #include "SkDWrite.h" 9 #include "SkDWrite.h"
10 #include "SkDWriteFontFileStream.h" 10 #include "SkDWriteFontFileStream.h"
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 84
85 /** localeNameLength must include the null terminator. */ 85 /** localeNameLength must include the null terminator. */
86 SkRemotableFontMgr_DirectWrite(IDWriteFontCollection* fontCollection, 86 SkRemotableFontMgr_DirectWrite(IDWriteFontCollection* fontCollection,
87 WCHAR* localeName, int localeNameLength) 87 WCHAR* localeName, int localeNameLength)
88 : fFontCollection(SkRefComPtr(fontCollection)) 88 : fFontCollection(SkRefComPtr(fontCollection))
89 , fLocaleName(localeNameLength) 89 , fLocaleName(localeNameLength)
90 { 90 {
91 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR)); 91 memcpy(fLocaleName.get(), localeName, localeNameLength * sizeof(WCHAR));
92 } 92 }
93 93
94 SkDataTable* getFamilyNames() const SK_OVERRIDE { 94 SkDataTable* getFamilyNames() const override {
95 int count = fFontCollection->GetFontFamilyCount(); 95 int count = fFontCollection->GetFontFamilyCount();
96 96
97 SkDataTableBuilder names(1024); 97 SkDataTableBuilder names(1024);
98 for (int index = 0; index < count; ++index) { 98 for (int index = 0; index < count; ++index) {
99 SkTScopedComPtr<IDWriteFontFamily> fontFamily; 99 SkTScopedComPtr<IDWriteFontFamily> fontFamily;
100 HRNM(fFontCollection->GetFontFamily(index, &fontFamily), 100 HRNM(fFontCollection->GetFontFamily(index, &fontFamily),
101 "Could not get requested family."); 101 "Could not get requested family.");
102 102
103 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames; 103 SkTScopedComPtr<IDWriteLocalizedStrings> familyNames;
104 HRNM(fontFamily->GetFamilyNames(&familyNames), "Could not get family names."); 104 HRNM(fontFamily->GetFamilyNames(&familyNames), "Could not get family names.");
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 SkASSERT(false); 151 SkASSERT(false);
152 } 152 }
153 153
154 int weight = font->GetWeight(); 154 int weight = font->GetWeight();
155 int width = font->GetStretch(); 155 int width = font->GetStretch();
156 156
157 fontId->fFontStyle = SkFontStyle(weight, width, slant); 157 fontId->fFontStyle = SkFontStyle(weight, width, slant);
158 return S_OK; 158 return S_OK;
159 } 159 }
160 160
161 SkRemotableFontIdentitySet* getIndex(int familyIndex) const SK_OVERRIDE { 161 SkRemotableFontIdentitySet* getIndex(int familyIndex) const override {
162 SkTScopedComPtr<IDWriteFontFamily> fontFamily; 162 SkTScopedComPtr<IDWriteFontFamily> fontFamily;
163 HRNM(fFontCollection->GetFontFamily(familyIndex, &fontFamily), 163 HRNM(fFontCollection->GetFontFamily(familyIndex, &fontFamily),
164 "Could not get requested family."); 164 "Could not get requested family.");
165 165
166 int count = fontFamily->GetFontCount(); 166 int count = fontFamily->GetFontCount();
167 SkFontIdentity* fontIds; 167 SkFontIdentity* fontIds;
168 SkAutoTUnref<SkRemotableFontIdentitySet> fontIdSet( 168 SkAutoTUnref<SkRemotableFontIdentitySet> fontIdSet(
169 new SkRemotableFontIdentitySet(count, &fontIds)); 169 new SkRemotableFontIdentitySet(count, &fontIds));
170 for (int fontIndex = 0; fontIndex < count; ++fontIndex) { 170 for (int fontIndex = 0; fontIndex < count; ++fontIndex) {
171 SkTScopedComPtr<IDWriteFont> font; 171 SkTScopedComPtr<IDWriteFont> font;
172 HRNM(fontFamily->GetFont(fontIndex, &font), "Could not get font."); 172 HRNM(fontFamily->GetFont(fontIndex, &font), "Could not get font.");
173 173
174 HRN(FontToIdentity(font.get(), &fontIds[fontIndex])); 174 HRN(FontToIdentity(font.get(), &fontIds[fontIndex]));
175 } 175 }
176 return fontIdSet.detach(); 176 return fontIdSet.detach();
177 } 177 }
178 178
179 virtual SkFontIdentity matchIndexStyle(int familyIndex, 179 virtual SkFontIdentity matchIndexStyle(int familyIndex,
180 const SkFontStyle& pattern) const SK_ OVERRIDE 180 const SkFontStyle& pattern) const ove rride
181 { 181 {
182 SkFontIdentity identity = { SkFontIdentity::kInvalidDataId }; 182 SkFontIdentity identity = { SkFontIdentity::kInvalidDataId };
183 183
184 SkTScopedComPtr<IDWriteFontFamily> fontFamily; 184 SkTScopedComPtr<IDWriteFontFamily> fontFamily;
185 HR_GENERAL(fFontCollection->GetFontFamily(familyIndex, &fontFamily), 185 HR_GENERAL(fFontCollection->GetFontFamily(familyIndex, &fontFamily),
186 "Could not get requested family.", 186 "Could not get requested family.",
187 identity); 187 identity);
188 188
189 const DWriteStyle dwStyle(pattern); 189 const DWriteStyle dwStyle(pattern);
190 SkTScopedComPtr<IDWriteFont> font; 190 SkTScopedComPtr<IDWriteFont> font;
(...skipping 18 matching lines...) Expand all
209 } 209 }
210 210
211 size_t len = wcsnlen_s(metrics.lfMessageFont.lfFaceName, LF_FACESIZE) + 1; 211 size_t len = wcsnlen_s(metrics.lfMessageFont.lfFaceName, LF_FACESIZE) + 1;
212 if (0 != wcsncpy_s(name->reset(len), len, metrics.lfMessageFont.lfFaceNa me, _TRUNCATE)) { 212 if (0 != wcsncpy_s(name->reset(len), len, metrics.lfMessageFont.lfFaceNa me, _TRUNCATE)) {
213 return E_UNEXPECTED; 213 return E_UNEXPECTED;
214 } 214 }
215 215
216 return S_OK; 216 return S_OK;
217 } 217 }
218 218
219 SkRemotableFontIdentitySet* matchName(const char familyName[]) const SK_OVER RIDE { 219 SkRemotableFontIdentitySet* matchName(const char familyName[]) const overrid e {
220 SkSMallocWCHAR dwFamilyName; 220 SkSMallocWCHAR dwFamilyName;
221 if (NULL == familyName) { 221 if (NULL == familyName) {
222 HR_GENERAL(getDefaultFontFamilyName(&dwFamilyName), 222 HR_GENERAL(getDefaultFontFamilyName(&dwFamilyName),
223 NULL, SkRemotableFontIdentitySet::NewEmpty()); 223 NULL, SkRemotableFontIdentitySet::NewEmpty());
224 } else { 224 } else {
225 HR_GENERAL(sk_cstring_to_wchar(familyName, &dwFamilyName), 225 HR_GENERAL(sk_cstring_to_wchar(familyName, &dwFamilyName),
226 NULL, SkRemotableFontIdentitySet::NewEmpty()); 226 NULL, SkRemotableFontIdentitySet::NewEmpty());
227 } 227 }
228 228
229 UINT32 index; 229 UINT32 index;
230 BOOL exists; 230 BOOL exists;
231 HR_GENERAL(fFontCollection->FindFamilyName(dwFamilyName.get(), &index, & exists), 231 HR_GENERAL(fFontCollection->FindFamilyName(dwFamilyName.get(), &index, & exists),
232 "Failed while finding family by name.", 232 "Failed while finding family by name.",
233 SkRemotableFontIdentitySet::NewEmpty()); 233 SkRemotableFontIdentitySet::NewEmpty());
234 if (!exists) { 234 if (!exists) {
235 return SkRemotableFontIdentitySet::NewEmpty(); 235 return SkRemotableFontIdentitySet::NewEmpty();
236 } 236 }
237 237
238 return this->getIndex(index); 238 return this->getIndex(index);
239 } 239 }
240 240
241 virtual SkFontIdentity matchNameStyle(const char familyName[], 241 virtual SkFontIdentity matchNameStyle(const char familyName[],
242 const SkFontStyle& style) const SK_OVE RRIDE 242 const SkFontStyle& style) const overri de
243 { 243 {
244 SkFontIdentity identity = { SkFontIdentity::kInvalidDataId }; 244 SkFontIdentity identity = { SkFontIdentity::kInvalidDataId };
245 245
246 SkSMallocWCHAR dwFamilyName; 246 SkSMallocWCHAR dwFamilyName;
247 if (NULL == familyName) { 247 if (NULL == familyName) {
248 HR_GENERAL(getDefaultFontFamilyName(&dwFamilyName), NULL, identity); 248 HR_GENERAL(getDefaultFontFamilyName(&dwFamilyName), NULL, identity);
249 } else { 249 } else {
250 HR_GENERAL(sk_cstring_to_wchar(familyName, &dwFamilyName), NULL, ide ntity); 250 HR_GENERAL(sk_cstring_to_wchar(familyName, &dwFamilyName), NULL, ide ntity);
251 } 251 }
252 252
(...skipping 19 matching lines...) Expand all
272 virtual ~FontFallbackRenderer() { } 272 virtual ~FontFallbackRenderer() { }
273 273
274 // IDWriteTextRenderer methods 274 // IDWriteTextRenderer methods
275 virtual HRESULT STDMETHODCALLTYPE DrawGlyphRun( 275 virtual HRESULT STDMETHODCALLTYPE DrawGlyphRun(
276 void* clientDrawingContext, 276 void* clientDrawingContext,
277 FLOAT baselineOriginX, 277 FLOAT baselineOriginX,
278 FLOAT baselineOriginY, 278 FLOAT baselineOriginY,
279 DWRITE_MEASURING_MODE measuringMode, 279 DWRITE_MEASURING_MODE measuringMode,
280 DWRITE_GLYPH_RUN const* glyphRun, 280 DWRITE_GLYPH_RUN const* glyphRun,
281 DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription, 281 DWRITE_GLYPH_RUN_DESCRIPTION const* glyphRunDescription,
282 IUnknown* clientDrawingEffect) SK_OVERRIDE 282 IUnknown* clientDrawingEffect) override
283 { 283 {
284 SkTScopedComPtr<IDWriteFont> font; 284 SkTScopedComPtr<IDWriteFont> font;
285 HRM(fOuter->fFontCollection->GetFontFromFontFace(glyphRun->fontFace, &font), 285 HRM(fOuter->fFontCollection->GetFontFromFontFace(glyphRun->fontFace, &font),
286 "Could not get font from font face."); 286 "Could not get font from font face.");
287 287
288 // It is possible that the font passed does not actually have the re quested character, 288 // It is possible that the font passed does not actually have the re quested character,
289 // due to no font being found and getting the fallback font. 289 // due to no font being found and getting the fallback font.
290 // Check that the font actually contains the requested character. 290 // Check that the font actually contains the requested character.
291 BOOL exists; 291 BOOL exists;
292 HRM(font->HasCharacter(fCharacter, &exists), "Could not find charact er."); 292 HRM(font->HasCharacter(fCharacter, &exists), "Could not find charact er.");
293 293
294 if (exists) { 294 if (exists) {
295 HR(fOuter->FontToIdentity(font.get(), &fIdentity)); 295 HR(fOuter->FontToIdentity(font.get(), &fIdentity));
296 } 296 }
297 297
298 return S_OK; 298 return S_OK;
299 } 299 }
300 300
301 virtual HRESULT STDMETHODCALLTYPE DrawUnderline( 301 virtual HRESULT STDMETHODCALLTYPE DrawUnderline(
302 void* clientDrawingContext, 302 void* clientDrawingContext,
303 FLOAT baselineOriginX, 303 FLOAT baselineOriginX,
304 FLOAT baselineOriginY, 304 FLOAT baselineOriginY,
305 DWRITE_UNDERLINE const* underline, 305 DWRITE_UNDERLINE const* underline,
306 IUnknown* clientDrawingEffect) SK_OVERRIDE 306 IUnknown* clientDrawingEffect) override
307 { return E_NOTIMPL; } 307 { return E_NOTIMPL; }
308 308
309 virtual HRESULT STDMETHODCALLTYPE DrawStrikethrough( 309 virtual HRESULT STDMETHODCALLTYPE DrawStrikethrough(
310 void* clientDrawingContext, 310 void* clientDrawingContext,
311 FLOAT baselineOriginX, 311 FLOAT baselineOriginX,
312 FLOAT baselineOriginY, 312 FLOAT baselineOriginY,
313 DWRITE_STRIKETHROUGH const* strikethrough, 313 DWRITE_STRIKETHROUGH const* strikethrough,
314 IUnknown* clientDrawingEffect) SK_OVERRIDE 314 IUnknown* clientDrawingEffect) override
315 { return E_NOTIMPL; } 315 { return E_NOTIMPL; }
316 316
317 virtual HRESULT STDMETHODCALLTYPE DrawInlineObject( 317 virtual HRESULT STDMETHODCALLTYPE DrawInlineObject(
318 void* clientDrawingContext, 318 void* clientDrawingContext,
319 FLOAT originX, 319 FLOAT originX,
320 FLOAT originY, 320 FLOAT originY,
321 IDWriteInlineObject* inlineObject, 321 IDWriteInlineObject* inlineObject,
322 BOOL isSideways, 322 BOOL isSideways,
323 BOOL isRightToLeft, 323 BOOL isRightToLeft,
324 IUnknown* clientDrawingEffect) SK_OVERRIDE 324 IUnknown* clientDrawingEffect) override
325 { return E_NOTIMPL; } 325 { return E_NOTIMPL; }
326 326
327 // IDWritePixelSnapping methods 327 // IDWritePixelSnapping methods
328 virtual HRESULT STDMETHODCALLTYPE IsPixelSnappingDisabled( 328 virtual HRESULT STDMETHODCALLTYPE IsPixelSnappingDisabled(
329 void* clientDrawingContext, 329 void* clientDrawingContext,
330 BOOL* isDisabled) SK_OVERRIDE 330 BOOL* isDisabled) override
331 { 331 {
332 *isDisabled = FALSE; 332 *isDisabled = FALSE;
333 return S_OK; 333 return S_OK;
334 } 334 }
335 335
336 virtual HRESULT STDMETHODCALLTYPE GetCurrentTransform( 336 virtual HRESULT STDMETHODCALLTYPE GetCurrentTransform(
337 void* clientDrawingContext, 337 void* clientDrawingContext,
338 DWRITE_MATRIX* transform) SK_OVERRIDE 338 DWRITE_MATRIX* transform) override
339 { 339 {
340 const DWRITE_MATRIX ident = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0}; 340 const DWRITE_MATRIX ident = {1.0, 0.0, 0.0, 1.0, 0.0, 0.0};
341 *transform = ident; 341 *transform = ident;
342 return S_OK; 342 return S_OK;
343 } 343 }
344 344
345 virtual HRESULT STDMETHODCALLTYPE GetPixelsPerDip( 345 virtual HRESULT STDMETHODCALLTYPE GetPixelsPerDip(
346 void* clientDrawingContext, 346 void* clientDrawingContext,
347 FLOAT* pixelsPerDip) SK_OVERRIDE 347 FLOAT* pixelsPerDip) override
348 { 348 {
349 *pixelsPerDip = 1.0f; 349 *pixelsPerDip = 1.0f;
350 return S_OK; 350 return S_OK;
351 } 351 }
352 352
353 // IUnknown methods 353 // IUnknown methods
354 ULONG STDMETHODCALLTYPE AddRef() SK_OVERRIDE { 354 ULONG STDMETHODCALLTYPE AddRef() override {
355 return InterlockedIncrement(&fRefCount); 355 return InterlockedIncrement(&fRefCount);
356 } 356 }
357 357
358 ULONG STDMETHODCALLTYPE Release() SK_OVERRIDE { 358 ULONG STDMETHODCALLTYPE Release() override {
359 ULONG newCount = InterlockedDecrement(&fRefCount); 359 ULONG newCount = InterlockedDecrement(&fRefCount);
360 if (0 == newCount) { 360 if (0 == newCount) {
361 delete this; 361 delete this;
362 } 362 }
363 return newCount; 363 return newCount;
364 } 364 }
365 365
366 virtual HRESULT STDMETHODCALLTYPE QueryInterface( 366 virtual HRESULT STDMETHODCALLTYPE QueryInterface(
367 IID const& riid, void** ppvObject) SK_OVERRIDE 367 IID const& riid, void** ppvObject) override
368 { 368 {
369 if (__uuidof(IUnknown) == riid || 369 if (__uuidof(IUnknown) == riid ||
370 __uuidof(IDWritePixelSnapping) == riid || 370 __uuidof(IDWritePixelSnapping) == riid ||
371 __uuidof(IDWriteTextRenderer) == riid) 371 __uuidof(IDWriteTextRenderer) == riid)
372 { 372 {
373 *ppvObject = this; 373 *ppvObject = this;
374 this->AddRef(); 374 this->AddRef();
375 return S_OK; 375 return S_OK;
376 } 376 }
377 *ppvObject = NULL; 377 *ppvObject = NULL;
378 return E_FAIL; 378 return E_FAIL;
379 } 379 }
380 380
381 const SkFontIdentity FallbackIdentity() { return fIdentity; } 381 const SkFontIdentity FallbackIdentity() { return fIdentity; }
382 382
383 protected: 383 protected:
384 ULONG fRefCount; 384 ULONG fRefCount;
385 SkAutoTUnref<const SkRemotableFontMgr_DirectWrite> fOuter; 385 SkAutoTUnref<const SkRemotableFontMgr_DirectWrite> fOuter;
386 UINT32 fCharacter; 386 UINT32 fCharacter;
387 SkFontIdentity fIdentity; 387 SkFontIdentity fIdentity;
388 }; 388 };
389 389
390 virtual SkFontIdentity matchNameStyleCharacter(const char familyName[], 390 virtual SkFontIdentity matchNameStyleCharacter(const char familyName[],
391 const SkFontStyle& pattern, 391 const SkFontStyle& pattern,
392 const char* bcp47[], int bcp4 7Count, 392 const char* bcp47[], int bcp4 7Count,
393 SkUnichar character) const SK _OVERRIDE 393 SkUnichar character) const ov erride
394 { 394 {
395 SkFontIdentity identity = { SkFontIdentity::kInvalidDataId }; 395 SkFontIdentity identity = { SkFontIdentity::kInvalidDataId };
396 396
397 IDWriteFactory* dwFactory = sk_get_dwrite_factory(); 397 IDWriteFactory* dwFactory = sk_get_dwrite_factory();
398 if (NULL == dwFactory) { 398 if (NULL == dwFactory) {
399 return identity; 399 return identity;
400 } 400 }
401 401
402 // TODO: use IDWriteFactory2::GetSystemFontFallback when available. 402 // TODO: use IDWriteFactory2::GetSystemFontFallback when available.
403 403
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
445 SkTScopedComPtr<FontFallbackRenderer> fontFallbackRenderer( 445 SkTScopedComPtr<FontFallbackRenderer> fontFallbackRenderer(
446 new FontFallbackRenderer(this, character)); 446 new FontFallbackRenderer(this, character));
447 447
448 HR_GENERAL(fallbackLayout->Draw(NULL, fontFallbackRenderer.get(), 50.0f, 50.0f), 448 HR_GENERAL(fallbackLayout->Draw(NULL, fontFallbackRenderer.get(), 50.0f, 50.0f),
449 "Could not draw layout with renderer.", 449 "Could not draw layout with renderer.",
450 identity); 450 identity);
451 451
452 return fontFallbackRenderer->FallbackIdentity(); 452 return fontFallbackRenderer->FallbackIdentity();
453 } 453 }
454 454
455 SkStreamAsset* getData(int dataId) const SK_OVERRIDE { 455 SkStreamAsset* getData(int dataId) const override {
456 SkAutoMutexAcquire ama(fDataIdCacheMutex); 456 SkAutoMutexAcquire ama(fDataIdCacheMutex);
457 if (dataId >= fDataIdCache.count()) { 457 if (dataId >= fDataIdCache.count()) {
458 return NULL; 458 return NULL;
459 } 459 }
460 const DataId& id = fDataIdCache[dataId]; 460 const DataId& id = fDataIdCache[dataId];
461 461
462 SkTScopedComPtr<IDWriteFontFileLoader> loader; 462 SkTScopedComPtr<IDWriteFontFileLoader> loader;
463 HRNM(id.fLoader->QueryInterface(&loader), "QuerryInterface IDWriteFontFi leLoader failed"); 463 HRNM(id.fLoader->QueryInterface(&loader), "QuerryInterface IDWriteFontFi leLoader failed");
464 464
465 SkTScopedComPtr<IDWriteFontFileStream> fontFileStream; 465 SkTScopedComPtr<IDWriteFontFileStream> fontFileStream;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 } else { 498 } else {
499 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH); 499 localeNameLen = getUserDefaultLocaleNameProc(localeNameStorage, LOCALE_N AME_MAX_LENGTH);
500 if (localeNameLen) { 500 if (localeNameLen) {
501 localeName = localeNameStorage; 501 localeName = localeNameStorage;
502 }; 502 };
503 } 503 }
504 504
505 return SkNEW_ARGS(SkRemotableFontMgr_DirectWrite, (sysFontCollection.get(), 505 return SkNEW_ARGS(SkRemotableFontMgr_DirectWrite, (sysFontCollection.get(),
506 localeName, localeNameLen )); 506 localeName, localeNameLen ));
507 } 507 }
OLDNEW
« no previous file with comments | « src/ports/SkImageGenerator_skia.cpp ('k') | src/ports/SkScalerContext_win_dw.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698