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

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

Issue 18132009: move failable work outside of constructors for SkGlyphCache and SkScalerContextGDI. If we fail, try… (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « src/core/SkGlyphCache.cpp ('k') | no next file » | 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 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 #include "SkAdvancedTypefaceMetrics.h" 9 #include "SkAdvancedTypefaceMetrics.h"
10 #include "SkBase64.h" 10 #include "SkBase64.h"
(...skipping 487 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 } 498 }
499 *srcRBPtr = srcRB; 499 *srcRBPtr = srcRB;
500 // offset to the start of the image 500 // offset to the start of the image
501 return (const char*)fBits + (fHeight - glyph.fHeight) * srcRB; 501 return (const char*)fBits + (fHeight - glyph.fHeight) * srcRB;
502 } 502 }
503 503
504 ////////////////////////////////////////////////////////////////////////////// 504 //////////////////////////////////////////////////////////////////////////////
505 505
506 class SkScalerContext_Windows : public SkScalerContext { 506 class SkScalerContext_Windows : public SkScalerContext {
507 public: 507 public:
508 SkScalerContext_Windows(SkTypeface*, const SkDescriptor* desc); 508 // we take ownership of the HDC
509 SkScalerContext_Windows(SkTypeface*, const SkDescriptor* desc, HDC);
509 virtual ~SkScalerContext_Windows(); 510 virtual ~SkScalerContext_Windows();
510 511
511 protected: 512 protected:
512 virtual unsigned generateGlyphCount() SK_OVERRIDE; 513 virtual unsigned generateGlyphCount() SK_OVERRIDE;
513 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; 514 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE;
514 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE; 515 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE;
515 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE; 516 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE;
516 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE; 517 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE;
517 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE; 518 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE;
518 virtual void generateFontMetrics(SkPaint::FontMetrics* mX, 519 virtual void generateFontMetrics(SkPaint::FontMetrics* mX,
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
565 default: 566 default:
566 if (rec.fFlags & SkScalerContext::kGenA8FromLCD_Flag) { 567 if (rec.fFlags & SkScalerContext::kGenA8FromLCD_Flag) {
567 return CLEARTYPE_QUALITY; 568 return CLEARTYPE_QUALITY;
568 } else { 569 } else {
569 return ANTIALIASED_QUALITY; 570 return ANTIALIASED_QUALITY;
570 } 571 }
571 } 572 }
572 } 573 }
573 574
574 SkScalerContext_Windows::SkScalerContext_Windows(SkTypeface* rawTypeface, 575 SkScalerContext_Windows::SkScalerContext_Windows(SkTypeface* rawTypeface,
575 const SkDescriptor* desc) 576 const SkDescriptor* desc,
577 HDC ddc)
576 : SkScalerContext(rawTypeface, desc) 578 : SkScalerContext(rawTypeface, desc)
577 , fDDC(0) 579 , fDDC(ddc)
578 , fFont(0) 580 , fFont(0)
579 , fSavefont(0) 581 , fSavefont(0)
580 , fSC(0) 582 , fSC(0)
581 , fGlyphCount(-1) 583 , fGlyphCount(-1)
582 { 584 {
585 SkASSERT(fDDC);
583 LogFontTypeface* typeface = reinterpret_cast<LogFontTypeface*>(rawTypeface); 586 LogFontTypeface* typeface = reinterpret_cast<LogFontTypeface*>(rawTypeface);
584 587
585 fDDC = ::CreateCompatibleDC(NULL);
586 SetGraphicsMode(fDDC, GM_ADVANCED); 588 SetGraphicsMode(fDDC, GM_ADVANCED);
587 SetBkMode(fDDC, TRANSPARENT); 589 SetBkMode(fDDC, TRANSPARENT);
588 590
589 // Scaling by the DPI is inconsistent with how Skia draws elsewhere 591 // Scaling by the DPI is inconsistent with how Skia draws elsewhere
590 //SkScalar height = -(fRec.fTextSize * GetDeviceCaps(ddc, LOGPIXELSY) / 72); 592 //SkScalar height = -(fRec.fTextSize * GetDeviceCaps(ddc, LOGPIXELSY) / 72);
591 LOGFONT lf = typeface->fLogFont; 593 LOGFONT lf = typeface->fLogFont;
592 lf.lfHeight = -gCanonicalTextSize; 594 lf.lfHeight = -gCanonicalTextSize;
593 lf.lfQuality = compute_quality(fRec); 595 lf.lfQuality = compute_quality(fRec);
594 fFont = CreateFontIndirect(&lf); 596 fFont = CreateFontIndirect(&lf);
bungeman-skia 2013/07/08 19:36:49 This line also creates a handle, we should also be
595 597
596 // if we're rotated, or want fractional widths, create a hires font 598 // if we're rotated, or want fractional widths, create a hires font
597 fHiResFont = 0; 599 fHiResFont = 0;
598 if (needHiResMetrics(fRec.fPost2x2)) { 600 if (needHiResMetrics(fRec.fPost2x2)) {
599 lf.lfHeight = -HIRES_TEXTSIZE; 601 lf.lfHeight = -HIRES_TEXTSIZE;
600 fHiResFont = CreateFontIndirect(&lf); 602 fHiResFont = CreateFontIndirect(&lf);
601 603
602 fMat22Identity.eM11 = fMat22Identity.eM22 = SkFixedToFIXED(SK_Fixed1); 604 fMat22Identity.eM11 = fMat22Identity.eM22 = SkFixedToFIXED(SK_Fixed1);
603 fMat22Identity.eM12 = fMat22Identity.eM21 = SkFixedToFIXED(0); 605 fMat22Identity.eM12 = fMat22Identity.eM21 = SkFixedToFIXED(0);
604 606
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
680 call_ensure_accessible(lf); 682 call_ensure_accessible(lf);
681 //if the following fails, we'll just draw at gCanonicalTextSize. 683 //if the following fails, we'll just draw at gCanonicalTextSize.
682 GetTextMetrics(fDDC, &fTM); 684 GetTextMetrics(fDDC, &fTM);
683 } 685 }
684 } 686 }
685 687
686 fOffscreen.init(fFont, xform); 688 fOffscreen.init(fFont, xform);
687 } 689 }
688 690
689 SkScalerContext_Windows::~SkScalerContext_Windows() { 691 SkScalerContext_Windows::~SkScalerContext_Windows() {
690 if (fDDC) { 692 ::SelectObject(fDDC, fSavefont);
691 ::SelectObject(fDDC, fSavefont); 693 ::DeleteDC(fDDC);
692 ::DeleteDC(fDDC); 694
693 }
694 if (fFont) { 695 if (fFont) {
695 ::DeleteObject(fFont); 696 ::DeleteObject(fFont);
696 } 697 }
697 if (fHiResFont) { 698 if (fHiResFont) {
698 ::DeleteObject(fHiResFont); 699 ::DeleteObject(fHiResFont);
699 } 700 }
700 if (fSC) { 701 if (fSC) {
701 ::ScriptFreeCache(&fSC); 702 ::ScriptFreeCache(&fSC);
702 } 703 }
703 } 704 }
(...skipping 954 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 } 1659 }
1659 1660
1660 SelectObject(hdc, savefont); 1661 SelectObject(hdc, savefont);
1661 DeleteObject(font); 1662 DeleteObject(font);
1662 DeleteDC(hdc); 1663 DeleteDC(hdc);
1663 1664
1664 return stream; 1665 return stream;
1665 } 1666 }
1666 1667
1667 SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc ) const { 1668 SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc ) const {
1668 return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<LogFontTypeface*>(thi s), desc)); 1669 HDC hdc = ::CreateCompatibleDC(NULL);
1670 if (!hdc) {
1671 return NULL;
1672 }
1673 return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<LogFontTypeface*>(thi s), desc, hdc));
1669 } 1674 }
1670 1675
1671 /** Return the closest matching typeface given either an existing family 1676 /** Return the closest matching typeface given either an existing family
1672 (specified by a typeface in that family) or by a familyName, and a 1677 (specified by a typeface in that family) or by a familyName, and a
1673 requested style. 1678 requested style.
1674 1) If familyFace is null, use familyName. 1679 1) If familyFace is null, use familyName.
1675 2) If familyName is null, use familyFace. 1680 2) If familyName is null, use familyFace.
1676 3) If both are null, return the default font that best matches style 1681 3) If both are null, return the default font that best matches style
1677 This MUST not return NULL. 1682 This MUST not return NULL.
1678 */ 1683 */
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
1918 return this->createFromStream(stream); 1923 return this->createFromStream(stream);
1919 } 1924 }
1920 1925
1921 private: 1926 private:
1922 SkTDArray<ENUMLOGFONTEX> fLogFontArray; 1927 SkTDArray<ENUMLOGFONTEX> fLogFontArray;
1923 }; 1928 };
1924 1929
1925 SkFontMgr* SkFontMgr::Factory() { 1930 SkFontMgr* SkFontMgr::Factory() {
1926 return SkNEW(SkFontMgrGDI); 1931 return SkNEW(SkFontMgrGDI);
1927 } 1932 }
OLDNEW
« no previous file with comments | « src/core/SkGlyphCache.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698