From a23a329bee08a6c780890c174d9370f4cb3b30a3 Mon Sep 17 00:00:00 2001 From: Balearica Date: Mon, 9 Sep 2024 09:01:00 -0700 Subject: [PATCH] Fixes to font handling --- js/fontSupp.js | 14 ++++++++++++++ js/utils/fontUtils.js | 4 ++-- js/utils/miscUtils.js | 6 ++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/js/fontSupp.js b/js/fontSupp.js index badd075..af8abec 100644 --- a/js/fontSupp.js +++ b/js/fontSupp.js @@ -142,8 +142,22 @@ export const calcSuppFontInfo = async (ocrArr) => { if (serifVotes > sansVotes) { FontProps.serifFontsDoc.add(key); + // console.log('Serif:', key, serifVotes, sansVotes); } else { FontProps.sansFontsDoc.add(key); + // console.log('Sans:', key, serifVotes, sansVotes); + } + } + + if (Object.keys(FontProps.sizeMult).length === 0) return; + + for (const page of ocrArr) { + for (const line of page.lines) { + for (const word of line.words) { + if (word.font && word.size && FontProps.sizeMult[word.font]) { + word.size *= FontProps.sizeMult[word.font]; + } + } } } diff --git a/js/utils/fontUtils.js b/js/utils/fontUtils.js index 7760420..7e59f99 100644 --- a/js/utils/fontUtils.js +++ b/js/utils/fontUtils.js @@ -295,8 +295,8 @@ export const calcWordFontSize = (word) => { // If the user manually set a size, then use that if (word.size) { - const mult = FontProps.sizeMult[word.font] || 1; - return word.size * mult; + const mult = FontProps.sizeMult[font.family] || 1; + return word.size / mult; } const lineFontSize = calcLineFontSize(word.line); diff --git a/js/utils/miscUtils.js b/js/utils/miscUtils.js index 0953eb7..c86f230 100644 --- a/js/utils/miscUtils.js +++ b/js/utils/miscUtils.js @@ -325,8 +325,10 @@ export function replaceObjectProperties(obj, obj2 = {}) { // Sans/serif lookup for common font families. These should not include spaces or underscores--multi-word font names should be concatenated. // Fonts that should not be added (both Sans and Serif variants): // DejaVu -const serifFonts = ['SerifDefault', 'Baskerville', 'Book', 'C059', 'Cambria', 'Century', 'Courier', 'Garamond', 'Georgia', 'LucidaBright', 'Minion', 'P052', 'Palatino', 'Times']; -const sansFonts = ['SansDefault', 'Arial', 'Calibri', 'Candara', 'Carlito', 'Comic', 'Franklin', 'Helvetica', 'Impact', 'Interstate', 'Myriad', 'Tahoma', 'Trebuchet', 'UniversNext', 'Verdana']; +const serifFonts = ['SerifDefault', 'Baskerville', 'C059', 'Calibri', 'Cambria', 'Century', 'Courier', 'Garamond', 'Georgia', + 'LucidaBright', 'Minion', 'Optima', 'P052', 'Palatino', 'Times']; +const sansFonts = ['SansDefault', 'Avenir', 'Arial', 'Calibri', 'Candara', 'Carlito', 'Comic', 'Franklin', 'Futura', 'Gotham', + 'Helvetica', 'Impact', 'Interstate', 'Myriad', 'Tahoma', 'Trebuchet', 'Univers', 'Verdana']; const serifFontsRegex = new RegExp(serifFonts.reduce((x, y) => `${x}|${y}`), 'i'); const sansFontsRegex = new RegExp(sansFonts.reduce((x, y) => `${x}|${y}`), 'i');