Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

CTLineMBS class

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
Function: The CTLine opaque type represents a line of text.
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

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

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

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.

Feedback, Comments & Corrections

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 which use 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...

MBS Xojo Chart Plugins