Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | Friends | List of all members
SkScalerContextRec Struct Reference

#include <SkScalerContext.h>

Public Types

enum class  PreMatrixScale { kFull , kVertical , kVerticalInteger }
 

Public Member Functions

SkScalar getDeviceGamma () const
 
void setDeviceGamma (SkScalar dg)
 
SkScalar getPaintGamma () const
 
void setPaintGamma (SkScalar pg)
 
SkScalar getContrast () const
 
void setContrast (SkScalar c)
 
void ignoreGamma ()
 
void ignorePreBlend ()
 
SkString dump () const
 
void getMatrixFrom2x2 (SkMatrix *) const
 
void getLocalMatrix (SkMatrix *) const
 
void getSingleMatrix (SkMatrix *) const
 
bool computeMatrices (PreMatrixScale preMatrixScale, SkVector *scale, SkMatrix *remaining, SkMatrix *remainingWithoutRotation=nullptr, SkMatrix *remainingRotation=nullptr, SkMatrix *total=nullptr)
 
SkAxisAlignment computeAxisAlignmentForHText () const
 
SkFontHinting getHinting () const
 
void setHinting (SkFontHinting)
 
SkMask::Format getFormat () const
 
SkColor getLuminanceColor () const
 
void setLuminanceColor (SkColor c)
 

Public Attributes

SkTypefaceID fTypefaceID
 
SkScalar fTextSize
 
SkScalar fPreScaleX
 
SkScalar fPreSkewX
 
SkScalar fPost2x2 [2][2]
 
SkScalar fFrameWidth
 
SkScalar fMiterLimit
 
uint32_t fForegroundColor {SK_ColorBLACK}
 
SkMask::Format fMaskFormat
 
uint16_t fFlags
 

Friends

class SkScalerContext
 

Detailed Description

Definition at line 61 of file SkScalerContext.h.

Member Enumeration Documentation

◆ PreMatrixScale

The kind of scale which will be applied by the underlying port (pre-matrix).

Enumerator
kFull 
kVertical 
kVerticalInteger 

Definition at line 162 of file SkScalerContext.h.

162 {
163 kFull, // The underlying port can apply both x and y scale.
164 kVertical, // The underlying port can only apply a y scale.
165 kVerticalInteger // The underlying port can only apply an integer y scale.
166 };

Member Function Documentation

◆ computeAxisAlignmentForHText()

SkAxisAlignment SkScalerContextRec::computeAxisAlignmentForHText ( ) const

Definition at line 973 of file SkScalerContext.cpp.

973 {
974 // Why fPost2x2 can be used here.
975 // getSingleMatrix multiplies in getLocalMatrix, which consists of
976 // * fTextSize (a scale, which has no effect)
977 // * fPreScaleX (a scale in x, which has no effect)
978 // * fPreSkewX (has no effect, but would on vertical text alignment).
979 // In other words, making the text bigger, stretching it along the
980 // horizontal axis, or fake italicizing it does not move the baseline.
983 }
984
985 if (0 == fPost2x2[1][0]) {
986 // The x axis is mapped onto the x axis.
987 return SkAxisAlignment::kX;
988 }
989 if (0 == fPost2x2[0][0]) {
990 // The x axis is mapped onto the y axis.
991 return SkAxisAlignment::kY;
992 }
994}
static constexpr bool SkToBool(const T &x)
Definition SkTo.h:35
SkScalar fPost2x2[2][2]

◆ computeMatrices()

bool SkScalerContextRec::computeMatrices ( PreMatrixScale  preMatrixScale,
SkVector scale,
SkMatrix remaining,
SkMatrix remainingWithoutRotation = nullptr,
SkMatrix remainingRotation = nullptr,
SkMatrix total = nullptr 
)

Compute useful matrices for use with sizing in underlying libraries.

There are two kinds of text size, a 'requested/logical size' which is like asking for size '12' and a 'real' size which is the size after the matrix is applied. The matrices produced by this method are based on the 'real' size. This method effectively finds the total device matrix and decomposes it in various ways.

