mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 05:10:47 +00:00
Add support for for link attributes.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@33433 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
b7f57fe859
commit
394d42736a
2 changed files with 122 additions and 39 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2011-07-03 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Source/NSLayoutManager.m (-drawGlyphsForGlyphRange:atPoint:,
|
||||||
|
-drawUnderlineForGlyphRange:...:): Add support for for link attributes.
|
||||||
|
|
||||||
2011-07-03 Riccardo Mottola <rm@gnu.org>
|
2011-07-03 Riccardo Mottola <rm@gnu.org>
|
||||||
|
|
||||||
* Source/NSSliderCell.m:
|
* Source/NSSliderCell.m:
|
||||||
|
@ -73,7 +78,6 @@
|
||||||
In particular, the action now deletes the newline character when
|
In particular, the action now deletes the newline character when
|
||||||
the insertion point is at the end of a line.
|
the insertion point is at the end of a line.
|
||||||
|
|
||||||
>>>>>>> .r33429
|
|
||||||
2011-06-22 Fred Kiefer <FredKiefer@gmx.de>
|
2011-06-22 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Headers/AppKit/NSPrintPanel.h: Add missing APPKIT_EXPORT for new
|
* Headers/AppKit/NSPrintPanel.h: Add missing APPKIT_EXPORT for new
|
||||||
|
|
|
@ -1485,6 +1485,8 @@ attachmentSize(linefrag_t *lf, NSUInteger glyphIndex)
|
||||||
*/
|
*/
|
||||||
NSColor *defaultTextColor = [NSColor textColor];
|
NSColor *defaultTextColor = [NSColor textColor];
|
||||||
NSColor *selectedTextColor = defaultTextColor;
|
NSColor *selectedTextColor = defaultTextColor;
|
||||||
|
NSColor *link_color = nil;
|
||||||
|
id linkValue;
|
||||||
|
|
||||||
#define GBUF_SIZE 16 /* TODO: tweak */
|
#define GBUF_SIZE 16 /* TODO: tweak */
|
||||||
NSGlyph gbuf[GBUF_SIZE];
|
NSGlyph gbuf[GBUF_SIZE];
|
||||||
|
@ -1544,6 +1546,18 @@ attachmentSize(linefrag_t *lf, NSUInteger glyphIndex)
|
||||||
if (run_color == nil)
|
if (run_color == nil)
|
||||||
run_color = defaultTextColor;
|
run_color = defaultTextColor;
|
||||||
|
|
||||||
|
linkValue = [attributes objectForKey: NSLinkAttributeName];
|
||||||
|
if (linkValue != nil)
|
||||||
|
{
|
||||||
|
if (link_color == nil)
|
||||||
|
{
|
||||||
|
NSDictionary *link_attributes = [[self firstTextView] linkTextAttributes];
|
||||||
|
link_color = [link_attributes valueForKey: NSForegroundColorAttributeName];
|
||||||
|
}
|
||||||
|
if (link_color != nil)
|
||||||
|
run_color = link_color;
|
||||||
|
}
|
||||||
|
|
||||||
if (selectedGlyphRange.length > 0)
|
if (selectedGlyphRange.length > 0)
|
||||||
{
|
{
|
||||||
/* Get the text view's color setting for selected text as we will
|
/* Get the text view's color setting for selected text as we will
|
||||||
|
@ -1639,6 +1653,19 @@ attachmentSize(linefrag_t *lf, NSUInteger glyphIndex)
|
||||||
{
|
{
|
||||||
run_color = defaultTextColor;
|
run_color = defaultTextColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
linkValue = [attributes objectForKey: NSLinkAttributeName];
|
||||||
|
if (linkValue != nil)
|
||||||
|
{
|
||||||
|
if (link_color == nil)
|
||||||
|
{
|
||||||
|
NSDictionary *link_attributes = [[self firstTextView] linkTextAttributes];
|
||||||
|
link_color = [link_attributes valueForKey: NSForegroundColorAttributeName];
|
||||||
|
}
|
||||||
|
if (link_color != nil)
|
||||||
|
run_color = link_color;
|
||||||
|
}
|
||||||
|
|
||||||
glyph = glyph_run->glyphs;
|
glyph = glyph_run->glyphs;
|
||||||
|
|
||||||
/* If the font has changed or the color has changed (and we are
|
/* If the font has changed or the color has changed (and we are
|
||||||
|
@ -1752,14 +1779,37 @@ for (i = 0; i < gbuf_len; i++) printf(" %3i : %04x\n", i, gbuf[i]); */
|
||||||
{
|
{
|
||||||
const NSRange characterRange = [self characterRangeForGlyphRange: range
|
const NSRange characterRange = [self characterRangeForGlyphRange: range
|
||||||
actualGlyphRange: NULL];
|
actualGlyphRange: NULL];
|
||||||
|
id linkUnderlineValue = nil;
|
||||||
|
|
||||||
for (i=characterRange.location; i<NSMaxRange(characterRange); )
|
for (i=characterRange.location; i<NSMaxRange(characterRange); )
|
||||||
{
|
{
|
||||||
NSRange underlinedCharacterRange;
|
NSRange underlinedCharacterRange;
|
||||||
id underlineValue = [[self textStorage] attribute: NSUnderlineStyleAttributeName
|
NSRange linkCharacterRange;
|
||||||
atIndex: i
|
id underlineValue = nil;
|
||||||
longestEffectiveRange: &underlinedCharacterRange
|
|
||||||
inRange: characterRange];
|
linkValue = [_textStorage attribute: NSLinkAttributeName
|
||||||
|
atIndex: i
|
||||||
|
longestEffectiveRange: &linkCharacterRange
|
||||||
|
inRange: characterRange];
|
||||||
|
if (linkValue != nil)
|
||||||
|
{
|
||||||
|
if (linkUnderlineValue == nil)
|
||||||
|
{
|
||||||
|
NSDictionary *link_attributes = [[self firstTextView] linkTextAttributes];
|
||||||
|
linkUnderlineValue = [link_attributes valueForKey: NSUnderlineStyleAttributeName];
|
||||||
|
}
|
||||||
|
underlineValue = linkUnderlineValue;
|
||||||
|
underlinedCharacterRange = linkCharacterRange;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
underlineValue = [_textStorage attribute: NSUnderlineStyleAttributeName
|
||||||
|
atIndex: i
|
||||||
|
longestEffectiveRange: &underlinedCharacterRange
|
||||||
|
inRange: characterRange];
|
||||||
|
underlinedCharacterRange = NSIntersectionRange(underlinedCharacterRange,
|
||||||
|
linkCharacterRange);
|
||||||
|
}
|
||||||
if (underlineValue != nil && [underlineValue integerValue] != NSUnderlineStyleNone)
|
if (underlineValue != nil && [underlineValue integerValue] != NSUnderlineStyleNone)
|
||||||
{
|
{
|
||||||
const NSRange underlinedGylphRange = [self glyphRangeForCharacterRange: underlinedCharacterRange
|
const NSRange underlinedGylphRange = [self glyphRangeForCharacterRange: underlinedCharacterRange
|
||||||
|
@ -1916,6 +1966,7 @@ static void GSDrawPatternLine(NSPoint start, NSPoint end, NSInteger pattern, CGF
|
||||||
// contiguous regions with the same underline color.
|
// contiguous regions with the same underline color.
|
||||||
|
|
||||||
NSUInteger i;
|
NSUInteger i;
|
||||||
|
NSColor *link_color = nil;
|
||||||
const NSRange characterRange = [self characterRangeForGlyphRange: underlineRange
|
const NSRange characterRange = [self characterRangeForGlyphRange: underlineRange
|
||||||
actualGlyphRange: NULL];
|
actualGlyphRange: NULL];
|
||||||
|
|
||||||
|
@ -1926,56 +1977,84 @@ static void GSDrawPatternLine(NSPoint start, NSPoint end, NSInteger pattern, CGF
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=characterRange.location; i<NSMaxRange(characterRange); )
|
for (i = characterRange.location; i < NSMaxRange(characterRange); )
|
||||||
{
|
{
|
||||||
NSRange underlineColorCharacterRange, foregroundColorCharacterRange, rangeToDraw;
|
NSRange underlineColorCharacterRange, foregroundColorCharacterRange, rangeToDraw;
|
||||||
NSColor *underlineColor = (NSColor*)[[self textStorage] attribute: NSUnderlineColorAttributeName
|
NSColor *underlineColor = nil;
|
||||||
atIndex: i
|
NSRange glyphRangeToDraw;
|
||||||
longestEffectiveRange: &underlineColorCharacterRange
|
NSRange linkCharacterRange;
|
||||||
inRange: NSMakeRange(i, NSMaxRange(characterRange)-i)];
|
id linkValue;
|
||||||
NSColor *foregroundColor = (NSColor*)[[self textStorage] attribute: NSForegroundColorAttributeName
|
|
||||||
atIndex: i
|
linkValue = [_textStorage attribute: NSLinkAttributeName
|
||||||
longestEffectiveRange: &foregroundColorCharacterRange
|
atIndex: i
|
||||||
inRange: NSMakeRange(i, NSMaxRange(characterRange)-i)];
|
longestEffectiveRange: &linkCharacterRange
|
||||||
/*NSLog(@"asked to underline '%@'. at %d, ul color is %@ (%@) and fg color is %@ (%@)", [[[self textStorage] string] substringWithRange: characterRange],
|
inRange: NSMakeRange(i, NSMaxRange(characterRange)-i)];
|
||||||
i,
|
if (linkValue != nil)
|
||||||
underlineColor,
|
{
|
||||||
NSStringFromRange(underlineColorCharacterRange),
|
if (link_color == nil)
|
||||||
foregroundColor,
|
{
|
||||||
NSStringFromRange(foregroundColorCharacterRange));*/
|
NSDictionary *link_attributes = [[self firstTextView] linkTextAttributes];
|
||||||
|
link_color = [link_attributes valueForKey: NSForegroundColorAttributeName];
|
||||||
|
}
|
||||||
|
if (link_color != nil)
|
||||||
|
underlineColor = link_color;
|
||||||
|
|
||||||
|
underlineColorCharacterRange = linkCharacterRange;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
underlineColor = (NSColor*)[[self textStorage]
|
||||||
|
attribute: NSUnderlineColorAttributeName
|
||||||
|
atIndex: i
|
||||||
|
longestEffectiveRange: &underlineColorCharacterRange
|
||||||
|
inRange: NSMakeRange(i, NSMaxRange(characterRange)-i)];
|
||||||
|
underlineColorCharacterRange = NSIntersectionRange(underlineColorCharacterRange,
|
||||||
|
linkCharacterRange);
|
||||||
|
}
|
||||||
|
|
||||||
if (underlineColor != nil)
|
if (underlineColor != nil)
|
||||||
{
|
{
|
||||||
[underlineColor set];
|
[underlineColor set];
|
||||||
|
rangeToDraw = underlineColorCharacterRange;
|
||||||
}
|
}
|
||||||
else if (foregroundColor != nil)
|
else
|
||||||
{
|
{
|
||||||
[foregroundColor set];
|
NSColor *foregroundColor = (NSColor*)[[self textStorage]
|
||||||
}
|
attribute: NSForegroundColorAttributeName
|
||||||
else
|
atIndex: i
|
||||||
{
|
longestEffectiveRange: &foregroundColorCharacterRange
|
||||||
[[NSColor textColor] set];
|
inRange: NSMakeRange(i, NSMaxRange(characterRange)-i)];
|
||||||
}
|
|
||||||
|
|
||||||
// Draw the smaller range
|
if (foregroundColor != nil)
|
||||||
rangeToDraw = underlineColorCharacterRange.length < foregroundColorCharacterRange.length ?
|
{
|
||||||
underlineColorCharacterRange : foregroundColorCharacterRange;
|
[foregroundColor set];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[[NSColor textColor] set];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Draw the smaller range
|
||||||
|
rangeToDraw = underlineColorCharacterRange.length < foregroundColorCharacterRange.length ?
|
||||||
|
underlineColorCharacterRange : foregroundColorCharacterRange;
|
||||||
|
}
|
||||||
|
|
||||||
// do the actual underline
|
glyphRangeToDraw = [self glyphRangeForCharacterRange: rangeToDraw
|
||||||
{
|
actualCharacterRange: NULL];
|
||||||
|
if (glyphRangeToDraw.length > 0)
|
||||||
const NSRange glyphRangeToDraw = [self glyphRangeForCharacterRange: rangeToDraw
|
{
|
||||||
actualCharacterRange: NULL];
|
// do the actual underline
|
||||||
|
|
||||||
// FIXME: find the largest font within the range to underline
|
// FIXME: find the largest font within the range to underline
|
||||||
NSFont *largestFont = [self effectiveFontForGlyphAtIndex: glyphRangeToDraw.location // NOTE: GS private method
|
// NOTE: GS private method
|
||||||
range: NULL];
|
NSFont *largestFont = [self effectiveFontForGlyphAtIndex: glyphRangeToDraw.location
|
||||||
|
range: NULL];
|
||||||
|
|
||||||
const CGFloat underlineWidth = [largestFont pointSize] *
|
const CGFloat underlineWidth = [largestFont pointSize] *
|
||||||
(((type & NSUnderlineStyleDouble) != 0) ? 0.05 : 0.07);
|
(((type & NSUnderlineStyleDouble) != 0) ? 0.05 : 0.07);
|
||||||
|
|
||||||
NSPoint start = [self locationForGlyphAtIndex: glyphRangeToDraw.location];
|
NSPoint start = [self locationForGlyphAtIndex: glyphRangeToDraw.location];
|
||||||
NSPoint end = [self locationForGlyphAtIndex: NSMaxRange(glyphRangeToDraw) - 1]; //FIXME: check length > 0
|
NSPoint end = [self locationForGlyphAtIndex: NSMaxRange(glyphRangeToDraw) - 1];
|
||||||
|
|
||||||
// FIXME: remove this hack lowers the underline slightly
|
// FIXME: remove this hack lowers the underline slightly
|
||||||
start.y += [largestFont pointSize] * 0.07;
|
start.y += [largestFont pointSize] * 0.07;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue