Skip to content

Commit

Permalink
Fixes to font handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Balearica committed Sep 9, 2024
1 parent 5846586 commit a23a329
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
14 changes: 14 additions & 0 deletions js/fontSupp.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions js/utils/fontUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
6 changes: 4 additions & 2 deletions js/utils/miscUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit a23a329

Please sign in to comment.