Super class: CFObjectMBS
|Type||Topic||Plugin||Version||macOS||Windows||Linux||Console & Web||iOS|
|class||CoreText||MBS MacCG Plugin||14.2||Yes||No||No||Yes, macOS only||No|
Sub Paint(g As Graphics)
// inside paint event of a Canvas
// create a font, quasi systemFontWithSize:24.0
dim sysUIFont as CTFontMBS = CTFontMBS.CreateUIFontForLanguage(CTFontMBS.kCTFontUIFontSystem, 24.0)
// create a naked string
dim text as string = "Some Text."
dim cgColor as CGColorMBS = CGColorMBS.CreateGenericRGB(0.0, 0.0, 1.0)
// single underline
dim underline as Integer = CoreTextMBS.kCTUnderlineStyleSingle
// pack it into attributes dictionary
dim attributesDict as new Dictionary
attributesDict.Value(CoreTextMBS.kCTFontAttributeName) = sysUIFont
attributesDict.Value(CoreTextMBS.kCTForegroundColorAttributeName) = cgColor
attributesDict.Value(CoreTextMBS.kCTUnderlineStyleAttributeName) = underline
// make the attributed string
dim cfDic as new CFDictionaryMBS(attributesDict)
dim cfStr as new CFStringMBS(text)
dim stringToDraw as CFAttributedStringMBS = CFAttributedStringMBS.Create( cfStr, cfDic)
// now for the actual drawing
dim CGContextHandle as Integer = g.Handle(g.HandleTypeCGContextRef)
dim CGContext as CGContextMBS = CGContextMBS.contextWithCGContext(CGContextHandle)
// reset text matrix
dim a as CGAffineTransformMBS = CGAffineTransformMBS.Identity
CGContext.TextMatrix = a
dim line as CTLineMBS = CTLineMBS.CreateWithAttributedString(stringToDraw)
dim x as Integer = 10
dim y as Integer = 10
// plus text height
y = y + 24
// swap y
y = g.Height - y
CGContext.TextPosition = new CGPointMBS(x, y)
A CTLine object contains an array of glyph runs. Line objects are created by the typesetter during a framesetting operation and can draw themselves directly into a graphics context.
Subclass of the CFObjectMBS class.
This is an abstract class. You can't create an instance, but you can get one from various plugin functions.
- 4 properties
- 11 methods
- method Bounds(options as Integer = 0) as CGRectMBS
- method Constructor
- method CreateJustifiedLine(justificationFactor as Double, justificationWidth as Double) as CTLineMBS
- method CreateTruncatedLine(width as Double, truncationType as Integer, truncationToken as CTLineMBS = nil) as CTLineMBS
- method Draw(context as CGContextMBS)
- method GlyphRuns as CTRunMBS()
- method ImageBounds(context as CGContextMBS) as CGRectMBS
- method OffsetForStringIndex(charIndex as Integer, byref secondaryOffset as Double) as Double
- method PenOffsetForFlush(flushFactor as Double, flushWidth as Double) as Double
- method StringIndexForPosition(position as CGPointMBS) as Integer
- method TypographicBounds(byref ascent as Double, byref descent as Double, byref leading as Double) as Double
- 2 shared methods
- 8 constants
Pass this option to exclude typographic leading.
Pass this option to ignore cross-stream shifts due to positioning (such as kerning or baseline alignment).
Pass this option to use glyph path bounds rather than the default typographic bounds.
Normally line bounds include all glyphs; pass this option to treat standard punctuation hanging off either end of the line as fully hanging.
Pass this option to use optical bounds. This option overrides kCTLineBoundsUseGlyphPathBounds.
Truncate the end of the line, leaving the start portion visible.
Truncate the middle of the line, leaving both the start and the end portions visible.
Truncate the beginning of the line, leaving the end portion visible.
Super class CFObjectMBS
- 5 properties
- 8 methods
- shared method NewCFObject(handle as Integer) as CFObjectMBS
This class has no sub classes.
Some methods using this class:
- CTFrameMBS.Lines as CTLineMBS()
- CTTypesetterMBS.CreateLine(location as Integer, length as Integer, offset as Double = 0.0) as CTLineMBS
Some examples which use this class:
The items on this page are in the following plugins: MBS MacCF Plugin, MBS MacCG Plugin.
MBS Xojo Plugins