Skip to content
Snippets Groups Projects
Commit bbafd51b authored by Alexa Valentová's avatar Alexa Valentová
Browse files

fix avatar dl, new template

parent a74ffffb
Branches
No related tags found
No related merge requests found
Pipeline #21277 passed
2.22.1 2.23.0
\ No newline at end of file
...@@ -37,7 +37,8 @@ export default { ...@@ -37,7 +37,8 @@ export default {
this.redrawing = false; this.redrawing = false;
}, },
downloadImage() { downloadImage() {
this.canvas.discardActiveObject().renderAll(); this.canvas.discardActiveObject()
this.canvas.renderAll();
let link = document.createElement("a"); let link = document.createElement("a");
......
...@@ -246,17 +246,16 @@ const transformHighlightedText = ( ...@@ -246,17 +246,16 @@ const transformHighlightedText = (
let positionWithinLine = 0; let positionWithinLine = 0;
let linePosition = 0; let linePosition = 0;
let previousLinePosition = 0;
let highlightIsActive = false; let highlightIsActive = false;
let styles = { let styles = {
0: {}, 0: {},
}; };
let prependWithSpace = false;
let rects = []; let rects = [];
let line = ""; let line = "";
let highlightedText = ""; let highlightedText = "";
let resetHLTnextRound = false;
for (const character of text) { for (const character of text) {
const characterIsStar = character === "*"; const characterIsStar = character === "*";
...@@ -264,31 +263,15 @@ const transformHighlightedText = ( ...@@ -264,31 +263,15 @@ const transformHighlightedText = (
if (characterIsStar) { if (characterIsStar) {
highlightIsActive = !highlightIsActive; highlightIsActive = !highlightIsActive;
if (resetHLTnextRound) {
highlightedText = "";
resetHLTnextRound = false;
}
if (highlightIsActive) { if (highlightIsActive) {
highlightedText += ( highlightedText += "";
!options.invertHighlight line += "";
? " " : ""
);
line += (
!options.invertHighlight
? " " : ""
);
} }
text = setCharAt( text = setCharAt(
text, text,
positionWithinString, positionWithinString,
!options.invertHighlight "",
? // For now, just put an empty Unicode character that still registers
// as one. To do this properly, we would have to adjust the code so that
// it goes back one character. But I don't feel like doing that.
" "
: "",
); );
} else if (highlightIsActive) { } else if (highlightIsActive) {
highlightedText += character; highlightedText += character;
...@@ -304,7 +287,10 @@ const transformHighlightedText = ( ...@@ -304,7 +287,10 @@ const transformHighlightedText = (
if (highlightIsActive || characterIsStar) { if (highlightIsActive || characterIsStar) {
if (!options.invertHighlight) { if (!options.invertHighlight) {
if (!options.skipAddingBg) {
style.textBackgroundColor = highlightColor; style.textBackgroundColor = highlightColor;
}
style.fill = highlightedTextColor; style.fill = highlightedTextColor;
} else { } else {
style.fill = highlightColor; style.fill = highlightColor;
...@@ -328,6 +314,7 @@ const transformHighlightedText = ( ...@@ -328,6 +314,7 @@ const transformHighlightedText = (
positionWithinLine++; positionWithinLine++;
positionWithinString++; positionWithinString++;
previousLinePosition = linePosition;
if (character === "\n") { if (character === "\n") {
styles[linePosition + 1] = {}; styles[linePosition + 1] = {};
......
...@@ -6,7 +6,7 @@ import { sanitizeValue } from "./utils"; ...@@ -6,7 +6,7 @@ import { sanitizeValue } from "./utils";
<script> <script>
export default { export default {
components: { InputHeading }, components: { InputHeading },
props: ["name", "important", "highlightable", "zIndex", "modelValue"], props: ["name", "important", "highlightable", "zIndex", "customHighlightText", "modelValue"],
emits: ["update:modelValue"], emits: ["update:modelValue"],
}; };
</script> </script>
...@@ -27,8 +27,11 @@ export default { ...@@ -27,8 +27,11 @@ export default {
@input="$emit('update:modelValue', sanitizeValue($event.target.value))" @input="$emit('update:modelValue', sanitizeValue($event.target.value))"
></textarea> ></textarea>
<small v-if="highlightable"> <small v-if="highlightable">
<span v-if="!customHighlightText">
Pro zvýraznění části textu ho <em>*obal do hvězdiček.*</em><br /> Pro zvýraznění části textu ho <em>*obal do hvězdiček.*</em><br />
Nezapomeň na druhou hvězdičku. Nezapomeň na druhou hvězdičku.
</span>
<span v-else v-text="customHighlightText" />
</small> </small>
</section> </section>
</template> </template>
...@@ -183,6 +183,7 @@ export default { ...@@ -183,6 +183,7 @@ export default {
v-model="mainText" v-model="mainText"
:important="true" :important="true"
:highlightable="true" :highlightable="true"
customHighlightText="V této šabloně lze zvýrazňovat pouze celé řádky, pro správnou funkci zvýrazněte pouze celé řádky."
zIndex="9" zIndex="9"
/> />
<ShortTextInput <ShortTextInput
......
...@@ -29,6 +29,7 @@ let previousLogoPosition = null; ...@@ -29,6 +29,7 @@ let previousLogoPosition = null;
let leftQuote = null; let leftQuote = null;
let rightQuote = null; let rightQuote = null;
let rects = [];
const redraw = async (canvas, options) => { const redraw = async (canvas, options) => {
canvas.controlsAboveOverlay = true; canvas.controlsAboveOverlay = true;
...@@ -47,8 +48,9 @@ const redraw = async (canvas, options) => { ...@@ -47,8 +48,9 @@ const redraw = async (canvas, options) => {
canvas, canvas,
); );
if (highlightedData) { if (rects) {
clearObjects(highlightedData.rects, canvas); clearObjects(rects, canvas);
rects = [];
} }
canvas.preserveObjectStacking = true; canvas.preserveObjectStacking = true;
...@@ -102,6 +104,8 @@ const redraw = async (canvas, options) => { ...@@ -102,6 +104,8 @@ const redraw = async (canvas, options) => {
// centerGradientBackground: true, // centerGradientBackground: true,
x: textMarginLeft, x: textMarginLeft,
y: mainTextBoxTopEstimate, y: mainTextBoxTopEstimate,
skipAddingBg: true,
highlightContainedToLine: true,
} }
); );
...@@ -126,42 +130,66 @@ const redraw = async (canvas, options) => { ...@@ -126,42 +130,66 @@ const redraw = async (canvas, options) => {
mainTextBox.top = canvas.height - mainTextBox.height - highlightedData.paddingBottom - mainTextMarginBottom; mainTextBox.top = canvas.height - mainTextBox.height - highlightedData.paddingBottom - mainTextMarginBottom;
const mainTextBoxTop = mainTextBox.top; const mainTextBoxTop = mainTextBox.top;
canvas.renderAll(); // grab the original so we can still draw the text
const _origRenderTextLine = fabric.Textbox.prototype._renderTextLine;
function renderTextLine(method, ctx, line, left, top, lineIndex) {
if (line.includes("")) {
let actualLineText = "";
for (let char of line) {
if (char == "") {
continue;
}
actualLineText += char;
}
console.log(ctx);
// measure the line width in the current context
const metrics = ctx.measureText(actualLineText);
const lineWidth = metrics.width * 1.05;
const height = this.fontSize * 1.05; // adjust vertical padding if you like
const defaultGradient = new fabric.Gradient({ const defaultGradient = new fabric.Gradient({
type: 'linear', type: 'linear',
gradientUnits: 'pixels', gradientUnits: 'pixels',
coords: { x1: 0, y1: 0, x2: mainTextSize, y2: 0 }, coords: { x1: 0, y1: 0, x2: lineWidth + 20, y2: 0 },
colorStops: [ colorStops: [
{ offset: 0, color: '#CF7BCC' }, { offset: 0, color: '#CF7BCC' },
{ offset: 1, color: '#FDC801' }, { offset: 1, color: '#FDC801' },
], ],
}); });
console.log("is doing a ting"); // build the rect
function renderTextLine (method, ctx, line, left, top, lineIndex) {
console.log("meowfdksfosdkfo");
// if (line.length) {
if (true) {
console.log(mainTextBox.left - left, mainTextBox.top - top);
const rect = new fabric.Rect({ const rect = new fabric.Rect({
left: mainTextBox.left - left, left: canvas.width / 2 + left - 20,
top: mainTextBox.right - top, top: canvas.height - mainTextMarginBottom - highlightedData.paddingBottom * 0.5 - 20 - (
height: mainTextSize * 2, (mainTextBox._textLines.length - lineIndex)
width: 50, * mainTextSize
// * mainTextLineHeight
),
width: lineWidth, // Add padding to left side, line breaks do right
height: height,
fill: defaultGradient, fill: defaultGradient,
zIndex: 9 // Right under text zIndex originX: 'left',
originY: 'top',
evented: false,
selectable: false,
zIndex: 9,
}); });
rects.push(rect);
canvas.add(rect); canvas.add(rect);
} }
// render the text line // finally draw the text chars
this._renderChars(method, ctx, line, left, top, lineIndex); _origRenderTextLine.call(this, method, ctx, line, left, top, lineIndex);
}; }
// hook it up to your textbox
mainTextBox._renderTextLine = renderTextLine; mainTextBox._renderTextLine = renderTextLine;
canvas.renderAll(); canvas.renderAll();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment