Skip to content

Commit

Permalink
Merge pull request danielearwicker#32 from creately/add-getDrawableCo…
Browse files Browse the repository at this point in the history
…ntent-method

Added getDrawableContent method
  • Loading branch information
thani-sh authored Jul 4, 2019
2 parents 5b419e8 + a0856ff commit 8ef4e66
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@creately/carota",
"author": "Daniel Earwicker ([email protected])",
"description": "Simple, flexible rich text rendering/editing on HTML Canvas",
"version": "2.7.2",
"version": "2.8.0",
"repository": {
"type": "git",
"url": "https://github.com/danielearwicker/carota.git"
Expand Down
52 changes: 52 additions & 0 deletions src/doc.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,59 @@ var prototype = node.derive({
documentRange: function() {
return this.range(0, this.frame.length - 1);
},
getDrawableContent: function() {
var words = [];
var underLines = [];
var strikLines = [];
for (let i = 0; i < this.frame.lines.length; i++) {
var line = this.frame.lines[i];
if ( line.positionedWords ) {
for (let j = 0; j < line.positionedWords.length; j++) {
var left = line.positionedWords[j].left;
var word = line.positionedWords[j].word;
var text = word.text.parts[0];

if ( text.run.underline === true ) {
underLines.push({
baseline: line.baseline,
width: word.width, // text width + space width,
left,
color: text.run.color || this.defaultFormatting.color,
})
}

if ( text.run.strikeout === true ) {
strikLines.push({
ascent: word.ascent,
baseline: line.baseline,
width: word.width, // text width + space width,
left,
color: text.run.color || this.defaultFormatting.color,
})
}

words.push({
baseline: line.baseline,
left,
content: {
text: text.run.text.trim() + '&#160;'.repeat( word.space.length ),
size: text.run.size || this.defaultFormatting.size,
font: text.run.font || this.defaultFormatting.font,
color: text.run.color || this.defaultFormatting.color,
bold: text.run.bold || this.defaultFormatting.bold,
italic: text.run.italic || this.defaultFormatting.italic,
underline: text.run.underline || this.defaultFormatting.underline,
strikeout: text.run.strikeout || this.defaultFormatting.strikeout,
align: text.run.align || this.defaultFormatting.align,
script: text.run.script || this.defaultFormatting.script,
}
})
}
}

}
return { words, underLines, strikLines };
},
isMultiLine: function() {
return this.frame.lines.length > 1;
},
Expand Down

0 comments on commit 8ef4e66

Please sign in to comment.