The most useful decomposition is into 'scale' and 'remaining'. The 'scale' is applied first and then the 'remaining' to fully apply the total matrix. This decomposition is useful when the text size ('scale') may have meaning apart from the total matrix. This is true when hinting, and sometimes true for other properties as well.

The second (optional) decomposition is of 'remaining' into a non-rotational part 'remainingWithoutRotation' and a rotational part 'remainingRotation'. The 'scale' is applied first, then 'remainingWithoutRotation', then 'remainingRotation' to fully apply the total matrix. This decomposition is helpful when only horizontal metrics can be trusted, so the 'scale' and 'remainingWithoutRotation' will be handled by the underlying library, but the final rotation 'remainingRotation' will be handled manually.

The 'total' matrix is also (optionally) available. This is useful in cases where the underlying library will not be used, often when working directly with font data.

The parameters 'scale' and 'remaining' are required, the other pointers may be nullptr.

Parameters
preMatrixScalethe kind of scale to extract from the total matrix.
scalethe scale extracted from the total matrix (both values positive).
remainingapply after scale to apply the total matrix.
remainingWithoutRotationapply after scale to apply the total matrix sans rotation.
remainingRotationapply after remainingWithoutRotation to apply the total matrix.
totalthe total matrix.
Returns
false if the matrix was singular. The output will be valid but not invertible.

Definition at line 854 of file SkScalerContext.cpp.

