Skip to content

Commit

Permalink
Add new norm layout
Browse files Browse the repository at this point in the history
  • Loading branch information
catusphan committed Nov 14, 2024
1 parent fdffde0 commit 6905a36
Show file tree
Hide file tree
Showing 5 changed files with 1,215 additions and 9 deletions.
160 changes: 155 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,86 @@ import jsonfile from 'jsonfile'
import webfont from 'webfont'
import { argv } from 'yargs'





























import helpers from './src/helpers'
import ruby from './src/ruby'
import svg from './src/svg'


















const fs = require('fs');












function generateSvg(data, config) {
const baseEngine = ruby.loadFont(config.baseFontFilepath)
const rubyEngine = ruby.loadFont(config.rubyFontFilepath)
const build_folder = `${config.workingDir}`

// Define the codepoint you're searching for
const targetCodePoint = "U+1ED9";

// Check if the code point exists in the existingData array (by checking codepoint field)
const inExistingData = data.some(item => item.codepoint === targetCodePoint);

if (inExistingData) {
console.log(`${targetCodePoint} exists in the existingData array.`);
} else {
console.log(`${targetCodePoint} does not exist in the existingData array.`);
}
// config.set_canvas(baseEngine.font.unitsPerEm, baseEngine.font.unitsPerEm)
// config.layout;
const fs = require('fs')

if (!fs.existsSync(build_folder)) {
Expand All @@ -22,13 +93,26 @@ function generateSvg(data, config) {

for (let datum = 0; datum < data.length; datum += 1) {
const char = data[datum]
const svgContent = svg.wrap(
ruby.getBase(baseEngine, char.glyph, config.layout.base),
ruby.getRuby(rubyEngine, char.ruby, config.layout.ruby)
)

const unicode = char.codepoint.replace('U+', 'u')
svg.save(`${config.workingDir}/${unicode}-${char.glyph}.svg`, svgContent)
if (!char.ruby){
const svgContent = svg.wrap(
ruby.getBase(baseEngine, char.glyph, config.layout.norm)
)
svg.save(`${config.workingDir}/${unicode}-${char.glyph}.svg`, svgContent)
}
else {
const svgContent = svg.wrap(
ruby.getBase(baseEngine, char.glyph, config.layout.base),
ruby.getRuby(rubyEngine, char.ruby, config.layout.ruby)
)
svg.save(`${config.workingDir}/${unicode}-${char.glyph}.svg`, svgContent)
}




// svg.save(`${config.workingDir}/${unicode}.svg`, svgContent)
}
}

Expand Down Expand Up @@ -62,6 +146,32 @@ function getConfigData(configValue) {
return 'default.json'
}


// Function to load the code points from the JSON file
function loadExtraCodePoints() {
const data = fs.readFileSync('src/added_codepoints.json', 'utf-8');
return JSON.parse(data);
}
// Function to add code points to the existing data
function addCodePointsToExistingData(codePoints, existingData) {
codePoints.forEach(codePoint => {
// Convert the code point (e.g., "U+6211") to the actual character
const character = String.fromCodePoint(parseInt(codePoint.replace('U+', ''), 16)); // Remove 'U+' and convert to number

// Add new object to the existing array
existingData.push({
codepoint: codePoint,
ruby: "", // Ruby is set to an empty string
glyph: character // Glyph is the character corresponding to the code point
});
});

// Write the updated array back to the file
fs.writeFileSync('existingData.json', JSON.stringify(existingData, null, 2));

console.log('Updated data written to existingData.json');
}

function start(cliArguments) {
let config = helpers.setBuildConfig(cliArguments)
config = helpers.setDataSource(config, cliArguments)
Expand Down Expand Up @@ -95,6 +205,11 @@ function start(cliArguments) {
throw err
}

// Example usage
const extra_data = loadExtraCodePoints();

addCodePointsToExistingData(extra_data, data);

helpers.prepare(config)

// Use when only generate the config then quit
Expand All @@ -108,4 +223,39 @@ function start(cliArguments) {
})
}

/*
// Define the Unicode ranges in an array
const unicodeRanges = [
{ start: 0x0000, end: 0x007F }, // Basic Latin
{ start: 0x0080, end: 0x00FF }, // Latin-1 Supplement
{ start: 0x0100, end: 0x017F }, // Latin Extended-A
{ start: 0x0180, end: 0x024F }, // Latin Extended-B
{ start: 0x1E00, end: 0x1EFF }, // Latin Extended Additional
{ start: 0x0300, end: 0x036F }, // Combining Diacritical Marks
];
// Function to generate code points in the specified ranges
function generateUnicodeCodePoints(ranges) {
const codePoints = [];
ranges.forEach(range => {
for (let i = range.start; i <= range.end; i++) {
codePoints.push(`U+${i.toString(16).toUpperCase().padStart(4, '0')}`);
}
});
return codePoints;
}
// Generate the Unicode code points array
const codePoints = generateUnicodeCodePoints(unicodeRanges);
// Write the code points to a JSON file
fs.writeFileSync('src/added_codepoints.json', JSON.stringify(codePoints, null, 2));
console.log('Unicode code points written to unicodeCodePoints.json');
*/

start(argv)
5 changes: 3 additions & 2 deletions resources/fonts/README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Should contains fonts to use (also need by travis).

Vietnamese font ranges
- C0 Controls and Basic Latin: U+0000-U+0000
- C1 Controls and Latin-1 Supplement: U+0080-U+00FF
- Controls and Basic Latin: U+0000-U+007F
- Latin-1 Supplement Supplement: U+0080-U+00FF
- Latin Extended-A: U+0100-U+017F
- Latin Extended-B: U+0180-U+024F
- Latin Extended Additional: U+1E00-U+1EFF
- Combining Diacritical Marks: U+0300-U+036F
Loading

0 comments on commit 6905a36

Please sign in to comment.