Vuo  2.3.2
Classes | Macros | Typedefs | Functions | Variables
VuoImageText.cc File Reference

Description

VuoImageText implementation.

Definition in file VuoImageText.cc.

Go to the source code of this file.

Classes

class  VuoFontClass
 A wrapper for VuoFont, so it can be used as a std::map key. More...
 

Macros

#define ScreenToGL(x)   (((x) / screenWidthInPixels) * 2.)
 Shortcut macro for converting to GL coordinates in VuoImageTextData_convertToVuoCoordinates function. More...
 

Typedefs

typedef std::vector< VuoPoint2d > VuoCorners
 4 corners of a (non-axis-aligned) rectangle. More...
 
typedef std::pair< std::string, VuoFontClassVuoImageTextCacheDescriptor
 Text, font. More...
 
typedef std::pair< std::pair< VuoImage, VuoCorners >, double > VuoImageTextCacheEntry
 ((An image, its bounds), and the last time it was used) More...
 
typedef std::map< VuoImageTextCacheDescriptor, VuoImageTextCacheEntryVuoImageTextCacheType
 A pool of images. More...
 

Functions

bool operator< (const VuoFontClass &a, const VuoFontClass &b)
 Returns true if a is less than b. More...
 
VuoImageTextData VuoImageTextData_make ()
 Initialize a new instance of VuoImageTextData. More...
 
void VuoImageTextData_free (void *data)
 Free a VuoImageTextData pointer and it's contents. More...
 
static void VuoImageTextCache_cleanup (void *blah)
 Purges expired images from the cache. More...
 
static void VuoImageTextCache_init (void)
 Initializes the cache. More...
 
VuoReal VuoImageText_getVerticalScale (VuoReal screenWidth, VuoReal backingScaleFactor)
 Get the vertical scaling used for text. More...
 
static CFArrayRef VuoImageText_createCTLines (VuoText text, VuoFont font, VuoReal backingScaleFactor, VuoReal verticalScale, VuoReal rotation, VuoReal wrapWidth, bool includeTrailingWhiteSpace, CTFontRef *ctFont, CGColorRef *cgColor, CGColorSpaceRef *colorspace, VuoImageTextData textImageData, CGAffineTransform *outTransform)
 Formats the specified text for rendering using font and backingScaleFactor. More...
 
VuoRectangle VuoImage_getTextRectangle (VuoText text, VuoFont font, VuoReal backingScaleFactor, VuoReal verticalScale, VuoReal rotation, float wrapWidth, bool includeTrailingWhiteSpace)
 Returns a rectangle (in points) that fully encloses the specified text when rendered with the specified font. More...
 
VuoImageTextData VuoImage_getTextImageData (VuoText text, VuoFont font, VuoReal backingScaleFactor, VuoReal verticalScale, VuoReal rotation, bool includeTrailingWhiteSpace)
 Returns a struct containing all information necessary to calculate text and character size and placement when rendered. More...
 
VuoPoint2d VuoImageText_getTextSize (VuoText text, VuoFont font, VuoPoint2d windowSize, VuoReal backingScaleFactor, bool includeTrailingWhiteSpace)
 Outputs the size in Vuo coordinates of a real-size text layer. More...
 
VuoReal VuoImageText_getLineHeight (VuoFont font, VuoReal screenWidthInPixels, VuoReal backingScaleFactor)
 Get the line height of a font in Vuo coordinates. More...
 
void VuoImageTextData_convertToVuoCoordinates (VuoImageTextData textData, VuoReal screenWidthInPixels, VuoReal backingScaleFactor)
 Convert VuoImageTextData from pixel coordinates to Vuo coordinates in place. More...
 
VuoPoint2d VuoImageTextData_getPositionForLineIndex (VuoImageTextData textData, unsigned int lineIndex)
 Get the origin point of a line of text (bottom left point of first character billboard in line). More...
 
unsigned int VuoImageTextData_getLineWithCharIndex (VuoImageTextData textData, unsigned int charIndex, unsigned int *lineStartCharIndex)
 Find the line index that the character at charIndex resides in. More...
 
