Skip to content

Commit

Permalink
Fixed bug in sample text handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Lorp committed Jul 24, 2024
1 parent d103e0e commit f038321
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/fencer.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ const GLOBAL = {
samsa: "samsa",
},
renderFontSize: 200,
renderText: "Rag",
};

function Q (selector) {
Expand Down Expand Up @@ -2042,6 +2041,7 @@ function downloadFont() {
function updateRenders() {

const renderer = Q("#renderer").value;
const renderText = Q("#sample-text").value;


if (!["harfbuzz", "browser"].includes(renderer)) {
Expand Down Expand Up @@ -2078,7 +2078,7 @@ function updateRenders() {
if (renderer === "browser") {

// browser method
renderEl.innerHTML = GLOBAL.renderText;
renderEl.innerHTML = renderText;
renderEl.style.fontSize = `${GLOBAL.renderFontSize}px`;
renderEl.style.fontVariationSettings = fvsEntries.join();
renderEl.style.color = "blue";
Expand All @@ -2093,7 +2093,6 @@ function updateRenders() {

const font = GLOBAL.hbFont;
const hb = GLOBAL.hb;
const text = GLOBAL.renderText;
const fontSize = GLOBAL.renderFontSize;
const upem = GLOBAL.font.head.unitsPerEm;
const scale = fontSize/upem;
Expand All @@ -2106,10 +2105,11 @@ function updateRenders() {
if (!buffer) {
console.log("could not create hb buffer")
}
buffer.addText(text);
buffer.addText(renderText);
buffer.guessSegmentProperties();
hb.shape(font, buffer);
const result = buffer.json(font);
buffer.destroy();

const paths = {}; // indexed by glyphId (use object not array, because this may be very sparse)
let x = 0;
Expand All @@ -2123,12 +2123,7 @@ function updateRenders() {
svgHbEl.attr({width: 10000, height: 10000})
svgHbEl.innerHTML = gPreamble + svg + gPostamble;


//document.querySelector("body").append(svgHbEl);
renderEl.append(svgHbEl);

buffer.destroy();

}
}

Expand Down

0 comments on commit f038321

Please sign in to comment.