mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 19:10:48 +00:00
Added drawing code for text attachments (Still untested, as there
is a problem with unicode characters in NSAttributedString) git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10071 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
9e915128f3
commit
f2074e78b6
1 changed files with 53 additions and 5 deletions
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include <Foundation/Foundation.h>
|
#include <Foundation/Foundation.h>
|
||||||
#include <AppKit/NSStringDrawing.h>
|
#include <AppKit/NSStringDrawing.h>
|
||||||
|
#include <AppKit/NSTextAttachment.h>
|
||||||
#include <AppKit/AppKit.h>
|
#include <AppKit/AppKit.h>
|
||||||
#include "GSTextStorage.h"
|
#include "GSTextStorage.h"
|
||||||
|
|
||||||
|
@ -129,6 +130,7 @@ typedef struct GSTextRunStruct {
|
||||||
float width; // Width of entire run.
|
float width; // Width of entire run.
|
||||||
float height; // Height of entire run.
|
float height; // Height of entire run.
|
||||||
float baseline; // Where to draw glyphs.
|
float baseline; // Where to draw glyphs.
|
||||||
|
// These fields are for normal glyphs
|
||||||
NSFont *font;
|
NSFont *font;
|
||||||
NSColor *bg;
|
NSColor *bg;
|
||||||
NSColor *fg;
|
NSColor *fg;
|
||||||
|
@ -137,10 +139,32 @@ typedef struct GSTextRunStruct {
|
||||||
float base;
|
float base;
|
||||||
float kern;
|
float kern;
|
||||||
int ligature;
|
int ligature;
|
||||||
|
// Fields for special glyphs
|
||||||
|
id <NSTextAttachmentCell> cell;
|
||||||
|
unsigned charIndex;
|
||||||
|
|
||||||
|
// Forward and backward link
|
||||||
struct GSTextRunStruct *last;
|
struct GSTextRunStruct *last;
|
||||||
struct GSTextRunStruct *next;
|
struct GSTextRunStruct *next;
|
||||||
} GSTextRun;
|
} GSTextRun;
|
||||||
|
|
||||||
|
static void
|
||||||
|
drawSpecialRun(GSTextRun *run, NSPoint origin, GSDrawInfo *draw)
|
||||||
|
{
|
||||||
|
// Currently this is only used for attachments
|
||||||
|
id <NSTextAttachmentCell> cell = run->cell;
|
||||||
|
unsigned charIndex = run->charIndex;
|
||||||
|
NSRect cellFrame = NSMakeRect(origin.x, origin.y,
|
||||||
|
run->glyphs[0].adv.width,
|
||||||
|
run->glyphs[0].adv.height);
|
||||||
|
NSView *controlView = [draw->ctxt focusView];
|
||||||
|
|
||||||
|
[cell drawWithFrame: cellFrame
|
||||||
|
inView: controlView
|
||||||
|
characterIndex: charIndex
|
||||||
|
layoutManager: nil];
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
drawRun(GSTextRun *run, NSPoint origin, GSDrawInfo *draw)
|
drawRun(GSTextRun *run, NSPoint origin, GSDrawInfo *draw)
|
||||||
{
|
{
|
||||||
|
@ -156,6 +180,13 @@ drawRun(GSTextRun *run, NSPoint origin, GSDrawInfo *draw)
|
||||||
{
|
{
|
||||||
origin.y += run->base;
|
origin.y += run->base;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (run->glyphs[0].glyph == NSControlGlyph)
|
||||||
|
{
|
||||||
|
drawSpecialRun(run, origin, draw);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Set current font and color if necessary.
|
* Set current font and color if necessary.
|
||||||
*/
|
*/
|
||||||
|
@ -228,11 +259,6 @@ drawRun(GSTextRun *run, NSPoint origin, GSDrawInfo *draw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
/* FIXME: Hack to force DGS to flush the text */
|
|
||||||
DPSrectfill(draw->ctxt, 0, 0, 0.5, 0.5);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (run->underline)
|
if (run->underline)
|
||||||
{
|
{
|
||||||
DPSmoveto(draw->ctxt, origin.x, origin.y);
|
DPSmoveto(draw->ctxt, origin.x, origin.y);
|
||||||
|
@ -240,6 +266,22 @@ drawRun(GSTextRun *run, NSPoint origin, GSDrawInfo *draw)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
setupSpecialRun(GSTextRun *run, unsigned length, unichar *chars, unsigned pos,
|
||||||
|
NSDictionary *attr)
|
||||||
|
{
|
||||||
|
NSTextAttachment *attachment = [attr objectForKey: NSAttachmentAttributeName];
|
||||||
|
|
||||||
|
run->cell = [attachment attachmentCell];
|
||||||
|
run->charIndex = pos;
|
||||||
|
run->glyphs[0].glyph = NSControlGlyph;
|
||||||
|
// We should better call the cellFrameForTextContainer:... method here
|
||||||
|
run->glyphs[0].adv = [run->cell cellSize];
|
||||||
|
|
||||||
|
run->baseline = [run->cell cellBaselineOffset].y;
|
||||||
|
run->height = run->glyphs[0].adv.height;
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
setupRun(GSTextRun *run, unsigned length, unichar *chars, unsigned pos,
|
setupRun(GSTextRun *run, unsigned length, unichar *chars, unsigned pos,
|
||||||
NSDictionary *attr, GSGlyphArray *g, GSTextRun *last)
|
NSDictionary *attr, GSGlyphArray *g, GSTextRun *last)
|
||||||
|
@ -264,6 +306,12 @@ setupRun(GSTextRun *run, unsigned length, unichar *chars, unsigned pos,
|
||||||
run->glyphs = &g->glyphs[g->used];
|
run->glyphs = &g->glyphs[g->used];
|
||||||
g->used += run->glyphCount;
|
g->used += run->glyphCount;
|
||||||
|
|
||||||
|
if (chars[0] == NSAttachmentCharacter)
|
||||||
|
{
|
||||||
|
setupSpecialRun(run, length, chars, pos, attr);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Get font to be used by characters in run.
|
// Get font to be used by characters in run.
|
||||||
run->font = (NSFont*)[attr objectForKey: NSFontAttributeName];
|
run->font = (NSFont*)[attr objectForKey: NSFontAttributeName];
|
||||||
if (run->font == nil)
|
if (run->font == nil)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue