Erweiterungen

This commit is contained in:
2026-02-13 13:09:31 +01:00
parent b80eb53300
commit 4fb673a4d8
2 changed files with 62 additions and 8 deletions

Binary file not shown.

View File

@@ -213,6 +213,27 @@ window.initProfileInvoiceGenerator = function() {
var w = (el.width || 100) * zoomFactor;
var h = (el.height || 30) * zoomFactor;
// For text elements, calculate actual text dimensions
if (el.type !== 'line' && el.type !== 'image') {
var fontSize = (el.fontSize || 14) * zoomFactor;
ctx.font = (el.fontStyle || '') + ' ' + fontSize + 'px Arial';
var lines = (el.text || '').split('\n');
var maxLineWidth = 0;
lines.forEach(function(line) {
var lineWidth = ctx.measureText(line).width;
maxLineWidth = Math.max(maxLineWidth, lineWidth);
});
// Use the larger of defined width or actual text width
w = Math.max(w, maxLineWidth + (10 * zoomFactor));
// Calculate actual height based on number of lines
var lineHeight = fontSize * 1.2;
var textHeight = lines.length * lineHeight;
h = Math.max(h, textHeight + (6 * zoomFactor));
}
ctx.strokeStyle = '#1976d2';
ctx.lineWidth = Math.max(1, 2 * zoomFactor);
ctx.setLineDash([5, 3]);
@@ -252,6 +273,26 @@ window.initProfileInvoiceGenerator = function() {
var ey = pageY + (el.y * zoomFactor);
var ew = (el.width || 100) * zoomFactor;
var eh = (el.height || 30) * zoomFactor;
// For text elements, calculate actual text dimensions for hit testing
if (el.type !== 'line' && el.type !== 'image') {
var fontSize = (el.fontSize || 14) * zoomFactor;
ctx.font = (el.fontStyle || '') + ' ' + fontSize + 'px Arial';
var lines = (el.text || '').split('\n');
var maxLineWidth = 0;
lines.forEach(function(line) {
var lineWidth = ctx.measureText(line).width;
maxLineWidth = Math.max(maxLineWidth, lineWidth);
});
ew = Math.max(ew, maxLineWidth + (10 * zoomFactor));
var lineHeight = fontSize * 1.2;
var textHeight = lines.length * lineHeight;
eh = Math.max(eh, textHeight + (6 * zoomFactor));
}
return x >= ex && x <= ex + ew && y >= ey && y <= ey + eh;
}
@@ -403,17 +444,23 @@ window.initProfileInvoiceGenerator = function() {
isStatic: isStatic || false
};
// Helper function to calculate height based on font size and lines
function calculateHeight(fontSize, lineCount) {
var lineHeight = fontSize * 1.2;
return Math.round(lineCount * lineHeight + 6);
}
// Handle static elements (user data)
if (isStatic && staticText) {
el.text = staticText;
el.color = '#1976d2'; // Blue color for static elements
el.fontStyle = 'bold';
el.height = 20;
el.height = calculateHeight(el.fontSize, 1);
} else {
switch (type) {
case 'text':
el.text = 'Text eingeben...';
el.height = 20;
el.height = calculateHeight(el.fontSize, 1);
break;
case 'header':
el.text = 'Überschrift';
@@ -421,29 +468,29 @@ window.initProfileInvoiceGenerator = function() {
el.fontStyle = 'bold';
el.color = '#000000';
el.width = 200;
el.height = 30;
el.height = calculateHeight(el.fontSize, 1);
break;
case 'date':
el.text = 'Datum: ' + new Date().toLocaleDateString('de-DE');
el.fontSize = 12;
el.color = '#666666';
el.height = 16;
el.height = calculateHeight(el.fontSize, 1);
break;
case 'customer':
el.text = 'Kundenname\nStraße Nr.\nPLZ Ort';
el.height = 50;
el.fontSize = 12;
el.height = calculateHeight(el.fontSize, 3);
break;
case 'company':
el.text = 'Ihr Unternehmen\nIhre Straße\nIhre PLZ Ort';
el.height = 50;
el.fontSize = 12;
el.height = calculateHeight(el.fontSize, 3);
break;
case 'amount':
el.text = 'Gesamtbetrag: 0,00 €';
el.fontStyle = 'bold';
el.width = 180;
el.height = 20;
el.height = calculateHeight(el.fontSize, 1);
break;
case 'line':
el.text = '';
@@ -457,7 +504,7 @@ window.initProfileInvoiceGenerator = function() {
break;
default:
el.text = label || 'Neues Element';
el.height = 20;
el.height = calculateHeight(el.fontSize, 1);
}
}
@@ -492,6 +539,13 @@ window.initProfileInvoiceGenerator = function() {
var el = elements.find(function(e) { return e.id === id; });
if (el) {
el.fontSize = size;
// Update height based on text content and new font size
if (el.type !== 'line' && el.type !== 'image') {
var lines = (el.text || '').split('\n');
var lineHeight = size * 1.2;
var textHeight = lines.length * lineHeight;
el.height = Math.max(textHeight + 6, 20); // Minimum height of 20
}
draw();
}
};