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 | 9 |
10 #include "SkScalerContext.h" | 10 #include "SkScalerContext.h" |
(...skipping 717 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 { | 728 { |
729 // A is the 'total' matrix. | 729 // A is the 'total' matrix. |
730 SkMatrix A; | 730 SkMatrix A; |
731 this->getSingleMatrix(&A); | 731 this->getSingleMatrix(&A); |
732 | 732 |
733 // The caller may find the 'total' matrix useful when dealing directly with EM sizes. | 733 // The caller may find the 'total' matrix useful when dealing directly with EM sizes. |
734 if (A_out) { | 734 if (A_out) { |
735 *A_out = A; | 735 *A_out = A; |
736 } | 736 } |
737 | 737 |
738 // If the 'total' matrix is singular, set the 'scale' to something finite an d zero the matrices. | |
739 // All underlying ports have issues with zero text size, so use the matricie s to zero. | |
740 | |
741 // Map the vectors [1,1] and [1,-1] (the EM) through the 'total' matrix. | |
742 // If the length of one of these vectors is less than 1/256 then an EM filli ng square will | |
743 // never affect any pixels. | |
744 SkVector diag[2] = { { A.getScaleX() + A.getSkewX(), A.getScaleY() + A.getSk ewY() }, | |
745 { A.getScaleX() - A.getSkewX(), A.getScaleY() - A.getSk ewY() }, }; | |
746 if (diag[0].lengthSqd() < SK_ScalarNearlyZero || diag[1].lengthSqd() < SK_Sc alarNearlyZero) { | |
reed1
2014/12/10 16:45:16
1. most often when we look at len^2, we compare it
bungeman-skia
2014/12/10 17:06:16
Done and done.
| |
747 s->fX = SK_Scalar1; | |
748 s->fY = SK_Scalar1; | |
749 sA->setScale(0, 0); | |
750 if (GsA) { | |
751 GsA->setScale(0, 0); | |
752 } | |
753 if (G_inv) { | |
754 G_inv->reset(); | |
755 } | |
756 return; | |
757 } | |
758 | |
738 // GA is the matrix A with rotation removed. | 759 // GA is the matrix A with rotation removed. |
739 SkMatrix GA; | 760 SkMatrix GA; |
740 bool skewedOrFlipped = A.getSkewX() || A.getSkewY() || A.getScaleX() < 0 || A.getScaleY() < 0; | 761 bool skewedOrFlipped = A.getSkewX() || A.getSkewY() || A.getScaleX() < 0 || A.getScaleY() < 0; |
741 if (skewedOrFlipped) { | 762 if (skewedOrFlipped) { |
742 // h is where A maps the horizontal baseline. | 763 // h is where A maps the horizontal baseline. |
743 SkPoint h = SkPoint::Make(SK_Scalar1, 0); | 764 SkPoint h = SkPoint::Make(SK_Scalar1, 0); |
744 A.mapPoints(&h, 1); | 765 A.mapPoints(&h, 1); |
745 | 766 |
746 // G is the Givens Matrix for A (rotational matrix where GA[0][1] == 0). | 767 // G is the Givens Matrix for A (rotational matrix where GA[0][1] == 0). |
747 SkMatrix G; | 768 SkMatrix G; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
782 if (intYScale == 0) { | 803 if (intYScale == 0) { |
783 intYScale = SK_Scalar1; | 804 intYScale = SK_Scalar1; |
784 } | 805 } |
785 s->fX = intYScale; | 806 s->fX = intYScale; |
786 s->fY = intYScale; | 807 s->fY = intYScale; |
787 break; | 808 break; |
788 } | 809 } |
789 } | 810 } |
790 | 811 |
791 // The 'remaining' matrix sA is the total matrix A without the scale. | 812 // The 'remaining' matrix sA is the total matrix A without the scale. |
792 if (!skewedOrFlipped && kFull_PreMatrixScale == preMatrixScale) { | 813 if (!skewedOrFlipped && ( |
814 (kFull_PreMatrixScale == preMatrixScale) || | |
815 (kVertical_PreMatrixScale == preMatrixScale && A.getScaleX() == A.ge tScaleY()))) | |
816 { | |
793 // If GA == A and kFull_PreMatrixScale, sA is identity. | 817 // If GA == A and kFull_PreMatrixScale, sA is identity. |
818 // If GA == A and kVertical_PreMatrixScale and A.scaleX == A.scaleY, sA is identity. | |
794 sA->reset(); | 819 sA->reset(); |
820 } else if (!skewedOrFlipped && kVertical_PreMatrixScale == preMatrixScale) { | |
821 // If GA == A and kVertical_PreMatrixScale, sA.scaleY is SK_Scalar1. | |
822 sA->reset(); | |
823 sA->setScaleX(A.getScaleX() / s->fY); | |
795 } else { | 824 } 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. | 825 // TODO: like kVertical_PreMatrixScale, kVerticalInteger_PreMatrixScale with int scales. |
799 *sA = A; | 826 *sA = A; |
800 sA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY)); | 827 sA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY)); |
801 } | 828 } |
802 | 829 |
803 // The 'remainingWithoutRotation' matrix GsA is the non-rotational part of A without the scale. | 830 // The 'remainingWithoutRotation' matrix GsA is the non-rotational part of A without the scale. |
804 if (GsA) { | 831 if (GsA) { |
805 *GsA = GA; | 832 *GsA = GA; |
806 // G is rotational so reorders with the scale. | 833 // G is rotational so reorders with the scale. |
807 GsA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY)); | 834 GsA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY)); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
856 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc, | 883 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc, |
857 bool allowFailure) const { | 884 bool allowFailure) const { |
858 SkScalerContext* c = this->onCreateScalerContext(desc); | 885 SkScalerContext* c = this->onCreateScalerContext(desc); |
859 | 886 |
860 if (!c && !allowFailure) { | 887 if (!c && !allowFailure) { |
861 c = SkNEW_ARGS(SkScalerContext_Empty, | 888 c = SkNEW_ARGS(SkScalerContext_Empty, |
862 (const_cast<SkTypeface*>(this), desc)); | 889 (const_cast<SkTypeface*>(this), desc)); |
863 } | 890 } |
864 return c; | 891 return c; |
865 } | 892 } |
OLD | NEW |