VuoPoint2d VuoImageTextData_getPositionForCharIndex (VuoImageTextData textData, unsigned int charIndex, unsigned int *lineIndex)
 Get the starting point for a character index (bottom left corner). More...
 
VuoRectangleVuoImageTextData_getRectsForHighlight (VuoImageTextData textData, unsigned int selectionStartIndex, unsigned int selectionLength, unsigned int *lineCount)
 Given a start index and length of selected characters return an array of VuoRectangles encompassing the selection. More...
 
unsigned int VuoImageTextData_getCharIndexForLine (VuoImageTextData textData, unsigned int lineIndex)
 Get the index of the first character at line index. More...
 
VuoRectangle VuoImageTextData_layoutRowAtIndex (VuoImageTextData textData, unsigned int index, unsigned int *charactersRemaining)
 Get a rect that contains a row of text starting at index. More...
 
int VuoImageTextData_getNearestCharToPoint (VuoImageTextData textData, VuoPoint2d point)
 Return the character index (0 indexed) nearest to point, where point is relative to the pivot point of a text layer. More...
 
VuoImage VuoImage_makeText (VuoText text, VuoFont font, float backingScaleFactor, float verticalScale, float rotation, float wrapWidth, VuoPoint2d *outCorners)
 Creates an image containing the specified text. More...
 

Variables

static VuoImageTextCacheTypeVuoImageTextCache
 A pool of images. More...
 
static dispatch_semaphore_t VuoImageTextCache_semaphore
 Serializes access to VuoImageTextCache. More...
 
static dispatch_semaphore_t VuoImageTextCache_canceledAndCompleted
 Signals when the last VuoImageTextCache cleanup has completed. More...
 
static volatile dispatch_source_t VuoImageTextCache_timer = NULL
 Periodically cleans up VuoImageTextCache. More...
 
static double VuoImageTextCache_timeout = 1.0
 Seconds an image can remain in the cache unused, before it gets purged. More...
 

Macro Definition Documentation

◆ ScreenToGL

#define ScreenToGL (   x)    (((x) / screenWidthInPixels) * 2.)

Shortcut macro for converting to GL coordinates in VuoImageTextData_convertToVuoCoordinates function.

Definition at line 464 of file VuoImageText.cc.

Typedef Documentation

◆ VuoCorners

typedef std::vector<VuoPoint2d> VuoCorners

4 corners of a (non-axis-aligned) rectangle.

Definition at line 118 of file VuoImageText.cc.

◆ VuoImageTextCacheDescriptor

typedef std::pair<std::string, VuoFontClass> VuoImageTextCacheDescriptor

Text, font.

Definition at line 119 of file VuoImageText.cc.

◆ VuoImageTextCacheEntry

typedef std::pair<std::pair<VuoImage, VuoCorners>, double> VuoImageTextCacheEntry

((An image, its bounds), and the last time it was used)

Definition at line 120 of file VuoImageText.cc.

◆ VuoImageTextCacheType

A pool of images.

Definition at line 121 of file VuoImageText.cc.

Function Documentation

◆ operator<()

bool operator< ( const VuoFontClass a,
const VuoFontClass b 
)

Returns true if a is less than b.

Definition at line 74 of file VuoImageText.cc.

◆ VuoImage_getTextImageData()

VuoImageTextData VuoImage_getTextImageData ( VuoText  text,
VuoFont  font,
VuoReal  backingScaleFactor,
VuoReal  verticalScale,
VuoReal  rotation,
bool  includeTrailingWhiteSpace 
)

Returns a struct containing all information necessary to calculate text and character size and placement when rendered.

If text is null or empty, null is returned.

Changed in Vuo 2.0.0:
Added backingScaleFactor, verticalScale, rotation arguments.

Definition at line 426 of file VuoImageText.cc.

◆ VuoImage_getTextRectangle()

