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 * SK_ScalarNearlyZero || |
| 747 diag[1].lengthSqd() <= SK_ScalarNearlyZero * SK_ScalarNearlyZero) |
| 748 { |
| 749 s->fX = SK_Scalar1; |
| 750 s->fY = SK_Scalar1; |
| 751 sA->setScale(0, 0); |
| 752 if (GsA) { |
| 753 GsA->setScale(0, 0); |
| 754 } |
| 755 if (G_inv) { |
| 756 G_inv->reset(); |
| 757 } |
| 758 return; |
| 759 } |
| 760 |
738 // GA is the matrix A with rotation removed. | 761 // GA is the matrix A with rotation removed. |
739 SkMatrix GA; | 762 SkMatrix GA; |
740 bool skewedOrFlipped = A.getSkewX() || A.getSkewY() || A.getScaleX() < 0 ||
A.getScaleY() < 0; | 763 bool skewedOrFlipped = A.getSkewX() || A.getSkewY() || A.getScaleX() < 0 ||
A.getScaleY() < 0; |
741 if (skewedOrFlipped) { | 764 if (skewedOrFlipped) { |
742 // h is where A maps the horizontal baseline. | 765 // h is where A maps the horizontal baseline. |
743 SkPoint h = SkPoint::Make(SK_Scalar1, 0); | 766 SkPoint h = SkPoint::Make(SK_Scalar1, 0); |
744 A.mapPoints(&h, 1); | 767 A.mapPoints(&h, 1); |
745 | 768 |
746 // G is the Givens Matrix for A (rotational matrix where GA[0][1] == 0). | 769 // G is the Givens Matrix for A (rotational matrix where GA[0][1] == 0). |
747 SkMatrix G; | 770 SkMatrix G; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
782 if (intYScale == 0) { | 805 if (intYScale == 0) { |
783 intYScale = SK_Scalar1; | 806 intYScale = SK_Scalar1; |
784 } | 807 } |
785 s->fX = intYScale; | 808 s->fX = intYScale; |
786 s->fY = intYScale; | 809 s->fY = intYScale; |
787 break; | 810 break; |
788 } | 811 } |
789 } | 812 } |
790 | 813 |
791 // The 'remaining' matrix sA is the total matrix A without the scale. | 814 // The 'remaining' matrix sA is the total matrix A without the scale. |
792 if (!skewedOrFlipped && kFull_PreMatrixScale == preMatrixScale) { | 815 if (!skewedOrFlipped && ( |
| 816 (kFull_PreMatrixScale == preMatrixScale) || |
| 817 (kVertical_PreMatrixScale == preMatrixScale && A.getScaleX() == A.ge
tScaleY()))) |
| 818 { |
793 // If GA == A and kFull_PreMatrixScale, sA is identity. | 819 // If GA == A and kFull_PreMatrixScale, sA is identity. |
| 820 // If GA == A and kVertical_PreMatrixScale and A.scaleX == A.scaleY, sA
is identity. |
794 sA->reset(); | 821 sA->reset(); |
| 822 } else if (!skewedOrFlipped && kVertical_PreMatrixScale == preMatrixScale) { |
| 823 // If GA == A and kVertical_PreMatrixScale, sA.scaleY is SK_Scalar1. |
| 824 sA->reset(); |
| 825 sA->setScaleX(A.getScaleX() / s->fY); |
795 } else { | 826 } 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. | 827 // TODO: like kVertical_PreMatrixScale, kVerticalInteger_PreMatrixScale
with int scales. |
799 *sA = A; | 828 *sA = A; |
800 sA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY)); | 829 sA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY)); |
801 } | 830 } |
802 | 831 |
803 // The 'remainingWithoutRotation' matrix GsA is the non-rotational part of A
without the scale. | 832 // The 'remainingWithoutRotation' matrix GsA is the non-rotational part of A
without the scale. |
804 if (GsA) { | 833 if (GsA) { |
805 *GsA = GA; | 834 *GsA = GA; |
806 // G is rotational so reorders with the scale. | 835 // G is rotational so reorders with the scale. |
807 GsA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY)); | 836 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, | 885 SkScalerContext* SkTypeface::createScalerContext(const SkDescriptor* desc, |
857 bool allowFailure) const { | 886 bool allowFailure) const { |
858 SkScalerContext* c = this->onCreateScalerContext(desc); | 887 SkScalerContext* c = this->onCreateScalerContext(desc); |
859 | 888 |
860 if (!c && !allowFailure) { | 889 if (!c && !allowFailure) { |
861 c = SkNEW_ARGS(SkScalerContext_Empty, | 890 c = SkNEW_ARGS(SkScalerContext_Empty, |
862 (const_cast<SkTypeface*>(this), desc)); | 891 (const_cast<SkTypeface*>(this), desc)); |
863 } | 892 } |
864 return c; | 893 return c; |
865 } | 894 } |
OLD | NEW |