한글뷰어 기능수정 Ver.01
This commit is contained in:
57
scratch_parse_hwpx.js
Normal file
57
scratch_parse_hwpx.js
Normal file
@@ -0,0 +1,57 @@
|
||||
const fs = require('fs');
|
||||
const jszip = require('jszip');
|
||||
|
||||
async function run() {
|
||||
try {
|
||||
const fileData = fs.readFileSync('downloaded_test.hwpx');
|
||||
const zip = await jszip.loadAsync(fileData);
|
||||
|
||||
// List files in the HWPX zip
|
||||
console.log('Zip file entries:');
|
||||
zip.forEach((relativePath, file) => {
|
||||
console.log(' -', relativePath);
|
||||
});
|
||||
|
||||
// Find section0.xml or similar XML files containing text content
|
||||
const sectionFile = Object.keys(zip.files).find(name => name.includes('section') && name.endsWith('.xml'));
|
||||
if (sectionFile) {
|
||||
console.log(`\nReading ${sectionFile}...`);
|
||||
const content = await zip.file(sectionFile).async('text');
|
||||
|
||||
// Search for shapes
|
||||
// In HWPX, shapes are under <hp:rect>, <hp:ellipse>, <hp:line> etc.
|
||||
// Let's write them to a local file for inspection
|
||||
fs.writeFileSync('section0.xml', content);
|
||||
console.log('Main section XML saved as section0.xml');
|
||||
|
||||
// Regex to find shape properties
|
||||
// HWPX coordinates: vertRelTo, horzRelTo, vertAlign, horzAlign, vertOffset, horzOffset
|
||||
console.log('\nSearching for shape properties in section XML:');
|
||||
const shapeObjectRegex = /<hp:shapeObject[^>]*>([\s\S]*?)<\/hp:shapeObject>/g;
|
||||
let match;
|
||||
let count = 0;
|
||||
while ((match = shapeObjectRegex.exec(content)) !== null) {
|
||||
count++;
|
||||
console.log(`\n--- Shape Object #${count} ---`);
|
||||
const shapeObjectHeader = match[0].substring(0, match[0].indexOf('>') + 1);
|
||||
console.log('Header:', shapeObjectHeader);
|
||||
|
||||
// Find vertRelTo, horzRelTo, etc.
|
||||
const attrs = ['vertRelTo', 'horzRelTo', 'vertAlign', 'horzAlign', 'vertOffset', 'horzOffset'];
|
||||
attrs.forEach(attr => {
|
||||
const reg = new RegExp(`${attr}="([^"]*)"`);
|
||||
const m = reg.exec(shapeObjectHeader);
|
||||
if (m) {
|
||||
console.log(` ${attr}: ${m[1]}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.log('No section XML file found.');
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Error parsing HWPX:', err);
|
||||
}
|
||||
}
|
||||
|
||||
run();
|
||||
Reference in New Issue
Block a user