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

Side by Side Diff: src/core/SkScalerContext.cpp

Issue 748883005: Factor text size device mapping in SkScalerContext. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comments, clarify names. Created 6 years 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
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 9
10 #include "SkScalerContext.h" 10 #include "SkScalerContext.h"
11 #include "SkColorPriv.h" 11 #include "SkColorPriv.h"
12 #include "SkDescriptor.h" 12 #include "SkDescriptor.h"
13 #include "SkDraw.h" 13 #include "SkDraw.h"
14 #include "SkFontHost.h" 14 #include "SkFontHost.h"
15 #include "SkGlyph.h" 15 #include "SkGlyph.h"
16 #include "SkMaskFilter.h" 16 #include "SkMaskFilter.h"
17 #include "SkMaskGamma.h" 17 #include "SkMaskGamma.h"
18 #include "SkMatrix22.h"
18 #include "SkReadBuffer.h" 19 #include "SkReadBuffer.h"
19 #include "SkWriteBuffer.h" 20 #include "SkWriteBuffer.h"
20 #include "SkPathEffect.h" 21 #include "SkPathEffect.h"
21 #include "SkRasterizer.h" 22 #include "SkRasterizer.h"
22 #include "SkRasterClip.h" 23 #include "SkRasterClip.h"
23 #include "SkStroke.h" 24 #include "SkStroke.h"
24 #include "SkThread.h" 25 #include "SkThread.h"
25 26
26 #define ComputeBWRowBytes(width) (((unsigned)(width) + 7) >> 3) 27 #define ComputeBWRowBytes(width) (((unsigned)(width) + 7) >> 3)
27 28
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 716
716 void SkScalerContextRec::getSingleMatrixWithoutTextSize(SkMatrix* m) const { 717 void SkScalerContextRec::getSingleMatrixWithoutTextSize(SkMatrix* m) const {
717 this->getLocalMatrixWithoutTextSize(m); 718 this->getLocalMatrixWithoutTextSize(m);
718 719
719 // now concat the device matrix 720 // now concat the device matrix
720 SkMatrix deviceMatrix; 721 SkMatrix deviceMatrix;
721 this->getMatrixFrom2x2(&deviceMatrix); 722 this->getMatrixFrom2x2(&deviceMatrix);
722 m->postConcat(deviceMatrix); 723 m->postConcat(deviceMatrix);
723 } 724 }
724 725
726 void SkScalerContextRec::computeMatrices(PreMatrixScale preMatrixScale, SkVector * s, SkMatrix* sA,
727 SkMatrix* GsA, SkMatrix* G_inv, SkMatri x* A_out)
728 {
729 // A is the 'total' matrix.
730 SkMatrix A;
731 this->getSingleMatrix(&A);
732
733 // The caller may find the 'total' matrix useful when dealing directly with EM sizes.
734 if (A_out) {
735 *A_out = A;
736 }
737
738 // GA is the matrix A with rotation removed.
739 SkMatrix GA;
740 bool skewedOrFlipped = A.getSkewX() || A.getSkewY() || A.getScaleX() < 0 || A.getScaleY() < 0;
741 if (skewedOrFlipped) {
742 // h is where A maps the horizontal baseline.
743 SkPoint h = SkPoint::Make(SK_Scalar1, 0);
744 A.mapPoints(&h, 1);
745
746 // G is the Givens Matrix for A (rotational matrix where GA[0][1] == 0).
747 SkMatrix G;
748 SkComputeGivensRotation(h, &G);
749
750 GA = G;
751 GA.preConcat(A);
752
753 // The 'remainingRotation' is G inverse, which is fairly simple since G is 2x2 rotational.
754 if (G_inv) {
755 G_inv->setAll(
756 G.get(SkMatrix::kMScaleX), -G.get(SkMatrix::kMSkewX), G.get(SkMa trix::kMTransX),
757 -G.get(SkMatrix::kMSkewY), G.get(SkMatrix::kMScaleY), G.get(SkMa trix::kMTransY),
758 G.get(SkMatrix::kMPersp0), G.get(SkMatrix::kMPersp1), G.get(SkMa trix::kMPersp2));
759 }
760 } else {
761 GA = A;
762 if (G_inv) {
763 G_inv->reset();
764 }
765 }
766
767 // At this point, given GA, create s.
768 switch (preMatrixScale) {
769 case kFull_PreMatrixScale:
770 s->fX = SkScalarAbs(GA.get(SkMatrix::kMScaleX));
771 s->fY = SkScalarAbs(GA.get(SkMatrix::kMScaleY));
772 break;
773 case kVertical_PreMatrixScale: {
774 SkScalar yScale = SkScalarAbs(GA.get(SkMatrix::kMScaleY));
775 s->fX = yScale;
776 s->fY = yScale;
777 break;
778 }
779 case kVerticalInteger_PreMatrixScale: {
780 SkScalar realYScale = SkScalarAbs(GA.get(SkMatrix::kMScaleY));
781 SkScalar intYScale = SkScalarRoundToScalar(realYScale);
782 if (intYScale == 0) {
783 intYScale = SK_Scalar1;
784 }
785 s->fX = intYScale;
786 s->fY = intYScale;
787 break;
788 }
789 }
790
791 // The 'remaining' matrix sA is the total matrix A without the scale.
792 if (!skewedOrFlipped && kFull_PreMatrixScale == preMatrixScale) {
793 // If GA == A and kFull_PreMatrixScale, sA is identity.
794 sA->reset();
795 } else {
796 // TODO: If GA == A and kVertical_PreMatrixScale, sA.scaleY is SK_Scalar 1.
797 // TODO: If GA == A and kVertical_PreMatrixScale and A.scaleX == A.scale Y, sA is identity.
798 // TODO: like kVertical_PreMatrixScale, kVerticalInteger_PreMatrixScale with int scales.
799 *sA = A;
800 sA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY));
801 }
802
803 // The 'remainingWithoutRotation' matrix GsA is the non-rotational part of A without the scale.
804 if (GsA) {
805 *GsA = GA;
806 // G is rotational so reorders with the scale.
807 GsA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY));
808 }
809 }
810
725 SkAxisAlignment SkComputeAxisAlignmentForHText(const SkMatrix& matrix) { 811 SkAxisAlignment SkComputeAxisAlignmentForHText(const SkMatrix& matrix) {
726 SkASSERT(!matrix.hasPerspective()); 812 SkASSERT(!matrix.hasPerspective());
727 813
728 if (0 == matrix[SkMatrix::kMSkewY]) { 814 if (0 == matrix[SkMatrix::kMSkewY]) {
729 return kX_SkAxisAlignment; 815 return kX_SkAxisAlignment;
730 } 816 }
731 if (0 == matrix[SkMatrix::kMScaleX]) { 817 if (0 == matrix[SkMatrix::kMScaleX]) {
732 return kY_SkAxisAlignment; 818 return kY_SkAxisAlignment;
733 } 819 }
734 return kNone_SkAxisAlignment; 820 return kNone_SkAxisAlignment;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc, 856 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc,
771 bool allowFailure) const { 857 bool allowFailure) const {
772 SkScalerContext* c = this->onCreateScalerContext(desc); 858 SkScalerContext* c = this->onCreateScalerContext(desc);
773 859
774 if (!c && !allowFailure) { 860 if (!c && !allowFailure) {
775 c = SkNEW_ARGS(SkScalerContext_Empty, 861 c = SkNEW_ARGS(SkScalerContext_Empty,
776 (const_cast<SkTypeface*>(this), desc)); 862 (const_cast<SkTypeface*>(this), desc));
777 } 863 }
778 return c; 864 return c;
779 } 865 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698