Fixed: Added underline support in CPTextView (#2875)

This commit is contained in:
jasperdeb authored and Martin Carlberg committed 2019-12-06 09:12:31 +01:00
1 parent fed0703ecf
commit 58c08cebd7
4 files changed
+55 -18

No files matched your search

+12
View File
@@ -84,6 +84,18 @@ CPCenterTextAlignment = 2;
CPJustifiedTextAlignment = 3;
CPNaturalTextAlignment = 4;
@typedef CPUnderlineStyle
CPUnderlineStyleNone = 0;
CPUnderlineStyleSingle = 1;
CPUnderlineStyleThick = 2;
CPUnderlineStyleDouble = 3;
CPUnderlineStylePatternSolid = 4;
CPUnderlineStylePatternDot = 5;
CPUnderlineStylePatternDash = 6;
CPUnderlineStylePatternDashDot = 7;
CPUnderlineStylePatternDashDotDot = 8;
CPUnderlineStyleByWord = 9;
/*
CPText notifications
*/
+33 -14
View File
@@ -495,16 +495,6 @@ _oncontextmenuhandler = function () { return false; };
}
- (void)drawUnderlineForGlyphRange:(CPRange)glyphRange
underlineType:(int)underlineVal
baselineOffset:(float)baselineOffset
lineFragmentRect:(CGRect)lineFragmentRect
lineFragmentGlyphRange:(CPRange)lineGlyphRange
containerOrigin:(CGPoint)containerOrigin
{
// FIXME
}
- (void)drawGlyphsForGlyphRange:(CPRange)aRange atPoint:(CGPoint)aPoint
{
var lineFragments = _objectsInRange(_lineFragments, aRange);
@@ -1094,6 +1084,11 @@ var _objectsInRange = function(aList, aRange)
#pragma mark Init methods
- (id)createDOMElementWithText:(CPString)aString andFont:(CPFont)aFont andColor:(CPColor)aColor
{
return [self createDOMElementWithText:aString andFont:aFont andColor:aColor andUnderline:nil];
}
- (id)createDOMElementWithText:(CPString)aString andFont:(CPFont)aFont andColor:(CPColor)aColor andUnderline:(CPUnderlineStyle)aUnderline
{
#if PLATFORM(DOM)
var style,
@@ -1110,6 +1105,30 @@ var _objectsInRange = function(aList, aRange)
style.whiteSpace = "pre";
style.backgroundColor = "transparent";
style.font = [aFont cssString];
if (aUnderline)
{
style.textDecoration = "underline";
switch (aUnderline)
{
case CPUnderlineStyleSingle:
style.textDecorationStyle = "solid";
break;
case CPUnderlineStyleDouble:
style.textDecorationStyle = "double";
break;
case CPUnderlineStylePatternDot:
style.textDecorationStyle = "dotted";
break;
case CPUnderlineStylePatternDash:
style.textDecorationStyle = "dashed";
break;
}
}
if (aColor)
style.color = [aColor cssString];
@@ -1148,14 +1167,14 @@ var _objectsInRange = function(aList, aRange)
effectiveRange = attributes ? CPIntersectionRange(aRange, effectiveRange) : aRange;
var string = [textStorage._string substringWithRange:effectiveRange],
font = [textStorage font] || [CPFont systemFontOfSize:12.0];
font = [textStorage font] || [CPFont systemFontOfSize:12.0],
underline = [attributes objectForKey:CPUnderlineStyleAttributeName] || CPUnderlineStyleNone ;
if ([attributes containsKey:CPFontAttributeName])
font = [attributes objectForKey:CPFontAttributeName];
var color = [attributes objectForKey:CPForegroundColorAttributeName],
elem = [self createDOMElementWithText:string andFont:font andColor:color],
run = {_range:CPMakeRangeCopy(effectiveRange), color:color, font:font, elem:nil, string:string};
run = {_range:CPMakeRangeCopy(effectiveRange), color:color, font:font, elem:nil, string:string, underline:underline};
_runs.push(run);
@@ -1248,7 +1267,7 @@ var _objectsInRange = function(aList, aRange)
if (!run.elem && CPRectIntersectsRect([_textContainer._textView exposedRect], _fragmentRect))
{
run.elem=[self createDOMElementWithText:run.string andFont:run.font andColor:run.color];
run.elem=[self createDOMElementWithText:run.string andFont:run.font andColor:run.color andUnderline:run.underline];
}
if (run.DOMactive && !run.DOMpatched)
+3 -3
View File
@@ -1922,14 +1922,14 @@ Sets the selection to a range of characters in response to user action.
if ([attrib containsKey:CPUnderlineStyleAttributeName] && [[attrib objectForKey:CPUnderlineStyleAttributeName] intValue])
[_textStorage removeAttribute:CPUnderlineStyleAttributeName range:_selectionRange];
else
[_textStorage addAttribute:CPUnderlineStyleAttributeName value:[CPNumber numberWithInt:1] range:CPMakeRangeCopy(_selectionRange)];
[_textStorage addAttribute:CPUnderlineStyleAttributeName value:CPUnderlineStyleSingle range:CPMakeRangeCopy(_selectionRange)];
}
else
{
if ([_typingAttributes containsKey:CPUnderlineStyleAttributeName] && [[_typingAttributes objectForKey:CPUnderlineStyleAttributeName] intValue])
[_typingAttributes setObject:[CPNumber numberWithInt:0] forKey:CPUnderlineStyleAttributeName];
[_typingAttributes setObject:CPUnderlineStyleNone forKey:CPUnderlineStyleAttributeName];
else
[_typingAttributes setObject:[CPNumber numberWithInt:1] forKey:CPUnderlineStyleAttributeName];
[_typingAttributes setObject:CPUnderlineStyleSingle forKey:CPUnderlineStyleAttributeName];
}
[_layoutManager textStorage:_textStorage edited:0 range:CPMakeRangeCopy(_selectionRange) changeInLength:0 invalidatedRange:CPMakeRangeCopy(_selectionRange)];
+7 -1
View File
@@ -27,6 +27,12 @@
[textView setDelegate:self];
[[theWindow contentView] addSubview:textView];
var button = [[CPButton alloc] initWithFrame:CGRectMake(400,10,75,25)];
[button setTitle:@"Underline"];
[button setTarget:textView];
[button setAction:@selector(underline:)];
[[theWindow contentView] addSubview:button];
delegateSpy = spy(self);
}
@@ -184,4 +190,4 @@
}
@end
@end