mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-11-23 15:05:52 +00:00
CoreText.
Still needs a lot of work; there are bugs, performance issues, and missing features.
This commit is contained in:
1 parent
aac09d8208
commit
4d47b5abf5
6 files changed
+845
No files matched your search
@@ -0,0 +1,169 @@
|
||||
/*
|
||||
* CTFrame.j
|
||||
* CoreText
|
||||
*
|
||||
* Created by Nicholas Small.
|
||||
* Copyright 2011, 280 North, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import "CTLine.j"
|
||||
|
||||
|
||||
kCTFrameProgressionTopToBottom = 0;
|
||||
kCTFrameProgressionRightToLeft = 1;
|
||||
|
||||
kCTFrameProgressionAttributeName = @"kCTFrameProgressionAttributeName";
|
||||
|
||||
function _CTFrameCreate(aPath, attributes, lines, attributedString)
|
||||
{
|
||||
return {
|
||||
path: aPath,
|
||||
attributes: attributes,
|
||||
lines: lines,
|
||||
string: attributedString
|
||||
};
|
||||
}
|
||||
|
||||
_CTFrameCreate.displayName = @"_CTFrameCreate";
|
||||
|
||||
// Returns a CPRange
|
||||
function CTFrameGetStringRange(/* CTFrame */ aFrame)
|
||||
{
|
||||
return CPMakeRange();
|
||||
}
|
||||
|
||||
CTFrameGetStringRange.displayName = @"CTFrameGetStringRange";
|
||||
|
||||
// Returns a CPRange
|
||||
function CTFrameGetVisibleStringRange(/* CTFrame */ aFrame)
|
||||
{
|
||||
return CPMakeRange();
|
||||
}
|
||||
|
||||
CTFrameGetVisibleStringRange.displayName = @"CTFrameGetVisibleStringRange";
|
||||
|
||||
// Returns a CGPath
|
||||
function CTFrameGetPath(/* CTFrame */ aFrame)
|
||||
{
|
||||
return aFrame.path;
|
||||
}
|
||||
|
||||
CTFrameGetPath.displayName = @"CTFrameGetPath";
|
||||
|
||||
// Returns a CPDictionary
|
||||
function CTFrameGetFrameAttributes(/* CTFrame */ aFrame)
|
||||
{
|
||||
return aFrame.frameAttributes;
|
||||
}
|
||||
|
||||
CTFrameGetFrameAttributes.displayName = @"CTFrameGetFrameAttributes";
|
||||
|
||||
// Returns an array of CTLines
|
||||
function CTFrameGetLines(/* CTFrame */ aFrame)
|
||||
{
|
||||
return aFrame.lines;
|
||||
}
|
||||
|
||||
CTFrameGetLines.displayName = @"CTFrameGetLines";
|
||||
|
||||
// Returns an array of CGPoints
|
||||
function CTFrameGetLineOrigins(/* CTFrame */ aFrame, /* CPRange */ aRange)
|
||||
{
|
||||
var results = [],
|
||||
lines = aRange ? CTFrameGetLinesForRange(aFrame, aRange) : aFrame.lines;
|
||||
|
||||
for (var i = -1, count = lines.length; ++i < count;)
|
||||
results.push(lines[i].origin);
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
CTFrameGetLineOrigins.displayName = @"CTFrameGetLineOrigins";
|
||||
|
||||
// Returns an array of CTLines
|
||||
// Divergent from Cocoa and expensive.
|
||||
function CTFrameGetLinesForRange(/* CTFrame */ aFrame, /* CPRange */ lhs)
|
||||
{
|
||||
var lines = aFrame.lines, results = [];
|
||||
for (var i = -1, count = lines.length; ++i < count;)
|
||||
{
|
||||
var line = lines[i],
|
||||
rhs = CTLineGetStringRange(line);
|
||||
|
||||
if ((CPMaxRange(lhs) < rhs.location || CPMaxRange(rhs) < lhs.location) && result.length)
|
||||
break;
|
||||
|
||||
if (lhs.location >= rhs.location && rhs.location <= CPMaxRange(lhs) && CPMaxRange(rhs) > lhs.location)
|
||||
results.push(line);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
CTFrameGetLinesForRange.displayName = @"CTFrameGetLinesForRange";
|
||||
|
||||
// Returns a CPRange
|
||||
// This is divergent from Cocoa. It's a convenience method used in CPTextView.
|
||||
function CTFrameGetRangeForPoint(/* CTFrame */ aFrame, /* CGPoint */ aPoint)
|
||||
{
|
||||
var lines = aFrame.lines, y = aPoint.y;
|
||||
for (var i = -1, count = lines.length; ++i < count;)
|
||||
{
|
||||
var line = lines[i],
|
||||
bounds = CTLineGetImageBounds(line),
|
||||
lineY = line._startPosition.y;
|
||||
|
||||
if (y >= lineY && y < bounds.size.height + lineY)
|
||||
{
|
||||
// FIXME: we seem to be doing stuff like this with some frequency;
|
||||
// Maybe it should be normalized at an earlier point.
|
||||
var index = CTLineGetStringIndexForPosition(line, aPoint),
|
||||
range = CTLineGetStringRange(line);
|
||||
|
||||
range.location += index;
|
||||
range.length = 0;
|
||||
return range;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CTFrameGetRangeForPoint.displayName = @"CTFrameGetRangeForPoint";
|
||||
|
||||
function CTFrameDraw(/* CTFrame */ aFrame, /* CGContext */ aContext)
|
||||
{
|
||||
var origin = aFrame.path.start,
|
||||
lines = aFrame.lines;
|
||||
|
||||
CGContextSetTextPosition(aContext, origin.x, origin.y);
|
||||
|
||||
for (var i = -1, count = lines.length; ++i < count;)
|
||||
{
|
||||
var line = lines[i],
|
||||
alignment = [line.string attribute:@"alignment" atIndex:0 effectiveRange:CPMakeRange(0, 0)],
|
||||
position = CGContextGetTextPosition(aContext);
|
||||
|
||||
if (alignment === CPLeftTextAlignment)
|
||||
line.origin = CGPointMake(origin.x, position.y);
|
||||
else if (alignment === CPRightTextAlignment)
|
||||
line.origin = CGPointMake((aFrame.path.elements[1].x - origin.x * 2) - CTLineGetTypographicBounds(line).width, position.y);
|
||||
|
||||
CGContextSetTextPosition(aContext, line.origin.x, line.origin.y);
|
||||
CTLineDraw(line, aContext);
|
||||
}
|
||||
}
|
||||
|
||||
CTFrameDraw.displayName = @"CTFrameDraw";
|
||||
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* CTFramesetter.j
|
||||
* CoreText
|
||||
*
|
||||
* Created by Nicholas Small.
|
||||
* Copyright 2011, 280 North, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import "CTFrame.j"
|
||||
@import "CTTypesetter.j"
|
||||
|
||||
|
||||
// Returns a CTFramesetter
|
||||
function CTFramesetterCreateWithAttributedString(/* CPAttributedString */ aString)
|
||||
{
|
||||
return {
|
||||
string: aString,
|
||||
typesetter: CTTypesetterCreateWithAttributedString(aString)
|
||||
};
|
||||
}
|
||||
|
||||
CTFramesetterCreateWithAttributedString.displayName = @"CTFramesetterCreateWithAttributedString";
|
||||
|
||||
// Returns a CTFrame
|
||||
function CTFramesetterCreateFrame(/* CTFramesetter */ aFramesetter, /* CPRange */ aRange, /* CGPath */ aPath, /* CPDictionary */ frameAttributes)
|
||||
{
|
||||
if (aFramesetter._cachedFrame && [aFramesetter._cachedAttributes isEqual:frameAttributes])
|
||||
return aFramesetter._cachedFrame;
|
||||
|
||||
var attributedString = aRange ? [aFramesetter.string attributedSubstringFromRange:aRange] : aFramesetter.string,
|
||||
nonattributedString = [attributedString string],
|
||||
splitLines = nonattributedString.split(/\n|\r/g),
|
||||
lines = [];
|
||||
|
||||
var index = 0;
|
||||
for (var i = -1, count = splitLines.length; ++i < count;)
|
||||
{
|
||||
var length = splitLines[i].length;
|
||||
if (i !== count - 1)
|
||||
++length;
|
||||
|
||||
var range = CPMakeRange(index, length),
|
||||
line = CTLineCreateWithAttributedString([attributedString attributedSubstringFromRange:range]);
|
||||
|
||||
line.range = range; // FIXME: a couple hacks to make managing lines in CPTextView easier
|
||||
line.prevLine = lastLine;
|
||||
|
||||
if (lastLine)
|
||||
lastLine.nextLine = line;
|
||||
|
||||
lines.push(line);
|
||||
index += length;
|
||||
|
||||
var lastLine = line;
|
||||
}
|
||||
|
||||
return aFramesetter._cachedFrame = _CTFrameCreate(aPath, frameAttributes, lines);
|
||||
}
|
||||
|
||||
CTFramesetterCreateFrame.displayName = @"CTFramesetterCreateFrame";
|
||||
|
||||
// Returns a CTTypesetter
|
||||
function CTFramesetterGetTypesetter(/* CTFramesetter */ aFramesetter)
|
||||
{
|
||||
return aFramesetter.typesetter;
|
||||
}
|
||||
|
||||
CTFramesetterGetTypesetter.displayName = @"CTFramesetterGetTypesetter";
|
||||
|
||||
// Returns a CGSize
|
||||
function CTFramesetterSuggestFrameSizeWithConstraints(/* CTFramesetter */ aFramesetter, /* CPRange */ aRange, /* CPDictionary */ frameAttributes, /* CGSize */ constraints, /* {CPRange} */ fitRange)
|
||||
{
|
||||
var frame = CTFramesetterCreateFrame(aFramesetter, aRange, null, frameAttributes),
|
||||
lines = CTFrameGetLines(frame),
|
||||
width = 0.0,
|
||||
height = 0.0;
|
||||
|
||||
for (var i = -1, count = lines.length; ++i < count;)
|
||||
{
|
||||
var bounds = CTLineGetTypographicBounds(lines[i]);
|
||||
// var bounds = CTLineGetImageBounds(lines[i], [[CPGraphicsContext currentContext] graphicsPort]).size;
|
||||
width = MAX(width, bounds.width);
|
||||
height += bounds.lineHeight;
|
||||
// height += bounds.height;
|
||||
}
|
||||
|
||||
return CGSizeMake(width, height);
|
||||
}
|
||||
|
||||
CTFramesetterSuggestFrameSizeWithConstraints.displayName = @"CTFramesetterSuggestFrameSizeWithConstraints";
|
||||
|
||||
function CTFramesetterGetAttributedString(/* CTFramesetter */ aFramesetter)
|
||||
{
|
||||
return aFramesetter.string;
|
||||
}
|
||||
|
||||
CTFramesetterGetAttributedString.displayName = @"CTFramesetterGetAttributedString";
|
||||
@@ -0,0 +1,227 @@
|
||||
/*
|
||||
* CTLine.j
|
||||
* CoreText
|
||||
*
|
||||
* Created by Nicholas Small.
|
||||
* Copyright 2011, 280 North, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import "CTRun.j"
|
||||
|
||||
|
||||
kCTLineTruncationStart = 0;
|
||||
kCTLineTruncationEnd = 1;
|
||||
kCTLineTruncationMiddle = 2;
|
||||
|
||||
// Returns a CTLine
|
||||
function CTLineCreateWithAttributedString(/* CPAttributedString */ aString)
|
||||
{
|
||||
var line = {
|
||||
string: aString,
|
||||
runs: []
|
||||
};
|
||||
|
||||
_CTLineCreateRuns(line);
|
||||
|
||||
return line;
|
||||
}
|
||||
|
||||
CTLineCreateWithAttributedString.displayName = @"CTLineCreateWithAttributedString";
|
||||
|
||||
// Returns a CTLine
|
||||
function CTLineCreateTruncatedLine(/* CTLine */ aLine, /* float */ width, /* CTLineTruncationType */ truncationType, /* CTLine */ truncationToken)
|
||||
{
|
||||
return aLine;
|
||||
}
|
||||
|
||||
CTLineCreateTruncatedLine.displayName = @"CTLineCreateTruncatedLine";
|
||||
|
||||
// Returns a CTLine
|
||||
function CTLineCreateJustifiedLine(/* CTline */ aLine, /* float */ justificationFactor, /* float */ width)
|
||||
{
|
||||
return aLine;
|
||||
}
|
||||
|
||||
CTLineCreateJustifiedLine.displayName = @"CTLineCreateJustifiedLine";
|
||||
|
||||
// Returns an index
|
||||
function CTLineGetGlyphCount(/* CTLine */ aLine)
|
||||
{
|
||||
return [aLine.string length];
|
||||
}
|
||||
|
||||
CTLineGetGlyphCount.displayName = @"CTLineGetGlyphCount";
|
||||
|
||||
// Returns an array of CTGlyphRuns
|
||||
function CTLineGetGlyphRuns(/* CTLine */ aLine)
|
||||
{
|
||||
return aLine.runs;
|
||||
}
|
||||
|
||||
CTLineGetGlyphRuns.displayName = @"CTLineGetGlyphRuns";
|
||||
|
||||
// Returns a CPRange
|
||||
function CTLineGetStringRange(/* CTLine */ aLine)
|
||||
{
|
||||
return CPCopyRange(aLine.range) || CPMakeRange(0, [aLine.string length])
|
||||
}
|
||||
|
||||
CTLineGetStringRange.displayName = @"CTLineGetStringRange";
|
||||
|
||||
function CTLineGetPenOffsetForFlush(/* CTLine */ aLine, /* float */ flushFactor, /* float */ flushWidth)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CTLineGetPenOffsetForFlush.displayName = @"CTLineGetPenOffsetForFlush";
|
||||
|
||||
function CTLineDraw(/* CTLine */ aLine, /* CGContext */ aContext)
|
||||
{
|
||||
var startPosition = aLine._startPosition = CGContextGetTextPosition(aContext),
|
||||
height = CTLineGetImageBounds(aLine, aContext).size.height;
|
||||
|
||||
// FIXME: This is WRONG. This NEEDS to be in CGContext.
|
||||
CGContextSetTextPosition(aContext, startPosition.x, startPosition.y + height * 0.5);
|
||||
|
||||
var runs = aLine.runs;
|
||||
for (var i = -1, count = runs.length; ++i < count;)
|
||||
CTRunDraw(runs[i], aContext);
|
||||
|
||||
CGContextSetTextPosition(aContext, startPosition.x, startPosition.y + height);
|
||||
}
|
||||
|
||||
CTLineDraw.displayName = @"CTLineDraw";
|
||||
|
||||
// Returns a CGRect
|
||||
// Cheap
|
||||
function CTLineGetImageBounds(/* CTLine */ aLine, /* CGContext */ aContext)
|
||||
{
|
||||
if (aLine._imageBounds)
|
||||
return aLine._imageBounds;
|
||||
|
||||
var runs = aLine.runs,
|
||||
width = 0.0,
|
||||
height = 0.0;
|
||||
|
||||
for (var i = -1, count = runs.length; ++i < count;)
|
||||
{
|
||||
var runSize = CTRunGetImageBounds(runs[i], aContext).size;
|
||||
width += runSize.width;
|
||||
height = MAX(height, runSize.height);
|
||||
}
|
||||
|
||||
return aLine._imageBounds = CGRectMake(0.0, 0.0, width, height);
|
||||
}
|
||||
|
||||
CTLineGetImageBounds.displayName = @"CTLineGetImageBounds";
|
||||
|
||||
// Returns a JSObject: {width: float, ascent: float, descent: float, lineHeight: float}
|
||||
// More expensive
|
||||
function CTLineGetTypographicBounds(/* CTLine */ aLine)
|
||||
{
|
||||
if (aLine._typographicBounds)
|
||||
return aLine._typographicBounds;
|
||||
|
||||
var runs = aLine.runs,
|
||||
width = 0.0,
|
||||
ascent = 0.0,
|
||||
descent = 0.0,
|
||||
lineHeight = 0.0;
|
||||
|
||||
for (var i = -1, count = runs.length; ++i < count;)
|
||||
{
|
||||
var runObject = CTRunGetTypographicBounds(runs[i]);
|
||||
width += runObject.width;
|
||||
ascent = MAX(ascent, runObject.ascent);
|
||||
descent = MAX(descent, runObject.descent);
|
||||
lineHeight = MAX(lineHeight, runObject.lineHeight);
|
||||
}
|
||||
|
||||
return aLine._typographicBounds = {
|
||||
width: width,
|
||||
ascent: ascent,
|
||||
descent: descent,
|
||||
lineHeight: lineHeight
|
||||
};
|
||||
}
|
||||
|
||||
CTLineGetTypographicBounds.displayName = @"CTLineGetTypographicBounds";
|
||||
|
||||
// Returns an index
|
||||
function CTLineGetStringIndexForPosition(/* CTLine */ aLine, /* CGPoint */ aPoint)
|
||||
{
|
||||
var runs = aLine.runs, x = aPoint.x, index = 0;
|
||||
for (var i = -1, count = runs.length; ++i < count;)
|
||||
{
|
||||
var run = runs[i],
|
||||
origins = run.glyphOrigins;
|
||||
|
||||
for (var j = -1, jcount = origins.length; ++j < jcount;)
|
||||
{
|
||||
var origin = origins[j], next;
|
||||
if (j < jcount - 1)
|
||||
next = origins[j + 1];
|
||||
else if (i < count - 1)
|
||||
next = runs[i + 1].glyphOrigins[0];
|
||||
else
|
||||
return index++;
|
||||
|
||||
if (x <= (next.x - origin.x) / 2 + origin.x)
|
||||
return index;
|
||||
|
||||
index++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
CTLineGetStringIndexForPosition.displayName = @"CTLineGetStringIndexForPosition";
|
||||
|
||||
// Returns a float
|
||||
function CTLineGetOffsetForStringIndex(/* CTLine */ aLine, /* int */ anIndex, /* float */ secondaryOffset)
|
||||
{
|
||||
var runs = aLine.runs;
|
||||
for (var i = -1, count = runs.length; ++i < count;)
|
||||
{
|
||||
var run = runs[i], runRange = run.range;
|
||||
if (CPLocationInRange(anIndex, runRange))
|
||||
return run.glyphOrigins[anIndex - runRange.location];
|
||||
}
|
||||
}
|
||||
|
||||
CTLineGetOffsetForStringIndex.displayName = @"CTLineGetOffsetForStringIndex";
|
||||
|
||||
function _CTLineCreateRuns(aLine)
|
||||
{
|
||||
var string = aLine.string,
|
||||
runs = aLine.runs,
|
||||
rangeEntries = string._rangeEntries;
|
||||
|
||||
for (var i = -1, count = rangeEntries.length; ++i < count;)
|
||||
{
|
||||
var rangeEntry = rangeEntries[i],
|
||||
range = rangeEntry.range,
|
||||
rangeString = [[string string] substringWithRange:range],
|
||||
attributes = rangeEntry.attributes;
|
||||
|
||||
var run = _CTRunCreate(rangeString, attributes);
|
||||
run.range = range;
|
||||
|
||||
runs.push(run);
|
||||
}
|
||||
}
|
||||
|
||||
_CTLineCreateRuns.displayName = @"_CTLineCreateRuns";
|
||||
@@ -0,0 +1,249 @@
|
||||
/*
|
||||
* CTRun.j
|
||||
* CoreText
|
||||
*
|
||||
* Created by Nicholas Small.
|
||||
* Copyright 2011, 280 North, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
kCTRunStatusNoStatus = 0;
|
||||
kCTRunStatusRightToLeft = 1 << 0;
|
||||
kCTRunStatusNonMonotonic = 1 << 1;
|
||||
kCTRunStatusNonIdentityMatrix = 1 << 2;
|
||||
|
||||
function _CTRunCreate(glyphs, attributes)
|
||||
{
|
||||
return {
|
||||
glyphs: glyphs,
|
||||
attributes: attributes,
|
||||
status: kCTRunStatusNoStatus
|
||||
};
|
||||
}
|
||||
|
||||
_CTRunCreate.displayName = @"_CTRunCreate";
|
||||
|
||||
// Returns an index
|
||||
function CTRunGetGlyphCount(/* CTRun */ aRun)
|
||||
{
|
||||
return aRun.glyphs.length;
|
||||
}
|
||||
|
||||
CTRunGetGlyphCount.displayName = @"CTRunGetGlyphCount";
|
||||
|
||||
// Returns a CPDictionary
|
||||
function CTRunGetAttributes(/* CTRun */ aRun)
|
||||
{
|
||||
return aRun.attributes;
|
||||
}
|
||||
|
||||
CTRunGetAttributes.displayName = @"CTRunGetAttributes";
|
||||
|
||||
// Returns a CTRunStatus (int)
|
||||
function CTRunGetStatus(/* CTRun */ aRun)
|
||||
{
|
||||
return aRun.status || kCTRunStatusNoStatus;
|
||||
}
|
||||
|
||||
CTRunGetStatus.displayName = @"CTRunGetStatus";
|
||||
|
||||
// Returns an array of CGGlyphs
|
||||
function CTRunGetGlyphs(/* CTRun */ aRun, /* CPRange */ aRange)
|
||||
{
|
||||
if (!aRun.glyphs)
|
||||
aRun.glyphs = [];
|
||||
|
||||
return aRun.glyphs;
|
||||
}
|
||||
|
||||
CTRunGetGlyphs.displayName = @"CTRunGetGlyphs";
|
||||
|
||||
// Returns an array of CGPoints
|
||||
function CTRunGetPositions(/* CTRun */ aRun, /* CPRange */ aRange)
|
||||
{
|
||||
if (!aRun.positions)
|
||||
aRun.positions = [];
|
||||
|
||||
return aRun.positions;
|
||||
}
|
||||
|
||||
CTRunGetPositions.displayName = @"CTRunGetPositions";
|
||||
|
||||
// Returns an array of CGSizes
|
||||
function CTRunGetAdvances(/* CTRun */ aRun, /* CPRange */ aRange)
|
||||
{
|
||||
if (!aRun.advances)
|
||||
aRun.advances = [];
|
||||
|
||||
return aRun.advances;
|
||||
}
|
||||
|
||||
CTRunGetAdvances.displayName = @"CTRunGetAdvances";
|
||||
|
||||
// Returns an array of indexes
|
||||
function CTRunGetStringIndices(/* CTRun */ aRun, /* CPRange */ aRange)
|
||||
{
|
||||
if (!aRun.stringIndices)
|
||||
aRun.stringIndices = [];
|
||||
|
||||
return aRun.stringIndices;
|
||||
}
|
||||
|
||||
CTRunGetStringIndices.displayName = @"CTRunGetStringIndices";
|
||||
|
||||
// Returns a CPRange
|
||||
function CTRunGetStringRange(/* CTRun */ aRun)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CTRunGetStringRange.displayName = @"CTRunGetStringRange";
|
||||
|
||||
// Returns a JSObject: {width: float, ascender: float, descender: float, lineHeight: float}
|
||||
// More expensive
|
||||
function CTRunGetTypographicBounds(/* CTRun */ aRun, /* CPRange */ aRange)
|
||||
{
|
||||
if (aRun._typographicBounds)
|
||||
return aRun._typographicBounds;
|
||||
|
||||
var attributes = aRun.attributes,
|
||||
font = [attributes valueForKey:@"font"],
|
||||
string = _CTRunStringForRange(aRun, aRange);
|
||||
|
||||
return aRun._typographicBounds = {
|
||||
width: [string sizeWithFont:font].width, // FIXME: account for tabs
|
||||
ascender: [font ascender],
|
||||
descender: [font descender],
|
||||
lineHeight: [font defaultLineHeightForFont]
|
||||
};
|
||||
}
|
||||
|
||||
CTRunGetTypographicBounds.displayName = @"CTRunGetTypographicBounds";
|
||||
|
||||
// Returns a CGRect
|
||||
// Cheap
|
||||
function CTRunGetImageBounds(/* CTRun */ aRun, /* CGContext */ aContext, /* CPRange */ aRange)
|
||||
{
|
||||
if (aRun._imageBounds)
|
||||
return aRun._imageBounds;
|
||||
|
||||
_CTRunPrepareDraw(aRun, aContext);
|
||||
|
||||
var string = _CTRunStringForRange(aRun, aRange),
|
||||
width = aContext.measureText(string).width,
|
||||
height = [CGContextGetFont(aContext) defaultLineHeightForFont];
|
||||
|
||||
_CTRunUnprepareDraw(aRun, aContext);
|
||||
|
||||
return aRun._imageBounds = CGRectMake(0.0, 0.0, width, height);
|
||||
}
|
||||
|
||||
CTRunGetImageBounds.displayName = @"CTRunGetImageBounds";
|
||||
|
||||
// CGAffineTransform
|
||||
function CTRunGetTextMatrix(/* CTRun */ aRun)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CTRunGetTextMatrix.displayName = @"CTRunGetTextMatrix";
|
||||
|
||||
function CTRunDraw(/* CTRun */ aRun, /* CGContext */ aContext, /* CPRange */ aRange)
|
||||
{
|
||||
_CTRunPrepareDraw(aRun, aContext);
|
||||
|
||||
var string = aRange ? [aRun.glyphs substringWithRange:aRange] : aRun.glyphs;
|
||||
_CTRunDrawShadow(aRun, aContext, string);
|
||||
|
||||
var origins = aRun.glyphOrigins = [];
|
||||
for (var i = -1, count = string.length; ++i < count;)
|
||||
{
|
||||
var glyph = string[i];
|
||||
origins[i] = CGContextGetTextPosition(aContext);
|
||||
|
||||
CGContextShowText(aContext, glyph);
|
||||
}
|
||||
|
||||
_CTRunUnprepareDraw(aRun, aContext);
|
||||
}
|
||||
|
||||
CTRunDraw.displayName = @"CTRunDraw";
|
||||
|
||||
function _CTRunDrawShadow(aRun, aContext, aString)
|
||||
{
|
||||
var attributes = aRun.attributes,
|
||||
textShadowColor = [attributes valueForKey:@"text-shadow-color"],
|
||||
textShadowOffset = [attributes valueForKey:@"text-shadow-offset"];
|
||||
|
||||
if (textShadowColor && textShadowOffset)
|
||||
{
|
||||
var color = CGContextGetFillColor(aContext),
|
||||
position = CGContextGetTextPosition(aContext);
|
||||
|
||||
CGContextSetFillColor(aContext, textShadowColor);
|
||||
CGContextShowTextAtPoint(aContext, position.x + textShadowOffset.width, position.y + textShadowOffset.height, aString);
|
||||
|
||||
CGContextSetFillColor(aContext, color);
|
||||
CGContextSetTextPosition(aContext, position.x, position.y);
|
||||
}
|
||||
}
|
||||
|
||||
_CTRunDrawShadow.displayName = @"_CTRunDrawShadow";
|
||||
|
||||
function _CTRunPrepareDraw(aRun, aContext)
|
||||
{
|
||||
var attributes = aRun.attributes,
|
||||
font = [attributes valueForKey:@"font"],
|
||||
color = [attributes valueForKey:@"color"];
|
||||
|
||||
if (font)
|
||||
{
|
||||
CGContextSelectFont(aContext, font);
|
||||
aRun._cachedFont = CGContextGetFont(aContext);
|
||||
}
|
||||
|
||||
if (color)
|
||||
{
|
||||
CGContextSetFillColor(aContext, color);
|
||||
aRun._cachedColor = CGContextGetFillColor(aContext);
|
||||
}
|
||||
}
|
||||
|
||||
_CTRunPrepareDraw.displayName = @"_CTRunPrepareDraw";
|
||||
|
||||
function _CTRunUnprepareDraw(aRun, aContext)
|
||||
{
|
||||
if (aRun._cachedFont)
|
||||
{
|
||||
CGContextSelectFont(aContext, aRun._cachedFont);
|
||||
aRun._cachedFont = nil;
|
||||
}
|
||||
|
||||
if (aRun._cachedColor)
|
||||
{
|
||||
CGContextSetFillColor(aContext, aRun._cachedColor);
|
||||
aRun._cachedColor = nil;
|
||||
}
|
||||
}
|
||||
|
||||
_CTRunUnprepareDraw.displayName = @"_CTRunUnprepareDraw";
|
||||
|
||||
function _CTRunStringForRange(aRun, aRange)
|
||||
{
|
||||
return (!aRange || aRange.length === 0) ? aRun.glyphs : [aRun.glyphs substringWithRange:aRange];
|
||||
}
|
||||
|
||||
_CTRunStringForRange.displayName = @"_CTRunStringForRange";
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* CTTypesetter.j
|
||||
* CoreText
|
||||
*
|
||||
* Created by Nicholas Small.
|
||||
* Copyright 2011, 280 North, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import "CTLine.j"
|
||||
|
||||
|
||||
kCTTypesetterOptionDisableBidiProcessing = @"kCTTypesetterOptionDisableBidiProcessing";
|
||||
kCTTypesetterOptionForcedEmbeddingLevel = @"kCTTypesetterOptionForcedEmbeddingLevel";
|
||||
|
||||
// Returns a CTTypesetter
|
||||
function CTTypesetterCreateWithAttributedString(/* CPAttributedString */ aString)
|
||||
{
|
||||
return CTTypesetterCreateWithAttributedStringAndOptions(aString, nil);
|
||||
}
|
||||
|
||||
// Returns a CTTypesetter
|
||||
function CTTypesetterCreateWithAttributedStringAndOptions(/* CPAttributedString */ aString, /* CPDictionary */ aDictionary)
|
||||
{
|
||||
return {
|
||||
string: aString,
|
||||
options: aDictionary
|
||||
}
|
||||
}
|
||||
|
||||
// Returns a CTLine
|
||||
function CTTypesetterCreateLine(/* CTTypesetter */ aTypesetter, /* CPRange */ aRange)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Returns an index
|
||||
function CTTypesetterSuggestLineBreak(/* CTTypesetter */ aTypesetter, /* int */ startIndex, /* float */ width)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Returns an index
|
||||
function CTTypesetterSuggestClusterBreak(/* CTTypesetter */ aTypesetter, /* int */ startIndex, /* float */ width)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* CoreText.j
|
||||
* CoreText
|
||||
*
|
||||
* Created by Nicholas Small.
|
||||
* Copyright 2011, 280 North, Inc.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*/
|
||||
|
||||
@import "CTFramesetter.j"
|
||||
@import "CTFrame.j"
|
||||
@import "CTTypesetter.j"
|
||||
@import "CTLine.j"
|
||||
@import "CTRun.j"
|
||||
|
||||
@import "CGContextText.j"
|
||||
Reference in new issue
Block a user