Skip to content

Commit 5d5d7f9

Browse files
authored
Merge branch 'devt' into fix-more-styles
2 parents 8a499c3 + a9cf93d commit 5d5d7f9

File tree

3 files changed

+1002
-5
lines changed

3 files changed

+1002
-5
lines changed

dist/assets/index-CSheNIRS.js

Lines changed: 981 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/App.jsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -475,10 +475,19 @@ const App = () => {
475475
if (myInfo.length !== 2) {
476476
myInfo = Info;
477477
}
478-
const strings = myInfo && myInfo[0];
479-
const font = JSON.parse(
480-
getObjectById(dataRef.current, myInfo && myInfo[1])
481-
);
478+
// Check if myInfo[1] is a valid font reference or just another text line
479+
// If it's not found as an object, treat the whole array as text (no font)
480+
let strings, font;
481+
const possibleFont = getObjectById(dataRef.current, myInfo && myInfo[1]);
482+
if (possibleFont) {
483+
// myInfo[1] is a valid font reference
484+
strings = myInfo[0];
485+
font = JSON.parse(possibleFont);
486+
} else {
487+
// myInfo[1] is not a font - treat whole array as text lines
488+
strings = myInfo;
489+
font = null;
490+
}
482491
const textDimensions = Text.calculateTextDimensions(strings, font);
483492
const event = JSON.stringify({ WX: { Info: [textDimensions.height, textDimensions.width], WGID } });
484493
return webSocket.send(event);

src/components/Text/index.jsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const calculateTextDimensions = (lines, font) => {
4646
if (!lines || (Array.isArray(lines) && lines.length === 0)) {
4747
return { height: 0, width: 0 };
4848
}
49+
//console.log('calculateTextDimensions input:', { lines, font, fontPName: font?.Properties?.PName, fontSize: font?.Properties?.Size });
4950
// Ensure lines is an array
5051
const linesArray = Array.isArray(lines) ? lines : [lines];
5152

@@ -65,14 +66,20 @@ const calculateTextDimensions = (lines, font) => {
6566
lineHeight = (font.Properties.Size * scale) + 'px';
6667
}
6768

69+
const fontStyles = getFontStyles(font);
6870
linesArray.forEach(line => {
6971
const lineDiv = document.createElement('div');
7072
lineDiv.style.margin = '0';
7173
lineDiv.style.padding = '0';
7274
lineDiv.textContent = line;
7375
lineDiv.style.display = 'block'; // Start each on a new line
7476
lineDiv.style.lineHeight = lineHeight;
75-
Object.assign(lineDiv.style, getFontStyles(font));
77+
if (font?.Properties?.Size) {
78+
fontStyles.fontSize = (font.Properties.Size * scale) + 'px';
79+
} else {
80+
fontStyles.fontSize = (12 * scale) + 'px';
81+
}
82+
Object.assign(lineDiv.style, fontStyles);
7683
container.appendChild(lineDiv);
7784
});
7885

0 commit comments

Comments
 (0)