mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 09:30:48 +00:00
Store the line frags array as an ivar instead of allocating and freeing it everytime -layoutLineNewParagraph: is called.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@15977 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
27e5baeab3
commit
7e1801395c
3 changed files with 44 additions and 32 deletions
|
@ -1,3 +1,10 @@
|
||||||
|
2003-02-16 17:48 Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
|
||||||
|
* Headers/gnustep/gui/GSHorizontalTypesetter.h,
|
||||||
|
Source/GSHorizontalTypesetter.m: Store the line frags array as
|
||||||
|
an ivar instead of allocating and freeing it everytime
|
||||||
|
-layoutLineNewParagraph: is called.
|
||||||
|
|
||||||
2003-02-16 15:51 Alexander Malmberg <alexander@malmberg.org>
|
2003-02-16 15:51 Alexander Malmberg <alexander@malmberg.org>
|
||||||
|
|
||||||
* Source/NSLayoutManager.m: Bring back the old implementation of
|
* Source/NSLayoutManager.m: Bring back the old implementation of
|
||||||
|
|
|
@ -65,6 +65,10 @@
|
||||||
struct GSHorizontalTypesetter_glyph_cache_s *cache;
|
struct GSHorizontalTypesetter_glyph_cache_s *cache;
|
||||||
unsigned int cache_base, cache_size, cache_length;
|
unsigned int cache_base, cache_size, cache_length;
|
||||||
BOOL at_end;
|
BOOL at_end;
|
||||||
|
|
||||||
|
|
||||||
|
struct GSHorizontalTypesetter_line_frag_s *line_frags;
|
||||||
|
int line_frags_num, line_frags_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
+(GSHorizontalTypesetter *) sharedInstance;
|
+(GSHorizontalTypesetter *) sharedInstance;
|
||||||
|
|
|
@ -65,6 +65,11 @@ cache fairly aggressively without having to worry about memory consumption.
|
||||||
free(cache);
|
free(cache);
|
||||||
cache = NULL;
|
cache = NULL;
|
||||||
}
|
}
|
||||||
|
if (line_frags)
|
||||||
|
{
|
||||||
|
free(line_frags);
|
||||||
|
line_frags = NULL;
|
||||||
|
}
|
||||||
DESTROY(lock);
|
DESTROY(lock);
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
|
@ -270,7 +275,7 @@ including gi will have been cached.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct GSHorizontalTypesetter_line_frag_s
|
||||||
{
|
{
|
||||||
NSRect rect;
|
NSRect rect;
|
||||||
float last_used;
|
float last_used;
|
||||||
|
@ -380,9 +385,6 @@ typedef struct
|
||||||
*/
|
*/
|
||||||
#define COMPUTE_BASELINE baseline = line_height - descender
|
#define COMPUTE_BASELINE baseline = line_height - descender
|
||||||
|
|
||||||
line_frag_t *line_frags = NULL;
|
|
||||||
int num_line_frags = 0;
|
|
||||||
|
|
||||||
|
|
||||||
[self _cacheMoveTo: curGlyph];
|
[self _cacheMoveTo: curGlyph];
|
||||||
if (!cache_length)
|
if (!cache_length)
|
||||||
|
@ -457,26 +459,25 @@ restart:
|
||||||
rects (eg. a text container with "hole"-columns every 100 points and
|
rects (eg. a text container with "hole"-columns every 100 points and
|
||||||
width 1e8)
|
width 1e8)
|
||||||
*/
|
*/
|
||||||
num_line_frags = 0;
|
line_frags_num = 0;
|
||||||
if (line_frags)
|
|
||||||
{
|
|
||||||
free(line_frags);
|
|
||||||
line_frags = NULL;
|
|
||||||
}
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
rect = [curTextContainer lineFragmentRectForProposedRect: remain
|
rect = [curTextContainer lineFragmentRectForProposedRect: remain
|
||||||
sweepDirection: NSLineSweepRight
|
sweepDirection: NSLineSweepRight
|
||||||
movementDirection: num_line_frags?NSLineDoesntMove:NSLineMoveDown
|
movementDirection: line_frags_num?NSLineDoesntMove:NSLineMoveDown
|
||||||
remainingRect: &remain];
|
remainingRect: &remain];
|
||||||
if (NSEqualRects(rect,NSZeroRect))
|
if (NSEqualRects(rect,NSZeroRect))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
num_line_frags++;
|
line_frags_num++;
|
||||||
line_frags = realloc(line_frags,sizeof(line_frag_t) * num_line_frags);
|
if (line_frags_num > line_frags_size)
|
||||||
line_frags[num_line_frags - 1].rect = rect;
|
{
|
||||||
|
line_frags_size += 2;
|
||||||
|
line_frags = realloc(line_frags, sizeof(line_frag_t) * line_frags_size);
|
||||||
|
}
|
||||||
|
line_frags[line_frags_num - 1].rect = rect;
|
||||||
}
|
}
|
||||||
if (!num_line_frags)
|
if (!line_frags_num)
|
||||||
{
|
{
|
||||||
if (curPoint.y == 0.0 &&
|
if (curPoint.y == 0.0 &&
|
||||||
line_height > [curTextContainer containerSize].height)
|
line_height > [curTextContainer containerSize].height)
|
||||||
|
@ -820,7 +821,7 @@ restart:
|
||||||
|
|
||||||
lf++;
|
lf++;
|
||||||
lfi++;
|
lfi++;
|
||||||
if (lfi == num_line_frags)
|
if (lfi == line_frags_num)
|
||||||
{
|
{
|
||||||
newParagraph = NO;
|
newParagraph = NO;
|
||||||
break;
|
break;
|
||||||
|
@ -847,26 +848,26 @@ restart:
|
||||||
/* Basic layout is done. */
|
/* Basic layout is done. */
|
||||||
|
|
||||||
/* Take care of the alignments. */
|
/* Take care of the alignments. */
|
||||||
if (lfi != num_line_frags)
|
if (lfi != line_frags_num)
|
||||||
{
|
{
|
||||||
lf->last_glyph = i;
|
lf->last_glyph = i;
|
||||||
lf->last_used = p.x;
|
lf->last_used = p.x;
|
||||||
|
|
||||||
/* TODO: incorrect if there is more than one line frag */
|
/* TODO: incorrect if there is more than one line frag */
|
||||||
if ([curParagraphStyle alignment] == NSRightTextAlignment)
|
if ([curParagraphStyle alignment] == NSRightTextAlignment)
|
||||||
[self rightAlignLine: line_frags : num_line_frags];
|
[self rightAlignLine: line_frags : line_frags_num];
|
||||||
else if ([curParagraphStyle alignment] == NSCenterTextAlignment)
|
else if ([curParagraphStyle alignment] == NSCenterTextAlignment)
|
||||||
[self centerAlignLine: line_frags : num_line_frags];
|
[self centerAlignLine: line_frags : line_frags_num];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ([curParagraphStyle lineBreakMode] == NSLineBreakByWordWrapping &&
|
if ([curParagraphStyle lineBreakMode] == NSLineBreakByWordWrapping &&
|
||||||
[curParagraphStyle alignment] == NSJustifiedTextAlignment)
|
[curParagraphStyle alignment] == NSJustifiedTextAlignment)
|
||||||
[self fullJustifyLine: line_frags : num_line_frags];
|
[self fullJustifyLine: line_frags : line_frags_num];
|
||||||
else if ([curParagraphStyle alignment] == NSRightTextAlignment)
|
else if ([curParagraphStyle alignment] == NSRightTextAlignment)
|
||||||
[self rightAlignLine: line_frags : num_line_frags];
|
[self rightAlignLine: line_frags : line_frags_num];
|
||||||
else if ([curParagraphStyle alignment] == NSCenterTextAlignment)
|
else if ([curParagraphStyle alignment] == NSCenterTextAlignment)
|
||||||
[self centerAlignLine: line_frags : num_line_frags];
|
[self centerAlignLine: line_frags : line_frags_num];
|
||||||
|
|
||||||
lfi--;
|
lfi--;
|
||||||
}
|
}
|
||||||
|
@ -895,10 +896,16 @@ restart:
|
||||||
usedRect: used_rect];
|
usedRect: used_rect];
|
||||||
p = g->pos;
|
p = g->pos;
|
||||||
/* TODO: probably don't need to call unless the flags are YES */
|
/* TODO: probably don't need to call unless the flags are YES */
|
||||||
[curLayoutManager setDrawsOutsideLineFragment: g->outside_line_frag
|
if (g->outside_line_frag)
|
||||||
forGlyphAtIndex: cache_base + i];
|
{
|
||||||
[curLayoutManager setNotShownAttribute: g->dont_show
|
[curLayoutManager setDrawsOutsideLineFragment: YES
|
||||||
forGlyphAtIndex: cache_base + i];
|
forGlyphAtIndex: cache_base + i];
|
||||||
|
}
|
||||||
|
if (g->dont_show)
|
||||||
|
{
|
||||||
|
[curLayoutManager setNotShownAttribute: YES
|
||||||
|
forGlyphAtIndex: cache_base + i];
|
||||||
|
}
|
||||||
p.y += baseline;
|
p.y += baseline;
|
||||||
j = i;
|
j = i;
|
||||||
while (i < lf->last_glyph)
|
while (i < lf->last_glyph)
|
||||||
|
@ -935,12 +942,6 @@ restart:
|
||||||
|
|
||||||
curPoint = NSMakePoint(0,NSMaxY(line_frags->rect));
|
curPoint = NSMakePoint(0,NSMaxY(line_frags->rect));
|
||||||
|
|
||||||
if (line_frags)
|
|
||||||
{
|
|
||||||
free(line_frags);
|
|
||||||
line_frags = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Check if we're at the end. */
|
/* Check if we're at the end. */
|
||||||
{
|
{
|
||||||
BOOL valid;
|
BOOL valid;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue