* Source/GSLayoutManager.m (-advancementForGlyphAtIndex:):

Simplify this method and move it in the file.
	* Source/NSLayoutManager.m: Use the pre-computed advancement
	instead of calculating it every time.


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@40167 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
fredkiefer 2016-10-23 20:13:37 +00:00
parent 99929f0781
commit 541a75bf97
3 changed files with 28 additions and 60 deletions

View file

@ -1,3 +1,10 @@
2016-10-23 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSLayoutManager.m (-advancementForGlyphAtIndex:):
Simplify this method and move it in the file.
* Source/NSLayoutManager.m: Use the pre-computed advancement
instead of calculating it every time.
2016-10-22 Fred Kiefer <FredKiefer@gmx.de>
* Source/GSLayoutManager.m: Don't try to get the advancement for

View file

@ -986,43 +986,6 @@ Fills in all glyph holes up to last. only looking at levels below level
return cpos + r->glyphs[glyphIndex - pos].char_offset;
}
/**
* GNUstep extension
*/
- (NSSize) advancementForGlyphAtIndex: (unsigned int)glyphIndex
{
glyph_run_t *r;
unsigned int pos, cpos;
if (glyphs->glyph_length <= glyphIndex)
{
[self _generateGlyphsUpToGlyph: glyphIndex];
if (glyphs->glyph_length <= glyphIndex)
{
[NSException raise: NSRangeException
format: @"%s glyph index out of range", __PRETTY_FUNCTION__];
return NSMakeSize(0,0);
}
}
r = run_for_glyph_index(glyphIndex, glyphs, &pos, &cpos);
if (!r)
{
[NSException raise: NSRangeException
format: @"%s glyph index out of range", __PRETTY_FUNCTION__];
return NSMakeSize(0,0);
}
if (r->head.glyph_length <= glyphIndex - pos)
{
[NSException raise: NSRangeException
format: @"%s internal error!", __PRETTY_FUNCTION__];
return NSMakeSize(0,0);
}
return r->glyphs[glyphIndex - pos].advancement;
}
- (NSRange) characterRangeForGlyphRange: (NSRange)glyphRange
actualGlyphRange: (NSRange *)actualGlyphRange
{
@ -1679,6 +1642,15 @@ places where we switch.
return r->font;
}
/**
* GNUstep extension
*/
- (NSSize) advancementForGlyphAtIndex: (unsigned int)idx
{
GET_GLYPH
return r->glyphs[idx].advancement;
}
- (void) insertGlyph: (NSGlyph)aGlyph
atGlyphIndex: (unsigned int)glyphIndex
characterIndex: (unsigned int)charIndex

View file