VuoRectangle VuoImage_getTextRectangle ( VuoText  text,
VuoFont  font,
VuoReal  backingScaleFactor,
VuoReal  verticalScale,
VuoReal  rotation,
float  wrapWidth,
bool  includeTrailingWhiteSpace 
)

Returns a rectangle (in points) that fully encloses the specified text when rendered with the specified font.

Depending on the font's design (e.g., if the font is monospace), the rectangle may be larger than the actual glyphs.

Changed in Vuo 2.0.0:
Added backingScaleFactor, verticalScale, rotation, wrapWidth arguments.

Definition at line 405 of file VuoImageText.cc.

◆ VuoImage_makeText()

VuoImage VuoImage_makeText ( VuoText  text,
VuoFont  font,
float  backingScaleFactor,
float  verticalScale,
float  rotation,
float  wrapWidth,
VuoPoint2d *  outCorners 
)

Creates an image containing the specified text.

If outCorners is not null, this function fills it with the text's 4 transformed bounds in pixels relative to the top-left of the image.

Changed in Vuo 2.0.0:
Added verticalScale, rotation, wrapwidth, outCorners arguments.

Definition at line 752 of file VuoImageText.cc.

◆ VuoImageText_createCTLines()

static CFArrayRef VuoImageText_createCTLines ( VuoText  text,
VuoFont  font,
VuoReal  backingScaleFactor,
VuoReal  verticalScale,
VuoReal  rotation,
VuoReal  wrapWidth,
bool  includeTrailingWhiteSpace,
CTFontRef *  ctFont,
CGColorRef *  cgColor,
CGColorSpaceRef *  colorspace,
VuoImageTextData  textImageData,
CGAffineTransform *  outTransform 
)
static

Formats the specified text for rendering using font and backingScaleFactor.

Definition at line 231 of file VuoImageText.cc.

◆ VuoImageText_getLineHeight()

VuoReal VuoImageText_getLineHeight ( VuoFont  font,
VuoReal  screenWidthInPixels,
VuoReal  backingScaleFactor 
)

Get the line height of a font in Vuo coordinates.

Useful in cases where no text data is available (ie, you should prefer using textData->lineHeight where available).

Changed in Vuo 2.0.0:
New.

Definition at line 471 of file VuoImageText.cc.

◆ VuoImageText_getTextSize()

VuoPoint2d VuoImageText_getTextSize ( VuoText  text,
VuoFont  font,
VuoPoint2d  windowSize,
VuoReal  backingScaleFactor,
bool  includeTrailingWhiteSpace 
)

Outputs the size in Vuo coordinates of a real-size text layer.

windowSize is in points.

Definition at line 449 of file VuoImageText.cc.

◆ VuoImageText_getVerticalScale()

VuoReal VuoImageText_getVerticalScale ( VuoReal  screenWidth,
VuoReal  backingScaleFactor 
)

Get the vertical scaling used for text.

Changed in Vuo 2.0.0:
New.

Definition at line 223 of file VuoImageText.cc.

◆ VuoImageTextCache_cleanup()

static void VuoImageTextCache_cleanup ( void *  blah)
static

Purges expired images from the cache.

Definition at line 131 of file VuoImageText.cc.

◆ VuoImageTextCache_init()

static void VuoImageTextCache_init ( void  )
static

Initializes the cache.

Definition at line 175 of file VuoImageText.cc.

◆ VuoImageTextData_convertToVuoCoordinates()

void VuoImageTextData_convertToVuoCoordinates ( VuoImageTextData  textData,
VuoReal  screenWidthInPixels,
VuoReal  backingScaleFactor 
)

Convert VuoImageTextData from pixel coordinates to Vuo coordinates in place.

Definition at line 497 of file VuoImageText.cc.

◆ VuoImageTextData_free()

void VuoImageTextData_free ( void *  data)

Free a VuoImageTextData pointer and it's contents.

Definition at line 102 of file VuoImageText.cc.

◆ VuoImageTextData_getCharIndexForLine()