856{
857 // A is the 'total' matrix.
858 SkMatrix A;
859 this->getSingleMatrix(&A);
860
861 // The caller may find the 'total' matrix useful when dealing directly with EM sizes.
862 if (A_out) {
863 *A_out = A;
864 }
865
866 // GA is the matrix A with rotation removed.
867 SkMatrix GA;
868 bool skewedOrFlipped = A.getSkewX() || A.getSkewY() || A.getScaleX() < 0 || A.getScaleY() < 0;
869 if (skewedOrFlipped) {
870 // QR by Givens rotations. G is Q^T and GA is R. G is rotational (no reflections).
871 // h is where A maps the horizontal baseline.
873 A.mapPoints(&h, 1);
874
875 // G is the Givens Matrix for A (rotational matrix where GA[0][1] == 0).
876 SkMatrix G;
878
879 GA = G;
880 GA.preConcat(A);
881
882 // The 'remainingRotation' is G inverse, which is fairly simple since G is 2x2 rotational.
883 if (G_inv) {
884 G_inv->setAll(
888 }
889 } else {
890 GA = A;
891 if (G_inv) {
892 G_inv->reset();
893 }
894 }
895
896 // If the 'total' matrix is singular, set the 'scale' to something finite and zero the matrices.
897 // All underlying ports have issues with zero text size, so use the matricies to zero.
898 // If one of the scale factors is less than 1/256 then an EM filling square will
899 // never affect any pixels.
900 // If there are any nonfinite numbers in the matrix, bail out and set the matrices to zero.
903 !GA.isFinite())
904 {
905 s->fX = SK_Scalar1;
906 s->fY = SK_Scalar1;
907 sA->setScale(0, 0);
908 if (GsA) {
909 GsA->setScale(0, 0);
910 }
911 if (G_inv) {
912 G_inv->reset();
913 }
914 return false;
915 }
916
917 // At this point, given GA, create s.
918 switch (preMatrixScale) {
922 break;
925 s->fX = yScale;
926 s->fY = yScale;
927 break;
928 }
930 SkScalar realYScale = SkScalarAbs(GA.get(SkMatrix::kMScaleY));
931 SkScalar intYScale = SkScalarRoundToScalar(realYScale);
932 if (intYScale == 0) {
933 intYScale = SK_Scalar1;
934 }
935 s->fX = intYScale;
936 s->fY = intYScale;
937 break;
938 }
939 }
940
941 // The 'remaining' matrix sA is the total matrix A without the scale.
942 if (!skewedOrFlipped && (
943 (PreMatrixScale::kFull == preMatrixScale) ||
944 (PreMatrixScale::kVertical == preMatrixScale && A.getScaleX() == A.getScaleY())))
945 {
946 // If GA == A and kFull, sA is identity.
947 // If GA == A and kVertical and A.scaleX == A.scaleY, sA is identity.
948 sA->reset();
949 } else if (!skewedOrFlipped && PreMatrixScale::kVertical == preMatrixScale) {
950 // If GA == A and kVertical, sA.scaleY is SK_Scalar1.
951 sA->reset();
952 sA->setScaleX(A.getScaleX() / s->fY);
953 } else {
954 // TODO: like kVertical, kVerticalInteger with int scales.
955 *sA = A;
956 sA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY));
957 }
958
959 // The 'remainingWithoutRotation' matrix GsA is the non-rotational part of A without the scale.
960 if (GsA) {
961 *GsA = GA;
962 // G is rotational so reorders with the scale.
963 GsA->preScale(SkScalarInvert(s->fX), SkScalarInvert(s->fY));
964 }
965
966 return true;
967}
void SkComputeGivensRotation(const SkVector &h, SkMatrix *G)
#define SkScalarInvert(x)
Definition SkScalar.h:73
#define SK_Scalar1
Definition SkScalar.h:18
#define SK_ScalarNearlyZero
Definition SkScalar.h:99
#define SkScalarRoundToScalar(x)
Definition SkScalar.h:32
#define SkScalarAbs(x)
Definition SkScalar.h:39
static constexpr int kMScaleX
horizontal scale factor
Definition SkMatrix.h:353
static constexpr int kMTransY
vertical translation
Definition SkMatrix.h:358
static constexpr int kMPersp1
input y perspective factor
Definition SkMatrix.h:360
SkMatrix & setAll(SkScalar scaleX, SkScalar skewX, SkScalar transX, SkScalar skewY, SkScalar scaleY, SkScalar transY, SkScalar persp0, SkScalar persp1, SkScalar persp2)
Definition SkMatrix.h:562
SkMatrix & preConcat(const SkMatrix &other)
Definition SkMatrix.cpp:674
static constexpr int kMPersp0
input x perspective factor
Definition SkMatrix.h:359
static constexpr int kMPersp2
perspective bias
Definition SkMatrix.h:361
static constexpr int kMTransX
horizontal translation
Definition SkMatrix.h:355
static constexpr int kMSkewY
vertical skew factor
Definition SkMatrix.h:356
bool isFinite() const
Definition SkMatrix.h:1834
SkScalar get(int index) const
Definition SkMatrix.h:392
static constexpr int kMScaleY
vertical scale factor
Definition SkMatrix.h:357
static constexpr int kMSkewX
horizontal skew factor
Definition SkMatrix.h:354
SkMatrix & preScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py)
Definition SkMatrix.cpp:315
float SkScalar
Definition extension.cpp:12
struct MyStruct s
SkScalar h
Definition SkMD5.cpp:125
static constexpr SkPoint Make(float x, float y)
void getSingleMatrix(SkMatrix *) const

◆ dump()

SkString SkScalerContextRec::dump ( ) const
inline

Definition at line 143 of file SkScalerContext.h.