@ -193,7 +193,6 @@ first. Remaining cases, highest priority first:
{
NSRange r;
NSPoint p;
NSFont *f;
NSUInteger i;
r = [self rangeOfNominallySpacedGlyphsContainingIndex: glyphIndex
@ -205,19 +204,9 @@ first. Remaining cases, highest priority first:
return NSMakePoint(0, 0);
}
i = r.location;
f = [self effectiveFontForGlyphAtIndex: i
range: &r];
/* TODO: this is rather inefficient and doesn't deal with non-shown
glyphs */
for (; i < glyphIndex; i++)
for (i = r.location; i < glyphIndex; i++)
{
if (i == r.location + r.length)
{
f = [self effectiveFontForGlyphAtIndex: i
range: &r];
}
p.x += [f advancementForGlyph: [self glyphAtIndex: i]].width;
p.x += [self advancementForGlyphAtIndex: i].width;
}
return p;
}
@ -330,7 +319,7 @@ container? necessary? */
if (!r->glyphs[i].isNotShown && r->glyphs[i].g &&
r->glyphs[i].g != NSControlGlyph)
{
x0 += [r->font advancementForGlyph: r->glyphs[i].g].width;
x0 += r->glyphs[i].advancement.width;
}
GLYPH_STEP_FORWARD(r, i, gpos, cpos)
}
@ -377,7 +366,7 @@ container? necessary? */
if (!r->glyphs[i].isNotShown && r->glyphs[i].g &&
r->glyphs[i].g != NSControlGlyph)
{
x1 += [r->font advancementForGlyph: r->glyphs[i].g].width;
x1 += r->glyphs[i].advancement.width;
}
GLYPH_STEP_FORWARD(r, i, gpos, cpos)
}
@ -777,7 +766,7 @@ anything visible
}
last_visible = j + glyph_pos;
cur = prev + [r->font advancementForGlyph: r->glyphs[j].g].width;
cur = prev + r->glyphs[j].advancement.width;
if (j + glyph_pos + 1 == lp->pos + lp->length && next > cur)
cur = next;
@ -960,7 +949,7 @@ has the same y origin and height as the line frag rect it is in.
if (!r->glyphs[i].isNotShown && r->glyphs[i].g &&
r->glyphs[i].g != NSControlGlyph)
{
x0 += [r->font advancementForGlyph: r->glyphs[i].g].width;
x0 += r->glyphs[i].advancement.width;
}
GLYPH_STEP_FORWARD(r, i, gpos, cpos)
}
@ -968,7 +957,7 @@ has the same y origin and height as the line frag rect it is in.
if (!r->glyphs[i].isNotShown && r->glyphs[i].g &&
r->glyphs[i].g != NSControlGlyph)
{
x1 += [r->font advancementForGlyph: r->glyphs[i].g].width;
x1 += r->glyphs[i].advancement.width;
}
}
@ -1864,7 +1853,7 @@ attachmentSize(linefrag_t *lf, NSUInteger glyphIndex)
if (!gbuf_len)
{
gbuf[0] = glyph->g;
advancementbuf[0] = [f advancementForGlyph: glyph->g];
advancementbuf[0] = glyph->advancement;
gbuf_point = p;
gbuf_len = 1;
}
@ -1879,11 +1868,11 @@ attachmentSize(linefrag_t *lf, NSUInteger glyphIndex)
gbuf_point = p;
}
gbuf[gbuf_len] = glyph->g;
advancementbuf[gbuf_len] = [f advancementForGlyph: glyph->g];
advancementbuf[gbuf_len] = glyph->advancement;
gbuf_len++;
}
}
p.x += [f advancementForGlyph: glyph->g].width;
p.x += glyph->advancement.width;
}
}
if (gbuf_len)
@ -2184,7 +2173,7 @@ static void GSDrawPatternLine(NSPoint start, NSPoint end, NSInteger pattern, CGF
start.y += [largestFont pointSize] * 0.07;
end.y += [largestFont pointSize] * 0.07;
end.x += [largestFont advancementForGlyph: [self glyphAtIndex: (NSMaxRange(glyphRangeToDraw) - 1)]].width;
end.x += [self advancementForGlyphAtIndex: (NSMaxRange(glyphRangeToDraw) - 1)].width;
start = NSMakePoint(start.x + containerOrigin.x + fragmentRect.origin.x, start.y + containerOrigin.y + fragmentRect.origin.y);
end = NSMakePoint(end.x + containerOrigin.x + fragmentRect.origin.x, end.y + containerOrigin.y + fragmentRect.origin.y);
@ -2234,7 +2223,7 @@ static void GSDrawPatternLine(NSPoint start, NSPoint end, NSInteger pattern, CGF
start.y += [largestFont pointSize] * 0.07;
end.y += [largestFont pointSize] * 0.07;
end.x += [largestFont advancementForGlyph: [self glyphAtIndex: (NSMaxRange(range) - 1)]].width;
end.x += [self advancementForGlyphAtIndex: (NSMaxRange(range) - 1)].width;
start = NSMakePoint(start.x + containerOrigin.x + fragmentRect.origin.x, start.y + containerOrigin.y + fragmentRect.origin.y);
end = NSMakePoint(end.x + containerOrigin.x + fragmentRect.origin.x, end.y + containerOrigin.y + fragmentRect.origin.y);