unsigned int VuoImageTextData_getCharIndexForLine ( VuoImageTextData  textData,
unsigned int  lineIndex 
)

Get the index of the first character at line index.

Changed in Vuo 2.0.0:
New.

Definition at line 661 of file VuoImageText.cc.

◆ VuoImageTextData_getLineWithCharIndex()

unsigned int VuoImageTextData_getLineWithCharIndex ( VuoImageTextData  textData,
unsigned int  charIndex,
unsigned int *  lineStartCharIndex 
)

Find the line index that the character at charIndex resides in.

If lineStartCharIndex is not null, the character index of the first character on the found line is stored. In the event that charIndex is out of the bounds of textData, 0 or lineCounts - 1 is returned.

Changed in Vuo 2.0.0:
Added lineIndex argument.

Definition at line 561 of file VuoImageText.cc.

◆ VuoImageTextData_getNearestCharToPoint()

int VuoImageTextData_getNearestCharToPoint ( VuoImageTextData  textData,
VuoPoint2d  point 
)

Return the character index (0 indexed) nearest to point, where point is relative to the pivot point of a text layer.

Definition at line 687 of file VuoImageText.cc.

◆ VuoImageTextData_getPositionForCharIndex()

VuoPoint2d VuoImageTextData_getPositionForCharIndex ( VuoImageTextData  textData,
unsigned int  charIndex,
unsigned int *  lineIndex 
)

Get the starting point for a character index (bottom left corner).

Definition at line 589 of file VuoImageText.cc.

◆ VuoImageTextData_getPositionForLineIndex()

VuoPoint2d VuoImageTextData_getPositionForLineIndex ( VuoImageTextData  textData,
unsigned int  lineIndex 
)

Get the origin point of a line of text (bottom left point of first character billboard in line).

Changed in Vuo 2.0.0:
New.

Definition at line 532 of file VuoImageText.cc.

◆ VuoImageTextData_getRectsForHighlight()

VuoRectangle* VuoImageTextData_getRectsForHighlight ( VuoImageTextData  textData,
unsigned int  selectionStartIndex,
unsigned int  selectionLength,
unsigned int *  lineCount 
)

Given a start index and length of selected characters return an array of VuoRectangles encompassing the selection.

Changed in Vuo 2.0.0:
New.

Definition at line 612 of file VuoImageText.cc.

◆ VuoImageTextData_layoutRowAtIndex()

VuoRectangle VuoImageTextData_layoutRowAtIndex ( VuoImageTextData  textData,
unsigned int  index,
unsigned int *  charactersRemaining 
)

Get a rect that contains a row of text starting at index.

The number of characters from index to line end is stored in length.

Changed in Vuo 2.0.0:
New.

Definition at line 674 of file VuoImageText.cc.

◆ VuoImageTextData_make()

VuoImageTextData VuoImageTextData_make ( )

Initialize a new instance of VuoImageTextData.

Definition at line 87 of file VuoImageText.cc.

Variable Documentation

◆ VuoImageTextCache

VuoImageTextCacheType* VuoImageTextCache
static

A pool of images.

Definition at line 122 of file VuoImageText.cc.

◆ VuoImageTextCache_canceledAndCompleted

dispatch_semaphore_t VuoImageTextCache_canceledAndCompleted
static

Signals when the last VuoImageTextCache cleanup has completed.

Definition at line 124 of file VuoImageText.cc.

◆ VuoImageTextCache_semaphore

dispatch_semaphore_t VuoImageTextCache_semaphore
static

Serializes access to VuoImageTextCache.

Definition at line 123 of file VuoImageText.cc.

◆ VuoImageTextCache_timeout

double VuoImageTextCache_timeout = 1.0
static

Seconds an image can remain in the cache unused, before it gets purged.

Definition at line 126 of file VuoImageText.cc.

◆ VuoImageTextCache_timer

volatile dispatch_source_t VuoImageTextCache_timer = NULL
static

Periodically cleans up VuoImageTextCache.

Definition at line 125 of file VuoImageText.cc.