diff --git a/ext/js/display/structured-content-generator.js b/ext/js/display/structured-content-generator.js index fd9a8d534..6cdc981bd 100644 --- a/ext/js/display/structured-content-generator.js +++ b/ext/js/display/structured-content-generator.js @@ -116,6 +116,7 @@ export class StructuredContentGenerator { if (typeof border === 'string') { imageContainer.style.border = border; } if (typeof borderRadius === 'string') { imageContainer.style.borderRadius = borderRadius; } + imageContainer.style.width = `${usedWidth}em`; if (typeof title === 'string') { imageContainer.title = title; } @@ -124,17 +125,13 @@ export class StructuredContentGenerator { const image = this._contentManager instanceof DisplayContentManager ? /** @type {HTMLCanvasElement} */ (this._createElement('canvas', 'gloss-image')) : /** @type {HTMLImageElement} */ (this._createElement('img', 'gloss-image')); - if (sizeUnits === 'em' && (hasPreferredWidth || hasPreferredHeight)) { - const emSize = 14; // We could Number.parseFloat(getComputedStyle(document.documentElement).fontSize); here for more accuracy but it would cause a layout and be extremely slow; possible improvement would be to calculate and cache the value - const scaleFactor = 2 * window.devicePixelRatio; - image.style.width = `${usedWidth}em`; - image.style.height = `${usedWidth * invAspectRatio}em`; - image.width = usedWidth * emSize * scaleFactor; - } else { - image.width = usedWidth; - } + image.width = width; image.height = image.width * invAspectRatio; + // Anki will not render images correctly without specifying to use 100% width and height + image.style.width = '100%'; + image.style.height = '100%'; + imageContainer.appendChild(image); if (this._contentManager instanceof DisplayContentManager) { diff --git a/test/data/anki-note-builder-test-results.json b/test/data/anki-note-builder-test-results.json index 86e64ed13..5aacb9eeb 100644 --- a/test/data/anki-note-builder-test-results.json +++ b/test/data/anki-note-builder-test-results.json @@ -863,12 +863,12 @@ "frequency-average-occurrence": "0", "furigana": "画像", "furigana-plain": "画像[がぞう]", - "glossary": "
", - "glossary-brief": "", - "glossary-no-dictionary": "", - "glossary-first": "", - "glossary-first-brief": "", - "glossary-first-no-dictionary": "", + "glossary": "", + "glossary-brief": "", + "glossary-no-dictionary": "", + "glossary-first": "", + "glossary-first-brief": "", + "glossary-first-no-dictionary": "", "part-of-speech": "Noun", "pitch-accents": "", "pitch-accent-graphs": "", @@ -1570,12 +1570,12 @@ "frequency-average-occurrence": "0", "furigana": "画像", "furigana-plain": "画像[がぞう]", - "glossary": "", - "glossary-brief": "", - "glossary-no-dictionary": "", - "glossary-first": "", - "glossary-first-brief": "", - "glossary-first-no-dictionary": "", + "glossary": "", + "glossary-brief": "", + "glossary-no-dictionary": "", + "glossary-first": "", + "glossary-first-brief": "", + "glossary-first-no-dictionary": "", "part-of-speech": "Noun", "pitch-accents": "", "pitch-accent-graphs": "",