emf-converter 2.0.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +13 -9
- package/dist/index.mjs +13 -9
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -423,19 +423,22 @@ function mapFontFamily(face, map) {
|
|
|
423
423
|
}
|
|
424
424
|
return resolved;
|
|
425
425
|
}
|
|
426
|
-
function
|
|
426
|
+
function fontSizePx(state, scale = 1) {
|
|
427
|
+
return Math.max(Math.abs(state.fontHeight) * Math.abs(scale || 1), 8);
|
|
428
|
+
}
|
|
429
|
+
function applyFont(ctx, state, scale = 1) {
|
|
427
430
|
const italic = state.fontItalic ? "italic " : "";
|
|
428
431
|
const weight = cssFontWeight(state.fontWeight);
|
|
429
432
|
const weightPart = weight ? `${weight} ` : "";
|
|
430
|
-
const size =
|
|
433
|
+
const size = fontSizePx(state, scale);
|
|
431
434
|
const family = mapFontFamily(state.fontFamily, state.fontFamilyMap);
|
|
432
435
|
ctx.font = `${italic}${weightPart}${size}px ${family}`;
|
|
433
436
|
}
|
|
434
|
-
function drawTextDecorations(ctx, state, x, y, width) {
|
|
437
|
+
function drawTextDecorations(ctx, state, x, y, width, scale = 1) {
|
|
435
438
|
if (!state.fontUnderline && !state.fontStrikeOut) {
|
|
436
439
|
return;
|
|
437
440
|
}
|
|
438
|
-
const size =
|
|
441
|
+
const size = fontSizePx(state, scale);
|
|
439
442
|
const thickness = Math.max(1, Math.round(size / 14));
|
|
440
443
|
const prevFill = ctx.fillStyle;
|
|
441
444
|
ctx.fillStyle = state.textColor;
|
|
@@ -1400,7 +1403,8 @@ function handleExtTextOutW(rCtx, offset, dataOff, recSize) {
|
|
|
1400
1403
|
if (nChars > 0 && offString > 0 && offset + offString + nChars * 2 <= maxOffset) {
|
|
1401
1404
|
const text = readUtf16LE(view, offset + offString, nChars);
|
|
1402
1405
|
if (text.length > 0) {
|
|
1403
|
-
|
|
1406
|
+
const fontScale = Math.abs(gmh(rCtx, 1));
|
|
1407
|
+
applyFont(ctx, state, fontScale);
|
|
1404
1408
|
ctx.fillStyle = state.textColor;
|
|
1405
1409
|
const vAlign = state.textAlign & 24;
|
|
1406
1410
|
const alignBaseline = vAlign === 24 ? "alphabetic" : vAlign === 8 ? "bottom" : "top";
|
|
@@ -1415,7 +1419,7 @@ function handleExtTextOutW(rCtx, offset, dataOff, recSize) {
|
|
|
1415
1419
|
ctx.textAlign = alignHoriz;
|
|
1416
1420
|
if (state.bkMode === 2) {
|
|
1417
1421
|
const measured = ctx.measureText(text);
|
|
1418
|
-
const bgH = state
|
|
1422
|
+
const bgH = fontSizePx(state, fontScale);
|
|
1419
1423
|
ctx.fillStyle = state.bkColor;
|
|
1420
1424
|
ctx.fillRect(gmx(rCtx, refX), gmy(rCtx, refY) - bgH, measured.width, bgH);
|
|
1421
1425
|
ctx.fillStyle = state.textColor;
|
|
@@ -1425,7 +1429,7 @@ function handleExtTextOutW(rCtx, offset, dataOff, recSize) {
|
|
|
1425
1429
|
const w = ctx.measureText(text).width;
|
|
1426
1430
|
const baseX = gmx(rCtx, refX);
|
|
1427
1431
|
const startX = alignHoriz === "center" ? baseX - w / 2 : alignHoriz === "right" ? baseX - w : baseX;
|
|
1428
|
-
drawTextDecorations(ctx, state, startX, gmy(rCtx, refY), w);
|
|
1432
|
+
drawTextDecorations(ctx, state, startX, gmy(rCtx, refY), w, fontScale);
|
|
1429
1433
|
}
|
|
1430
1434
|
}
|
|
1431
1435
|
}
|
|
@@ -4616,7 +4620,7 @@ function handleWmfDrawRecord(wCtx, recType, offset, dataOff, recSize) {
|
|
|
4616
4620
|
if (txOff + 4 <= offset + recSize) {
|
|
4617
4621
|
const ty2 = view.getInt16(txOff, true);
|
|
4618
4622
|
const txCoord = view.getInt16(txOff + 2, true);
|
|
4619
|
-
applyFont(ctx, state);
|
|
4623
|
+
applyFont(ctx, state, Math.abs(mh(1)));
|
|
4620
4624
|
ctx.fillStyle = state.textColor;
|
|
4621
4625
|
ctx.fillText(text, mx(txCoord), my(ty2));
|
|
4622
4626
|
}
|
|
@@ -4639,7 +4643,7 @@ function handleWmfDrawRecord(wCtx, recType, offset, dataOff, recSize) {
|
|
|
4639
4643
|
}
|
|
4640
4644
|
text += String.fromCharCode(ch);
|
|
4641
4645
|
}
|
|
4642
|
-
applyFont(ctx, state);
|
|
4646
|
+
applyFont(ctx, state, Math.abs(mh(1)));
|
|
4643
4647
|
ctx.fillStyle = state.textColor;
|
|
4644
4648
|
ctx.fillText(text, mx(txCoord), my(ty2));
|
|
4645
4649
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -421,19 +421,22 @@ function mapFontFamily(face, map) {
|
|
|
421
421
|
}
|
|
422
422
|
return resolved;
|
|
423
423
|
}
|
|
424
|
-
function
|
|
424
|
+
function fontSizePx(state, scale = 1) {
|
|
425
|
+
return Math.max(Math.abs(state.fontHeight) * Math.abs(scale || 1), 8);
|
|
426
|
+
}
|
|
427
|
+
function applyFont(ctx, state, scale = 1) {
|
|
425
428
|
const italic = state.fontItalic ? "italic " : "";
|
|
426
429
|
const weight = cssFontWeight(state.fontWeight);
|
|
427
430
|
const weightPart = weight ? `${weight} ` : "";
|
|
428
|
-
const size =
|
|
431
|
+
const size = fontSizePx(state, scale);
|
|
429
432
|
const family = mapFontFamily(state.fontFamily, state.fontFamilyMap);
|
|
430
433
|
ctx.font = `${italic}${weightPart}${size}px ${family}`;
|
|
431
434
|
}
|
|
432
|
-
function drawTextDecorations(ctx, state, x, y, width) {
|
|
435
|
+
function drawTextDecorations(ctx, state, x, y, width, scale = 1) {
|
|
433
436
|
if (!state.fontUnderline && !state.fontStrikeOut) {
|
|
434
437
|
return;
|
|
435
438
|
}
|
|
436
|
-
const size =
|
|
439
|
+
const size = fontSizePx(state, scale);
|
|
437
440
|
const thickness = Math.max(1, Math.round(size / 14));
|
|
438
441
|
const prevFill = ctx.fillStyle;
|
|
439
442
|
ctx.fillStyle = state.textColor;
|
|
@@ -1398,7 +1401,8 @@ function handleExtTextOutW(rCtx, offset, dataOff, recSize) {
|
|
|
1398
1401
|
if (nChars > 0 && offString > 0 && offset + offString + nChars * 2 <= maxOffset) {
|
|
1399
1402
|
const text = readUtf16LE(view, offset + offString, nChars);
|
|
1400
1403
|
if (text.length > 0) {
|
|
1401
|
-
|
|
1404
|
+
const fontScale = Math.abs(gmh(rCtx, 1));
|
|
1405
|
+
applyFont(ctx, state, fontScale);
|
|
1402
1406
|
ctx.fillStyle = state.textColor;
|
|
1403
1407
|
const vAlign = state.textAlign & 24;
|
|
1404
1408
|
const alignBaseline = vAlign === 24 ? "alphabetic" : vAlign === 8 ? "bottom" : "top";
|
|
@@ -1413,7 +1417,7 @@ function handleExtTextOutW(rCtx, offset, dataOff, recSize) {
|
|
|
1413
1417
|
ctx.textAlign = alignHoriz;
|
|
1414
1418
|
if (state.bkMode === 2) {
|
|
1415
1419
|
const measured = ctx.measureText(text);
|
|
1416
|
-
const bgH = state
|
|
1420
|
+
const bgH = fontSizePx(state, fontScale);
|
|
1417
1421
|
ctx.fillStyle = state.bkColor;
|
|
1418
1422
|
ctx.fillRect(gmx(rCtx, refX), gmy(rCtx, refY) - bgH, measured.width, bgH);
|
|
1419
1423
|
ctx.fillStyle = state.textColor;
|
|
@@ -1423,7 +1427,7 @@ function handleExtTextOutW(rCtx, offset, dataOff, recSize) {
|
|
|
1423
1427
|
const w = ctx.measureText(text).width;
|
|
1424
1428
|
const baseX = gmx(rCtx, refX);
|
|
1425
1429
|
const startX = alignHoriz === "center" ? baseX - w / 2 : alignHoriz === "right" ? baseX - w : baseX;
|
|
1426
|
-
drawTextDecorations(ctx, state, startX, gmy(rCtx, refY), w);
|
|
1430
|
+
drawTextDecorations(ctx, state, startX, gmy(rCtx, refY), w, fontScale);
|
|
1427
1431
|
}
|
|
1428
1432
|
}
|
|
1429
1433
|
}
|
|
@@ -4614,7 +4618,7 @@ function handleWmfDrawRecord(wCtx, recType, offset, dataOff, recSize) {
|
|
|
4614
4618
|
if (txOff + 4 <= offset + recSize) {
|
|
4615
4619
|
const ty2 = view.getInt16(txOff, true);
|
|
4616
4620
|
const txCoord = view.getInt16(txOff + 2, true);
|
|
4617
|
-
applyFont(ctx, state);
|
|
4621
|
+
applyFont(ctx, state, Math.abs(mh(1)));
|
|
4618
4622
|
ctx.fillStyle = state.textColor;
|
|
4619
4623
|
ctx.fillText(text, mx(txCoord), my(ty2));
|
|
4620
4624
|
}
|
|
@@ -4637,7 +4641,7 @@ function handleWmfDrawRecord(wCtx, recType, offset, dataOff, recSize) {
|
|
|
4637
4641
|
}
|
|
4638
4642
|
text += String.fromCharCode(ch);
|
|
4639
4643
|
}
|
|
4640
|
-
applyFont(ctx, state);
|
|
4644
|
+
applyFont(ctx, state, Math.abs(mh(1)));
|
|
4641
4645
|
ctx.fillStyle = state.textColor;
|
|
4642
4646
|
ctx.fillText(text, mx(txCoord), my(ty2));
|
|
4643
4647
|
}
|