I have always wanted to study coreText. Now I have the opportunity to record it.
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + examples/fOqtK7uPbV + examples + MO/0NC/examples + examples/examples + 4 LXItcjQxc + ioaM8L3A + examples/OhoyAyoaLJ + examples /samples/PTw9Pase3Kvr/Ju + bWxsf40/LX + samples + 2 samples/OjrNXiuPa21M/samples + samples/samples + bWxsf40/samples + c1_vcd4kpha + CjIuu + samples o6y147v3ysK8/examples + ho0NUTGluZSDT1r/examples/gttTT2mN0bGluZbXE1/examples + examples/examples + CjxwPs/Cw + samples + bG + samples + examples/examples + cjwvcD4KPHA + Environment + DNrLXE19a3 + yjA/Environment + nP4LnY19bM5SjA/Environment + 601rW91 + Environment + s/environment/Environment + cjxwPgp4uN + platform ++ Platform + platform/Platform + platform ++ bjftsgo0tRDzqq7 + Platform + Cs/Platform + c/f0tTPwrXE19bEuLK/t9a90M/platform/Platform + platform/terminal/ examples/samples + mzydfWt/u1xM/fu/LH + s/foaO/samples + samples/PJz73Hus3PwrK/tcTLrsa9z9 + hozwvcD4KPHA + samples/samples + 7 + samples/ f19a4/M/release/tMbwwLS6w8/xysfEvs23v + m/zLXE0rvR + TwvcD4KPHA + release/xu + release/dfW19a3 + release/release = "http://www.bkjia.com/uploadfile/Collfiles/20140106/2014010609171164.gif" alt = "\">
Character attribute name:
Const CFStringRef kCTCharacterShapeAttributeName; // The default value of the font shape attribute must be 0 for the CFNumberRef object. If the value is not 0, the corresponding character shape is defined. For example, 1 indicates the traditional character shape const CFStringRef; // The font attribute must be the CTFont object const CFStringRef kCTKernAttributeName; // The character interval attribute must be the CFNumberRef object const CFStringRef kCTLigatureAttributeName; // set whether to use the hyphen attribute to 0, indicates that the hyphen attribute is not used. The standard English hyphen (FI) and FL. The default value is 1. Both use the standard hyphen. That is, when f is searched, fl is considered as a text. It must be CFNumberRef. The default value is 1. You can set 0, 1, and 2 const CFStringRef kCTForegroundColorAttributeName. // The font color attribute must be a CGColor object. The default value is blackconst CFStringRef kctforeground; // The context font color attribute must be CFBooleanRef; default value: False; const CFStringRef kCTParagraphStyleAttributeName; // The stroke line width must be a CFNumberRef object. The default value is 0.0f and the standard value is 3.0 fconst CFStringRef k. CTStrokeColorAttributeName; // The color attribute of a stroke must be a CGColorRef object. The default value is const CFStringRef kCTSuperscriptAttributeName. // set the font's upper/lower mark attribute to the CFNumberRef object. The default value is 0, it can be-1 as subscript, 1 as superscript, and font support is required. For example, the composite style Cn1const CFStringRef kCTUnderlineColorAttributeName; // The font underline color attribute must be a CGColorRef object. The default value is the foreground color const CFStringRef kCTUnderlineStyleAttributeName. // The font underline style, if it is kCTUnderlineStyleNone, you can use CTUnderlineStypleModifiers to modify the underline style const CFStringRef kCTVerticalFormsAttributeName; // The font direction attribute of the text must be CFBooleanRef. The default value is false, true indicates that the vertical direction const CFStringRef kCTGlyphInfoAttributeName; // The font information attribute must be the CTGlyphInfo object const CFStringRef kCTRunDelegateAttributeName // CTRun the delegate attribute must be the CTRunDelegate object
About CTM
CTM, Context Translate Matrix. The context to be drawn is represented by a thing called Matrix. It can be simply used to map every point of the drawn context to the Matrix, your operations on the Matrix will change the vertices in the context accordingly. Such as amplification, rotation, and movement.
In a general tutorial, the context is changed first to achieve the purpose of rotation or zoom in and out, for example:
CGContextTranslateCTM(context, 0, self.bounds.size.height);CGContextScaleCTM(context, 1.0f, -1.0f);
Then perform the Drawing operation. So how is this drawing operation done? Why is this operation on Matrix put in front rather than behind? Why is it ineffective to put it behind? Doesn't it mean that changing the Matrix will change all the points mapped above? These conventional logic thinking makes the problem more and more difficult to understand and solve. Then we will first understand from context.
In general, we always think that context is the canvas, and all matrix rotations are aimed at the canvas rotation. Although this understanding is incorrect, the result is correct, however, if you want to understand the matrix before or after some complex coordinate system transformations or changes to the matrix, this understanding will produce a rare result.
In fact, context refers to the angle context of the painter. For example, by default, the Paster's angle is facing the canvas:
The canvas is white, while I use a yellow triangle in the upper left corner to mark its upper left corner, and left top to mark the upper left corner of the context, while the painter is a yellow circle.
Remember !! The canvas is always facing the screen. It does not rotate, zoom in or out, or move.
So why does it look like I have zoomed in or moved? Actually, you are moving your context, that is, your context perspective. For example, I want to rotate 180 degrees and write an "abcdefg" in the upper left corner ".
First, I need to rotate 180 degrees first:
Then, I wrote "abcdefg" in the upper left corner ":
Then reset context:
We can see that we changed the context only by changing the angle of the canvas, while the canvas is still facing the screen. We always set the upper left corner of the context as the top left corner of the canvas, instead of taking the upper left corner of the canvas as the upper left corner. That is to say, the coordinates (0, 0) during painting are the left top of the context after you rotate, rather than the upper left corner of the canvas. This is very important.
Therefore, when painting, it is actually drawn in the bottom right corner of the canvas. To reset the context, you just need to direct yourself to the canvas. This makes it clear why the plotting is effective after the context is changed using matrix (the angle of the canvas is adjusted first ), instead of making adjustments after the painting (because you have finished the painting, what is the purpose of adjusting your angle ?).
Correct understanding of how to use matrix to change context is important because it involves the coordinate system. Later, CoreText will give an example.
About NS Coordinate System
The NS coordinate system is in the lower left corner (0, 0), which is opposite to the iOS Coordinate System in Y. Therefore, the X direction is the same when CoreText is used for drawing or text in iOS, however, Y is reversed. For example:
So what should we do? Think about it. Looking at the figure above, it looks like a reflection in the normal direction, but the horizontal line is at the top. Well, move it down, and then turn it back to see the effect. For example:
Effect:
IOS CoreText. framework --- basic usage