API  1.0.0
CGContextText.j
Go to the documentation of this file.
1 /*
2  * CGContextText.j
3  * CoreText
4  *
5  * Created by Nicholas Small.
6  * Copyright 2011, 280 North, Inc.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
27 
28 function CGContextGetTextMatrix(/* CGContext */ aContext)
29 {
30  return aContext._textMatrix;
31 }
32 
33 function CGContextSetTextMatrix(/* CGContext */ aContext, /* CGAffineTransform */ aTransform)
34 {
35  aContext._textMatrix = aTransform;
36 }
37 
38 function CGContextGetTextPosition(/* CGContext */ aContext)
39 {
40  return aContext._textPosition || _CGPointMakeZero();
41 }
42 
43 function CGContextSetTextPosition(/* CGContext */ aContext, /* float */ x, /* float */ y)
44 {
45  aContext._textPosition = CGPointMake(x, y);
46 }
47 
48 function CGContextGetFont(/* CGContext */ aContext)
49 {
50  return aContext._CPFont;
51 }
52 
53 function CGContextSelectFont(/* CGContext */ aContext, /* CPFont */ aFont)
54 {
55  aContext.font = [aFont cssString];
56  aContext._CPFont = aFont;
57 }
58 
59 function CGContextSetTextDrawingMode(/* CGContext */ aContext, /* CGTextDrawingMode */ aMode)
60 {
61  aContext._textDrawingMode = aMode;
62 }
63 
64 function CGContextShowText(/* CGContext */ aContext, /* CPString */ aString)
65 {
66  CGContextShowTextAtPoint(aContext, aContext._textPosition.x, aContext._textPosition.y, aString);
67 }
68 
69 function CGContextShowTextAtPoint(/* CGContext */ aContext, /* float */ x, /* float */ y, /* CPString */ aString)
70 {
71  aContext.textBaseline = @"middle";
72  aContext.textAlign = @"left";
73 
74  var mode = aContext._textDrawingMode;
75  if (!mode && mode !== 0)
76  mode = kCGTextFill;
77 
78  var width = aContext.measureText(aString).width;
79 
80  if (mode === kCGTextFill || mode === kCGTextFillStroke)
81  aContext.fillText(aString, x, y);
82  if (mode === kCGTextStroke || mode === kCGTextFillStroke)
83  aContext.strokeText(aString, x, y);
84 
85  aContext._textPosition = CGPointMake(x + width, y);
86 }
kCGTextFill
Definition: CGContextText.j:23
function CGContextSetTextDrawingMode(aContext, aMode)
Definition: CGContextText.j:59
kCGTextFillStroke
Definition: CGContextText.j:25
function CGContextSetTextMatrix(aContext, aTransform)
Definition: CGContextText.j:33
int width
function CGContextGetFont(aContext)
Definition: CGContextText.j:48
kCGTextInvisible
Definition: CGContextText.j:26
function CGContextSelectFont(aContext, aFont)
Definition: CGContextText.j:53
function CGContextSetTextPosition(aContext, x, y)
Definition: CGContextText.j:43
function CGContextGetTextMatrix(aContext)
Definition: CGContextText.j:28
function CGContextShowTextAtPoint(aContext, x, y, aString)
Definition: CGContextText.j:69
function CGContextGetTextPosition(aContext)
Definition: CGContextText.j:38
function CGContextShowText(aContext, aString)
Definition: CGContextText.j:64
kCGTextStroke
Definition: CGContextText.j:24