| OLD | NEW |
| 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 490 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 SkScalerContext_Windows(SkTypeface*, const SkDescriptor* desc); |
| 509 virtual ~SkScalerContext_Windows(); | 509 virtual ~SkScalerContext_Windows(); |
| 510 | 510 |
| 511 // Returns true if the constructor was able to complete all of its |
| 512 // initializations (which may include calling GDI). |
| 513 bool isValid() const; |
| 514 |
| 511 protected: | 515 protected: |
| 512 virtual unsigned generateGlyphCount() SK_OVERRIDE; | 516 virtual unsigned generateGlyphCount() SK_OVERRIDE; |
| 513 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; | 517 virtual uint16_t generateCharToGlyph(SkUnichar uni) SK_OVERRIDE; |
| 514 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE; | 518 virtual void generateAdvance(SkGlyph* glyph) SK_OVERRIDE; |
| 515 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE; | 519 virtual void generateMetrics(SkGlyph* glyph) SK_OVERRIDE; |
| 516 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE; | 520 virtual void generateImage(const SkGlyph& glyph) SK_OVERRIDE; |
| 517 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE; | 521 virtual void generatePath(const SkGlyph& glyph, SkPath* path) SK_OVERRIDE; |
| 518 virtual void generateFontMetrics(SkPaint::FontMetrics* mX, | 522 virtual void generateFontMetrics(SkPaint::FontMetrics* mX, |
| 519 SkPaint::FontMetrics* mY) SK_OVERRIDE; | 523 SkPaint::FontMetrics* mY) SK_OVERRIDE; |
| 520 | 524 |
| 521 private: | 525 private: |
| 522 HDCOffscreen fOffscreen; | 526 HDCOffscreen fOffscreen; |
| 523 SkScalar fScale; // to get from canonical size to real size | 527 SkScalar fScale; // to get from canonical size to real size |
| 524 MAT2 fMat22; | 528 MAT2 fMat22; |
| 525 HDC fDDC; | 529 HDC fDDC; |
| 526 HFONT fSavefont; | 530 HFONT fSavefont; |
| 527 HFONT fFont; | 531 HFONT fFont; |
| 532 HFONT fHiResFont; |
| 528 SCRIPT_CACHE fSC; | 533 SCRIPT_CACHE fSC; |
| 529 int fGlyphCount; | 534 int fGlyphCount; |
| 530 | 535 |
| 531 HFONT fHiResFont; | |
| 532 MAT2 fMat22Identity; | 536 MAT2 fMat22Identity; |
| 533 SkMatrix fHiResMatrix; | 537 SkMatrix fHiResMatrix; |
| 534 enum Type { | 538 enum Type { |
| 535 kTrueType_Type, kBitmap_Type, | 539 kTrueType_Type, kBitmap_Type, |
| 536 } fType; | 540 } fType; |
| 537 TEXTMETRIC fTM; | 541 TEXTMETRIC fTM; |
| 538 }; | 542 }; |
| 539 | 543 |
| 540 static float mul2float(SkScalar a, SkScalar b) { | 544 static float mul2float(SkScalar a, SkScalar b) { |
| 541 return SkScalarToFloat(SkScalarMul(a, b)); | 545 return SkScalarToFloat(SkScalarMul(a, b)); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 568 } else { | 572 } else { |
| 569 return ANTIALIASED_QUALITY; | 573 return ANTIALIASED_QUALITY; |
| 570 } | 574 } |
| 571 } | 575 } |
| 572 } | 576 } |
| 573 | 577 |
| 574 SkScalerContext_Windows::SkScalerContext_Windows(SkTypeface* rawTypeface, | 578 SkScalerContext_Windows::SkScalerContext_Windows(SkTypeface* rawTypeface, |
| 575 const SkDescriptor* desc) | 579 const SkDescriptor* desc) |
| 576 : SkScalerContext(rawTypeface, desc) | 580 : SkScalerContext(rawTypeface, desc) |
| 577 , fDDC(0) | 581 , fDDC(0) |
| 582 , fSavefont(0) |
| 578 , fFont(0) | 583 , fFont(0) |
| 579 , fSavefont(0) | 584 , fHiResFont(0) |
| 580 , fSC(0) | 585 , fSC(0) |
| 581 , fGlyphCount(-1) | 586 , fGlyphCount(-1) |
| 582 { | 587 { |
| 583 LogFontTypeface* typeface = reinterpret_cast<LogFontTypeface*>(rawTypeface); | 588 LogFontTypeface* typeface = reinterpret_cast<LogFontTypeface*>(rawTypeface); |
| 584 | 589 |
| 585 fDDC = ::CreateCompatibleDC(NULL); | 590 fDDC = ::CreateCompatibleDC(NULL); |
| 591 if (!fDDC) { |
| 592 return; |
| 593 } |
| 594 |
| 586 SetGraphicsMode(fDDC, GM_ADVANCED); | 595 SetGraphicsMode(fDDC, GM_ADVANCED); |
| 587 SetBkMode(fDDC, TRANSPARENT); | 596 SetBkMode(fDDC, TRANSPARENT); |
| 588 | 597 |
| 589 // Scaling by the DPI is inconsistent with how Skia draws elsewhere | 598 // Scaling by the DPI is inconsistent with how Skia draws elsewhere |
| 590 //SkScalar height = -(fRec.fTextSize * GetDeviceCaps(ddc, LOGPIXELSY) / 72); | 599 //SkScalar height = -(fRec.fTextSize * GetDeviceCaps(ddc, LOGPIXELSY) / 72); |
| 591 LOGFONT lf = typeface->fLogFont; | 600 LOGFONT lf = typeface->fLogFont; |
| 592 lf.lfHeight = -gCanonicalTextSize; | 601 lf.lfHeight = -gCanonicalTextSize; |
| 593 lf.lfQuality = compute_quality(fRec); | 602 lf.lfQuality = compute_quality(fRec); |
| 594 fFont = CreateFontIndirect(&lf); | 603 fFont = CreateFontIndirect(&lf); |
| 604 if (!fFont) { |
| 605 return; |
| 606 } |
| 595 | 607 |
| 596 // if we're rotated, or want fractional widths, create a hires font | 608 // if we're rotated, or want fractional widths, create a hires font |
| 597 fHiResFont = 0; | |
| 598 if (needHiResMetrics(fRec.fPost2x2)) { | 609 if (needHiResMetrics(fRec.fPost2x2)) { |
| 599 lf.lfHeight = -HIRES_TEXTSIZE; | 610 lf.lfHeight = -HIRES_TEXTSIZE; |
| 600 fHiResFont = CreateFontIndirect(&lf); | 611 fHiResFont = CreateFontIndirect(&lf); |
| 612 if (!fHiResFont) { |
| 613 return; |
| 614 } |
| 601 | 615 |
| 602 fMat22Identity.eM11 = fMat22Identity.eM22 = SkFixedToFIXED(SK_Fixed1); | 616 fMat22Identity.eM11 = fMat22Identity.eM22 = SkFixedToFIXED(SK_Fixed1); |
| 603 fMat22Identity.eM12 = fMat22Identity.eM21 = SkFixedToFIXED(0); | 617 fMat22Identity.eM12 = fMat22Identity.eM21 = SkFixedToFIXED(0); |
| 604 | 618 |
| 605 // construct a matrix to go from HIRES logical units to our device units | 619 // construct a matrix to go from HIRES logical units to our device units |
| 606 fRec.getSingleMatrix(&fHiResMatrix); | 620 fRec.getSingleMatrix(&fHiResMatrix); |
| 607 SkScalar scale = SkScalarInvert(SkIntToScalar(HIRES_TEXTSIZE)); | 621 SkScalar scale = SkScalarInvert(SkIntToScalar(HIRES_TEXTSIZE)); |
| 608 fHiResMatrix.preScale(scale, scale); | 622 fHiResMatrix.preScale(scale, scale); |
| 609 } | 623 } |
| 610 fSavefont = (HFONT)SelectObject(fDDC, fFont); | 624 fSavefont = (HFONT)SelectObject(fDDC, fFont); |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 695 ::DeleteObject(fFont); | 709 ::DeleteObject(fFont); |
| 696 } | 710 } |
| 697 if (fHiResFont) { | 711 if (fHiResFont) { |
| 698 ::DeleteObject(fHiResFont); | 712 ::DeleteObject(fHiResFont); |
| 699 } | 713 } |
| 700 if (fSC) { | 714 if (fSC) { |
| 701 ::ScriptFreeCache(&fSC); | 715 ::ScriptFreeCache(&fSC); |
| 702 } | 716 } |
| 703 } | 717 } |
| 704 | 718 |
| 719 bool SkScalerContext_Windows::isValid() const { |
| 720 return fDDC && fFont; |
| 721 } |
| 722 |
| 705 unsigned SkScalerContext_Windows::generateGlyphCount() { | 723 unsigned SkScalerContext_Windows::generateGlyphCount() { |
| 706 if (fGlyphCount < 0) { | 724 if (fGlyphCount < 0) { |
| 707 if (fType == SkScalerContext_Windows::kBitmap_Type) { | 725 if (fType == SkScalerContext_Windows::kBitmap_Type) { |
| 708 return fTM.tmLastChar; | 726 return fTM.tmLastChar; |
| 709 } | 727 } |
| 710 fGlyphCount = calculateOutlineGlyphCount(fDDC); | 728 fGlyphCount = calculateOutlineGlyphCount(fDDC); |
| 711 } | 729 } |
| 712 return fGlyphCount; | 730 return fGlyphCount; |
| 713 } | 731 } |
| 714 | 732 |
| (...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1658 } | 1676 } |
| 1659 | 1677 |
| 1660 SelectObject(hdc, savefont); | 1678 SelectObject(hdc, savefont); |
| 1661 DeleteObject(font); | 1679 DeleteObject(font); |
| 1662 DeleteDC(hdc); | 1680 DeleteDC(hdc); |
| 1663 | 1681 |
| 1664 return stream; | 1682 return stream; |
| 1665 } | 1683 } |
| 1666 | 1684 |
| 1667 SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc
) const { | 1685 SkScalerContext* LogFontTypeface::onCreateScalerContext(const SkDescriptor* desc
) const { |
| 1668 return SkNEW_ARGS(SkScalerContext_Windows, (const_cast<LogFontTypeface*>(thi
s), desc)); | 1686 SkScalerContext_Windows* ctx = SkNEW_ARGS(SkScalerContext_Windows, |
| 1687 (const_cast<LogFontTypeface*>(th
is), desc)); |
| 1688 if (!ctx->isValid()) { |
| 1689 SkDELETE(ctx); |
| 1690 ctx = NULL; |
| 1691 } |
| 1692 return ctx; |
| 1669 } | 1693 } |
| 1670 | 1694 |
| 1671 /** Return the closest matching typeface given either an existing family | 1695 /** Return the closest matching typeface given either an existing family |
| 1672 (specified by a typeface in that family) or by a familyName, and a | 1696 (specified by a typeface in that family) or by a familyName, and a |
| 1673 requested style. | 1697 requested style. |
| 1674 1) If familyFace is null, use familyName. | 1698 1) If familyFace is null, use familyName. |
| 1675 2) If familyName is null, use familyFace. | 1699 2) If familyName is null, use familyFace. |
| 1676 3) If both are null, return the default font that best matches style | 1700 3) If both are null, return the default font that best matches style |
| 1677 This MUST not return NULL. | 1701 This MUST not return NULL. |
| 1678 */ | 1702 */ |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1918 return this->createFromStream(stream); | 1942 return this->createFromStream(stream); |
| 1919 } | 1943 } |
| 1920 | 1944 |
| 1921 private: | 1945 private: |
| 1922 SkTDArray<ENUMLOGFONTEX> fLogFontArray; | 1946 SkTDArray<ENUMLOGFONTEX> fLogFontArray; |
| 1923 }; | 1947 }; |
| 1924 | 1948 |
| 1925 SkFontMgr* SkFontMgr::Factory() { | 1949 SkFontMgr* SkFontMgr::Factory() { |
| 1926 return SkNEW(SkFontMgrGDI); | 1950 return SkNEW(SkFontMgrGDI); |
| 1927 } | 1951 } |
| OLD | NEW |