Platforms to show: All Mac Windows Linux Cross-Platform

CTLineMBS class

Super class: CFObjectMBS

Type Topic Plugin Version macOS Windows Linux iOS Targets
class CoreText MBS MacCG Plugin 14.2 ✅ Yes ❌ No ❌ No ✅ Yes All
The CTLine opaque type represents a line of text.
Example
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."

// blue
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

#If XojoVersion >= 2019.02 Then
Dim CGContextHandle As ptr = g.Handle(Graphics.HandleTypes.CGContextRef)
Dim CGContext As CGContextMBS = CGContextMBS.contextWithCGContext(CGContextHandle)
#Else
Dim CGContextHandle As Integer = g.Handle(g.HandleTypeCGContextRef)
Dim CGContext As CGContextMBS = CGContextMBS.contextWithCGContext(CGContextHandle)
#EndIf

CGContext.SaveGState

// reset text matrix
dim a as CGAffineTransformMBS = CGAffineTransformMBS.Identity
CGContext.TextMatrix = a

// draw
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)
line.Draw(CGContext)

CGContext.RestoreGState
CGContext.Flush
End Sub

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.

Line Bounds

Constant Value Description
kCTLineBoundsExcludeTypographicLeading 1 Pass this option to exclude typographic leading.
kCTLineBoundsExcludeTypographicShifts 2 Pass this option to ignore cross-stream shifts due to positioning (such as kerning or baseline alignment).
kCTLineBoundsUseGlyphPathBounds 8 Pass this option to use glyph path bounds rather than the default typographic bounds.
kCTLineBoundsUseHangingPunctuation 4 Normally line bounds include all glyphs; pass this option to treat standard punctuation hanging off either end of the line as fully hanging.
kCTLineBoundsUseOpticalBounds 16 Pass this option to use optical bounds. This option overrides kCTLineBoundsUseGlyphPathBounds.

Truncate Types

Constant Value Description
kCTLineTruncationEnd 1 Truncate the end of the line, leaving the start portion visible.
kCTLineTruncationMiddle 2 Truncate the middle of the line, leaving both the start and the end portions visible.
kCTLineTruncationStart 0 Truncate the beginning of the line, leaving the end portion visible.

Super class CFObjectMBS

This class has no sub classes.

Some methods using this class:

Some examples using this class:

Blog Entries


The items on this page are in the following plugins: MBS MacCF Plugin, MBS MacCG Plugin.


CTGlyphInfoMBS   -   CTMutableFontCollectionMBS


The biggest plugin in space...