-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplify setSubscript, setSuperscript #4190
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -855,11 +855,6 @@ | |
* @return {Number} fontSize of the character | ||
*/ | ||
getHeightOfChar: function(line, char) { | ||
var size = this.getValueOfPropertyAt(line, char, '*fontSize'); | ||
if (typeof size === 'number') { | ||
return size; | ||
} | ||
|
||
return this.getValueOfPropertyAt(line, char, 'fontSize'); | ||
}, | ||
|
||
|
@@ -1143,7 +1138,7 @@ | |
* @returns {Object} this | ||
*/ | ||
setSuperscript: function(line, char) { | ||
return this.superscript.apply(this, line, char); | ||
return this._setScript(line, char, this.superscript); | ||
}, | ||
|
||
/** | ||
|
@@ -1153,7 +1148,14 @@ | |
* @returns {Object} this | ||
*/ | ||
setSubscript: function(line, char) { | ||
return this.subscript.apply(this, line, char); | ||
return this._setScript(line, char, this.subscript); | ||
}, | ||
|
||
_setScript: function(line, char, schema) { | ||
var fontSize = this.getValueOfPropertyAt(line, char, 'fontSize'), | ||
baseline = this.getValueOfPropertyAt(line, char, 'deltaY') + fontSize * schema.baseline; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. that's supposed to be ... + fontSize * -schema.baseline (follows the baseline-shift attribute from SVG) |
||
this.setPropertyAt(line, char, 'deltaY', baseline); | ||
this.setPropertyAt(line, char, 'fontSize', fontSize * schema.size); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
}, | ||
|
||
/** | ||
|
@@ -1169,7 +1171,7 @@ | |
prevStyle.fontFamily !== thisStyle.fontFamily || | ||
prevStyle.fontWeight !== thisStyle.fontWeight || | ||
prevStyle.fontStyle !== thisStyle.fontStyle || | ||
prevStyle.deltaY != thisStyle.deltaY | ||
prevStyle.deltaY !== thisStyle.deltaY | ||
); | ||
}, | ||
|
||
|
@@ -1259,6 +1261,10 @@ | |
if (charStyle && typeof charStyle[property] !== 'undefined') { | ||
return charStyle[property]; | ||
} | ||
if (property === 'deltaY') { | ||
// if did not find deltaY in style, return 0 | ||
return 0; | ||
} | ||
|
||
return this[property]; | ||
}, | ||
|
@@ -1441,87 +1447,6 @@ | |
complexity: function() { | ||
return 1; | ||
} | ||
}, function(prototype, Text) { | ||
prototype.superscript.apply = prototype.subscript.apply = | ||
/** | ||
* Mutates the style at given position in 'self' based on values from 'this' | ||
* @param {Object} self the object to be mutated | ||
* @param {Number} line the line number or the starting position | ||
* @param {Number} char the character number or the final position | ||
* @returns {Object} self | ||
*/ | ||
function(self, line, char) { | ||
var schema = this; | ||
var apply = function(line, char) { | ||
var l = self._textLines[line]; | ||
if (l == null || typeof l[char] !== 'string') { | ||
return self; | ||
} | ||
|
||
var size = self.getValueOfPropertyAt(line, char, 'fontSize'); | ||
if (typeof self.getValueOfPropertyAt(line, char, '*fontSize') !== 'number') { | ||
self.setPropertyAt(line, char, '*fontSize', size); | ||
} | ||
|
||
var dy = self.getValueOfPropertyAt(line, char, 'deltaY') || 0; | ||
self.setPropertyAt(line, char, 'fontSize', size * schema.size); | ||
self.setPropertyAt(line, char, 'deltaY', dy + size * -schema.baseline); | ||
return self; | ||
}; | ||
|
||
if (typeof line === 'number') { | ||
if (typeof char === 'number') { | ||
return apply(line, char); | ||
} | ||
|
||
var c1 = char[0], c2 = char[1]; | ||
if (c1 >= c2) { | ||
return self; | ||
} | ||
|
||
for (var c = c1; c <= c2; c++) { | ||
apply(line, c, this); | ||
} | ||
return self; | ||
} | ||
|
||
var l1 = line[0], C1 = line[1]; | ||
if (typeof char !== 'object') { | ||
return apply(l1, C1); | ||
} | ||
|
||
var l2 = char[0], C2 = char[1]; | ||
if (l1 > l2) { | ||
return self; | ||
} | ||
|
||
var lines = self._textLines; | ||
for (var l = l1; l <= l2; l++) { // lines | ||
line = lines[l]; | ||
if (line == null) { | ||
break; | ||
} | ||
|
||
var c1 = 0, c2 = line.length - 1; | ||
switch (l) { | ||
case l1: | ||
c1 = C1; | ||
break; | ||
|
||
case l2: | ||
c2 = C2; | ||
} | ||
|
||
if (l1 == l2 && c1 == c2 || c1 > c2) { | ||
break; | ||
} | ||
for (var c = c1; c <= c2; c++) { // characters | ||
apply(l, c); | ||
} | ||
} | ||
|
||
return self; | ||
}; | ||
}); | ||
|
||
/* _FROM_SVG_START_ */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
some checks are missing here