143 {
144 SkString msg;
145 msg.appendf(" Rec\n");
146 msg.appendf(" textsize %a prescale %a preskew %a post [%a %a %a %a]\n",
148 fPost2x2[0][1], fPost2x2[1][0], fPost2x2[1][1]);
149 msg.appendf(" frame %g miter %g format %d join %d cap %d flags %#hx\n",
150 fFrameWidth, fMiterLimit, fMaskFormat, fStrokeJoin, fStrokeCap, fFlags);
151 msg.appendf(" lum bits %x, device gamma %d, paint gamma %d contrast %d\n", fLumBits,
152 fDeviceGamma, fPaintGamma, fContrast);
153 msg.appendf(" foreground color %x\n", fForegroundColor);
154 return msg;
155 }
void void void appendf(const char format[],...) SK_PRINTF_LIKE(2
Definition SkString.cpp:550
SkMask::Format fMaskFormat

◆ getContrast()

SkScalar SkScalerContextRec::getContrast ( ) const
inline

Definition at line 100 of file SkScalerContext.h.

100 {
101 sk_ignore_unused_variable(fReservedAlign);
102 return SkIntToScalar(fContrast) / ((1 << 8) - 1);
103 }
#define SkIntToScalar(x)
Definition SkScalar.h:57
void sk_ignore_unused_variable(const T &)
Definition SkTemplates.h:37

◆ getDeviceGamma()

SkScalar SkScalerContextRec::getDeviceGamma ( ) const
inline

Definition at line 82 of file SkScalerContext.h.

82 {
83 return SkIntToScalar(fDeviceGamma) / (1 << 6);
84 }

◆ getFormat()

SkMask::Format SkScalerContextRec::getFormat ( ) const
inline

Definition at line 211 of file SkScalerContext.h.

211 {
212 return fMaskFormat;
213 }

◆ getHinting()

SkFontHinting SkScalerContextRec::getHinting ( ) const
inline

Definition at line 478 of file SkScalerContext.h.

478 {
479 unsigned hint = (fFlags & SkScalerContext::kHinting_Mask) >>
481 return static_cast<SkFontHinting>(hint);
482}
SkFontHinting
Definition SkFontTypes.h:18

◆ getLocalMatrix()

void SkScalerContextRec::getLocalMatrix ( SkMatrix m) const

Definition at line 841 of file SkScalerContext.cpp.

841 {
843}
static SkMatrix MakeTextMatrix(SkScalar size, SkScalar scaleX, SkScalar skewX)
Definition SkFontPriv.h:41

◆ getLuminanceColor()

SkColor SkScalerContextRec::getLuminanceColor ( ) const
inline

Definition at line 215 of file SkScalerContext.h.

215 {
216 return fLumBits;
217 }

◆ getMatrixFrom2x2()

void SkScalerContextRec::getMatrixFrom2x2 ( SkMatrix dst) const

Definition at line 835 of file SkScalerContext.cpp.

835 {
836 dst->setAll(fPost2x2[0][0], fPost2x2[0][1], 0,
837 fPost2x2[1][0], fPost2x2[1][1], 0,
838 0, 0, 1);
839}
dst
Definition cp.py:12

◆ getPaintGamma()

SkScalar SkScalerContextRec::getPaintGamma ( ) const
inline

Definition at line 91 of file SkScalerContext.h.

91 {
92 return SkIntToScalar(fPaintGamma) / (1 << 6);
93 }

◆ getSingleMatrix()

void SkScalerContextRec::getSingleMatrix ( SkMatrix m) const

Definition at line 845 of file SkScalerContext.cpp.

845 {
846 this->getLocalMatrix(m);
847
848 // now concat the device matrix
849 SkMatrix deviceMatrix;
850 this->getMatrixFrom2x2(&deviceMatrix);
851 m->postConcat(deviceMatrix);
852}
void getLocalMatrix(SkMatrix *) const
void getMatrixFrom2x2(SkMatrix *) const

◆ ignoreGamma()

void SkScalerContextRec::ignoreGamma ( )
inline

Causes the luminance color to be ignored, and the paint and device gamma to be effectively 1.0

Definition at line 114 of file SkScalerContext.h.

114 {
118 }
constexpr SkColor SK_ColorTRANSPARENT
Definition SkColor.h:99
void setPaintGamma(SkScalar pg)
void setDeviceGamma(SkScalar dg)
void setLuminanceColor(SkColor c)

◆ ignorePreBlend()

void SkScalerContextRec::ignorePreBlend ( )
inline

Causes the luminance color and contrast to be ignored, and the paint and device gamma to be effectively 1.0.

Definition at line 124 of file SkScalerContext.h.

124 {
125 ignoreGamma();
126 setContrast(0);
127 }
void setContrast(SkScalar c)

◆ setContrast()

void SkScalerContextRec::setContrast ( SkScalar  c)
inline

Definition at line 104 of file SkScalerContext.h.

104 {
107 fContrast = SkScalarRoundToInt(c * ((1 << 8) - 1));
108 }
#define SkASSERT(cond)
Definition SkAssert.h:116
#define SkScalarRoundToInt(x)
Definition SkScalar.h:37
static constexpr SkScalar kMaxContrastInclusive
static constexpr SkScalar kMinContrastInclusive

◆ setDeviceGamma()

void SkScalerContextRec::setDeviceGamma ( SkScalar  dg)
inline

Definition at line 85 of file SkScalerContext.h.

85 {
88 fDeviceGamma = SkScalarFloorToInt(dg * (1 << 6));
89 }
#define SkScalarFloorToInt(x)
Definition SkScalar.h:35
static constexpr SkScalar kMaxGammaExclusive
static constexpr SkScalar kMinGammaInclusive

◆ setHinting()

void SkScalerContextRec::setHinting ( SkFontHinting  hinting)
inline

Definition at line 484 of file SkScalerContext.h.

484 {
485 fFlags = (fFlags & ~SkScalerContext::kHinting_Mask) |
486 (static_cast<unsigned>(hinting) << SkScalerContext::kHinting_Shift);
487}

◆ setLuminanceColor()

void SkScalerContextRec::setLuminanceColor ( SkColor  c)

Definition at line 996 of file SkScalerContext.cpp.

996 {
999}
#define SkColorGetR(color)
Definition SkColor.h:65
#define SkColorGetG(color)
Definition SkColor.h:69
#define SkColorSetRGB(r, g, b)
Definition SkColor.h:57
#define SkColorGetB(color)
Definition SkColor.h:73
static SkColor CanonicalColor(SkColor color)

◆ setPaintGamma()

void SkScalerContextRec::setPaintGamma ( SkScalar  pg)
inline

Definition at line 94 of file SkScalerContext.h.

94 {
97 fPaintGamma = SkScalarFloorToInt(pg * (1 << 6));
98 }

Friends And Related Symbol Documentation

◆ SkScalerContext

friend class SkScalerContext
friend

Definition at line 225 of file SkScalerContext.h.

Member Data Documentation

◆ fFlags

uint16_t SkScalerContextRec::fFlags

Definition at line 136 of file SkScalerContext.h.

◆ fForegroundColor

uint32_t SkScalerContextRec::fForegroundColor {SK_ColorBLACK}

Definition at line 70 of file SkScalerContext.h.

constexpr SkColor SK_ColorBLACK
Definition SkColor.h:103

◆ fFrameWidth

SkScalar SkScalerContextRec::fFrameWidth

Definition at line 65 of file SkScalerContext.h.

◆ fMaskFormat

SkMask::Format SkScalerContextRec::fMaskFormat

Definition at line 129 of file SkScalerContext.h.

◆ fMiterLimit

SkScalar SkScalerContextRec::fMiterLimit

Definition at line 65 of file SkScalerContext.h.

◆ fPost2x2

SkScalar SkScalerContextRec::fPost2x2[2][2]

Definition at line 64 of file SkScalerContext.h.

◆ fPreScaleX

SkScalar SkScalerContextRec::fPreScaleX

Definition at line 63 of file SkScalerContext.h.

◆ fPreSkewX

SkScalar SkScalerContextRec::fPreSkewX

Definition at line 63 of file SkScalerContext.h.

◆ fTextSize

SkScalar SkScalerContextRec::fTextSize

Definition at line 63 of file SkScalerContext.h.

◆ fTypefaceID

SkTypefaceID SkScalerContextRec::fTypefaceID

Definition at line 62 of file SkScalerContext.h.


The documentation for this struct was generated from the following files: