Repository navigation
Remove Foundation from CTLine - #2586
Conversation
|
Nit: please reword to be in imperative mood and not end in a period. #Resolved |
Allen Ballway (aballway)
left a comment
There was a problem hiding this comment.
What are the perf differences from these changes? I don't see anything that should significantly affect memory or cpu time.
| return CFRangeMake(start, end - start); | ||
| } | ||
|
|
||
| static void __CFAtributedStringAppendAttributedString(CFMutableAttributedStringRef attString, CFAttributedStringRef appendString) { |
There was a problem hiding this comment.
Attributed* #Resolved
There was a problem hiding this comment.
nit: rename first param to attrString #Resolved
| ret->_glyphCount = _glyphCount; | ||
| ret->_runs.attach(CFArrayCreateMutableCopy(kCFAllocatorDefault, 0, _runs)); | ||
| ret->_relativeXOffset = _relativeXOffset; | ||
| static CFMutableAttributedStringRef __getTruncatedStringFromSourceLine(CTLineRef sourceLine, |
There was a problem hiding this comment.
nit: follow naming convention - __CTLineGet... #Resolved
| #import <cwchar> | ||
| #import <vector> | ||
|
|
||
| static inline CFRange __CFRangeIntersectionRange(CFRange a, CFRange b) { |
There was a problem hiding this comment.
should this be made a more public helper function? #WontFix
There was a problem hiding this comment.
CFIndex can be negative, so you need to make sure that the lengths are >= 0L #WontFix
There was a problem hiding this comment.
sadly this guy has to go :(.
Also the CF version of this in CFStroage doesn't seem to account for it.
In reply to: 112723252 [](ancestors = 112723252)
| CFIndex lenDiff = 0; | ||
| CFRange currentRange; | ||
|
|
||
| while ((index >= enumerationRange.location) && index < (enumerationRange.location + enumerationRange.length)) { |
There was a problem hiding this comment.
nit: add some comments about what's going on in this #Resolved
| index += (currentRange.length + lenDiff); | ||
| enumerationRange.length += lenDiff; | ||
|
|
||
| if (currentRange.length == 0) { |
There was a problem hiding this comment.
nit: 0L. #Resolved
| CFIndex CTLineGetGlyphCount(CTLineRef line) { | ||
| return line ? static_cast<_CTLine*>(line)->_glyphCount : 0; | ||
| RETURN_RESULT_IF_NULL(line, 0); | ||
| return line->_glyphCount; |
There was a problem hiding this comment.
These should all be getter methods #WontFix
There was a problem hiding this comment.
It would be ideal, but the earlier code violated the getter/setter pattern and exposed private vars outside the file.
so it doesn't help us much here.
In reply to: 112724807 [](ancestors = 112724807)
There was a problem hiding this comment.
I mean in the paradigm this was done in CTLineGetGlyphCount was the getter, but now since we're updating this to use CppBase and touching everything we should use better style 🛩 #ByDesign
There was a problem hiding this comment.
inline functions in structs are pretty awesome ;P Also it troubles me to write a getter for a public field.
In reply to: 112742078 [](ancestors = 112742078)
| double CTLineGetTypographicBounds(CTLineRef lineRef, CGFloat* ascent, CGFloat* descent, CGFloat* leading) { | ||
| _CTLine* line = static_cast<_CTLine*>(lineRef); | ||
|
|
||
| __CTLine* line = const_cast<__CTLine*>(lineRef); |
There was a problem hiding this comment.
Just move this into a CTLine::GetTypographicBounds(...) so it doesn't need to be mutated like this. Since the values are computed lazily just make them mutable so it can stay const. #ByDesign
There was a problem hiding this comment.
i'm not going to make logic changes in this CR.
That's out of scope, it should of been done initially to avoid modifying private vars.
In reply to: 112725004 [](ancestors = 112725004)
There was a problem hiding this comment.
It wouldn't be a logic change, just moving it into __CTLine like we do with other CppBase classes #ByDesign
There was a problem hiding this comment.
ah okay , you want to move the whole function into __CTLine.
uh, this is where it's going to get weird. __CTline is already violated elsewhere, so it has to go public strut.
Then this moves into it and expose a function. it would be ideal to clean everything up, so please open a bug for it.
The main purpose of this is to get rid of foundation.
In reply to: 112742309 [](ancestors = 112742309)
There was a problem hiding this comment.
This wouldn't require the rest of __CTLine be moved into a private struct (which would be better but would be some more churn). We're already adding extra abstraction with _CTLineCreate so we might as well do this right 😸 #Resolved
There was a problem hiding this comment.
LOL yes it would not require for that to occur, uh but this just get's uglier.
In reply to: 112746377 [](ancestors = 112746377)
There was a problem hiding this comment.
Also we need the cast anyways, since this method is modifying lineRef. so we can't do lineRef->GetTypographics...(), given GetTypographics can't be a const method.
In reply to: 112746739 [](ancestors = 112746739,112746377)
There was a problem hiding this comment.
The values being modified are for all intents and purposes constant for this method, they're just being lazily calculated, which is why they should be marked mutable. I did something similar w/ CGDataProvider to keep things const even though the values were being lazily modified #Resolved
| * @return Unmutable array of _CTLine objects created with the requested parameters. | ||
| */ | ||
| static _CTLine* _DWriteGetLine(CFAttributedStringRef string) { | ||
| static CTLineRef _DWriteGetLine(CFAttributedStringRef string) { |
There was a problem hiding this comment.
I'm not sure why this one is Get since it returns a +1, but can you change this to Create* #Resolved
There was a problem hiding this comment.
There was a problem hiding this comment.
Allen Ballway (@aballway) didn't you name this #ByDesign
There was a problem hiding this comment.
Yup, this one is 100% my fault. No clue why I named it that 🤷♂️ #ByDesign
| //****************************************************************************** | ||
| // | ||
| // Copyright (c) 2016 Microsoft Corporation. All rights reserved. | ||
| // Copyright (c) Microsoft. All rights reserved. |
There was a problem hiding this comment.
These are nice but again unrelated to the rest of these changes. Pull these into a separate commit? #ByDesign
There was a problem hiding this comment.
| CFArrayRef glyphRuns = CTLineGetGlyphRuns(sourceLine); | ||
| CFIndex numberOfRuns = CFArrayGetCount(glyphRuns); | ||
| double extractedWidth = 0; | ||
| bool done = 0; |
There was a problem hiding this comment.
nit: false #Resolved
There was a problem hiding this comment.
| CFIndex lenDiff = 0; | ||
| CFRange currentRange; | ||
|
|
||
| while ((index >= enumerationRange.location) && index < (enumerationRange.location + enumerationRange.length)) { |
There was a problem hiding this comment.
just use CFAttributedStringReplaceAttributedString instead #ByDesign
There was a problem hiding this comment.
this reflects what NSAttributedString is doing.
Given i don't have the full range of context on the CoreText dancing here, I decide to do the same.
which is also pretty trivial. If you are 100% this is sufficient, i can move forward.
In reply to: 112734332 [](ancestors = 112734332)
There was a problem hiding this comment.
Definitely just use CFAttributedStringReplaceAttributedString - I am 100% sure it is sufficient. The reason we don't use it for [NSMutableAttributedString appendAttributedString:] is to reduce the number of abstract functions. Before we made that class more properly abstract, the initial implementation of it DID use ReplaceAttributedString. #Resolved
| CFRangeMake(index, CFAttributedStringGetLength(typesetter->AttributedString()) - index), | ||
| CGRectMake(offset, 0, width, FLT_MAX)); | ||
| CTFrameRef frame = _DWriteGetFrame(typesetter->AttributedString(), | ||
| CFRangeMake(index, CFAttributedStringGetLength(typesetter->AttributedString()) - index), |
|
Allen Ballway (@aballway) there is, #1 you aren't doing message dispatches anymore, second there some redundant code that was reduced + reduced allocations. |
|
Nit: please reword to be in imperative mood and not end in a period. #Resolved |
|
ms-jihua Dustin L. Howett (MSFT) (@DHowett-MSFT) Allen Ballway (@aballway) |
|
|
||
| CFRange range = { 0, CFStringGetLength(string) }; | ||
| CFAttributedStringSetAttributes(attString, { range.location + replaceRange.location, range.length }, attribs, true); | ||
| CFAttributedStringSetAttributes(attrString, { range.location + replaceRange.location, range.length }, attribs, true); |
There was a problem hiding this comment.
range.location + replaceRange.location
soooo...
replaceRange.location?
wait, sooo
index ? #Resolved
| CGFloat _ascent, _descent, _leading; | ||
| } | ||
| @end | ||
| CGFloat _ascent; |
There was a problem hiding this comment.
so then if these are marked mutable you'll be able to keep GetTypographicBounds() const 😄 #Resolved
There was a problem hiding this comment.
| _CTLine* line = static_cast<_CTLine*>(lineRef); | ||
|
|
||
| RETURN_RESULT_IF((!line) || (CFArrayGetCount(line->_runs) == 0), 0); | ||
| double __CTLine::GetTypographicBounds(CGFloat* ascent, CGFloat* descent, CGFloat* leading) { |
There was a problem hiding this comment.
<3 #Resolved
Allen Ballway (aballway)
left a comment
There was a problem hiding this comment.
Approval pending mutable
| } | ||
|
|
||
| // Inserts the characters and attribute of the given string into the receiver at the given index. | ||
| static inline void __CFAttributedStringInsertAttributedStringOneAttribute(CFMutableAttributedStringRef attrString, |
There was a problem hiding this comment.
I don't think these would provide much perf improvement over your other non-OneAttribute helper, would they? I would like to just get rid of them. #ByDesign
There was a problem hiding this comment.
we keep on creating AttributedStrings and trying to insert them in the for-loop for based on the glyph count, it can be a bottleneck.
If glyph count is usually low, then this isn't needed.
In reply to: 112783999 [](ancestors = 112783999)
ms-jihua
left a comment
There was a problem hiding this comment.
Would like to not have the OneAttribute helpers (possibly the non-OneAttribute helper would even be faster...), otherwise fine.
- Implementation of CTLine via runtime based - Reduced/Removed Attributed string creation in loops - Implemented CFAttribute functions to append and insert attributed string - Implemented NSAttributes in terms of CFAttributes - Code improvements - Increased Perf Fixes microsoft#2357
NSMutableAttributedString stringFromToken is created, but the function can return upon an invalid truncationType before stringFromToken is released. Fixes microsoft#2451
1cdc520 to
6f96e0f
Compare

Fixes #2357,#2451