fl-web-component 2.0.0-beta.8 → 2.0.0-beta.9
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/package.json
CHANGED
|
@@ -364,7 +364,9 @@ function drawLine(recordDxf, entity, group, key, configParams) {
|
|
|
364
364
|
|
|
365
365
|
// group.add(line);
|
|
366
366
|
}
|
|
367
|
+
|
|
367
368
|
function drawText(recordDxf, entity, group, key, configParams) {
|
|
369
|
+
|
|
368
370
|
let color=entity.color;
|
|
369
371
|
let rgb=decimalToRGBHex(color);
|
|
370
372
|
console.log(rgb);
|
|
@@ -374,22 +376,22 @@ function drawText(recordDxf, entity, group, key, configParams) {
|
|
|
374
376
|
hex='#000';
|
|
375
377
|
}
|
|
376
378
|
let text = entity.text;
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
x: parseFloat(x),
|
|
390
|
-
y: -parseFloat(y),
|
|
379
|
+
const fontSize = entity.textHeight;
|
|
380
|
+
|
|
381
|
+
// 与 AutoCAD TEXT 一致:绕插入点对齐锚点旋转;Y 轴翻转后角度用 360°-θ
|
|
382
|
+
const insert =
|
|
383
|
+
entity.endPoint &&
|
|
384
|
+
(entity.halign !== undefined || entity.valign !== undefined)
|
|
385
|
+
? entity.endPoint
|
|
386
|
+
: entity.startPoint;
|
|
387
|
+
|
|
388
|
+
const dim = new Konva.Text({
|
|
389
|
+
x: 0,
|
|
390
|
+
y: 0,
|
|
391
391
|
text: text,
|
|
392
392
|
fontSize: fontSize,
|
|
393
|
+
align: "left",
|
|
394
|
+
verticalAlign: "top",
|
|
393
395
|
fill: hex,
|
|
394
396
|
customColor: configParams ? configParams.color : "",
|
|
395
397
|
name: key.replace(/\s*/g, ""),
|
|
@@ -399,103 +401,75 @@ function drawText(recordDxf, entity, group, key, configParams) {
|
|
|
399
401
|
stroke: hex,
|
|
400
402
|
strokeWidth:0.1,
|
|
401
403
|
});
|
|
402
|
-
let width=dim.getTextWidth()
|
|
403
|
-
//let clientRect=dim.getClientRect()
|
|
404
|
-
//let clientWidth=clientRect.width;
|
|
405
404
|
|
|
406
|
-
if(entity.
|
|
407
|
-
|
|
408
|
-
dim.attrs.x= dim.attrs.x-(width/2);
|
|
409
|
-
}
|
|
405
|
+
if (entity.xScale) {
|
|
406
|
+
dim.scaleX(entity.xScale);
|
|
410
407
|
}
|
|
411
408
|
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
409
|
+
const tw = dim.width();
|
|
410
|
+
const th = dim.height();
|
|
411
|
+
const lh = dim.lineHeight() || 1;
|
|
412
|
+
// 用字体度量计算锚点,避免 valign=2(中线) 与 baseline 近似重合
|
|
413
|
+
let ascent = fontSize * lh * 0.8;
|
|
414
|
+
let descent = fontSize * lh * 0.2;
|
|
415
|
+
try {
|
|
416
|
+
const metrics = dim.measureSize(text || "M");
|
|
417
|
+
const mAscent =
|
|
418
|
+
metrics?.fontBoundingBoxAscent ??
|
|
419
|
+
metrics?.actualBoundingBoxAscent;
|
|
420
|
+
const mDescent =
|
|
421
|
+
metrics?.fontBoundingBoxDescent ??
|
|
422
|
+
metrics?.actualBoundingBoxDescent;
|
|
423
|
+
if (typeof mAscent === "number" && mAscent > 0) {
|
|
424
|
+
ascent = mAscent;
|
|
426
425
|
}
|
|
427
|
-
if(
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
//console.log("rect");
|
|
431
|
-
//console.log(rect);
|
|
432
|
-
dim.attrs.y= -parseFloat(y) - fontSize*0.85;
|
|
433
|
-
dim.attrs.x = parseFloat(x) - fontSize*0.85;
|
|
434
|
-
if(text.length>9){
|
|
435
|
-
let width=dim.getTextWidth()
|
|
436
|
-
//let clientRect=dim.getClientRect()
|
|
437
|
-
//let clientWidth=clientRect.width;
|
|
438
|
-
dim.attrs.y= -parseFloat(y) +fontSize;
|
|
439
|
-
if(entity.halign){
|
|
440
|
-
if(entity.halign==1){
|
|
441
|
-
dim.attrs.x= dim.attrs.x-(width/2);
|
|
442
|
-
}
|
|
443
|
-
|
|
444
|
-
}
|
|
445
|
-
if (entity.valign === 3) { // Middle
|
|
446
|
-
dim.attrs.x= dim.attrs.x+1;
|
|
447
|
-
dim.attrs.y = -parseFloat(y) +fontSize*1.8 ;
|
|
448
|
-
}
|
|
449
|
-
}else{
|
|
450
|
-
if (entity.valign === 3) { // Middle
|
|
451
|
-
dim.attrs.x= dim.attrs.x+1;
|
|
452
|
-
dim.attrs.y = -parseFloat(y) ;
|
|
453
|
-
}
|
|
454
|
-
}
|
|
455
|
-
}
|
|
456
|
-
if(parseInt(entity.rotation)==330||parseInt(entity.rotation)==329) {
|
|
457
|
-
//dim.attrs.x= parseFloat(x) -200;
|
|
458
|
-
|
|
459
|
-
//console.log("rect");
|
|
460
|
-
//console.log(rect);
|
|
461
|
-
dim.attrs.y= -parseFloat(y) -fontSize;
|
|
462
|
-
dim.attrs.x = parseFloat(x) +0.5;
|
|
426
|
+
if (typeof mDescent === "number" && mDescent >= 0) {
|
|
427
|
+
descent = mDescent;
|
|
463
428
|
}
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
//console.log(rect);
|
|
469
|
-
dim.attrs.y= -parseFloat(y) ;
|
|
470
|
-
dim.attrs.x = parseFloat(x) -fontSize;
|
|
471
|
-
}
|
|
472
|
-
|
|
429
|
+
} catch (e) {
|
|
430
|
+
// ignore
|
|
431
|
+
}
|
|
432
|
+
const baselineOffset = ascent;
|
|
473
433
|
|
|
474
|
-
|
|
434
|
+
const halign = entity.halign != null ? Number(entity.halign) : 0;
|
|
435
|
+
const valign = entity.valign != null ? Number(entity.valign) : 0;
|
|
475
436
|
|
|
476
|
-
|
|
437
|
+
let anchorX = 0;
|
|
438
|
+
if (halign === 1 || halign === 4) {
|
|
439
|
+
anchorX = tw / 2;
|
|
440
|
+
} else if (halign === 2) {
|
|
441
|
+
anchorX = tw;
|
|
442
|
+
}
|
|
477
443
|
|
|
478
|
-
|
|
444
|
+
let anchorY = baselineOffset;
|
|
445
|
+
if (valign === 3) {
|
|
446
|
+
anchorY = 0;
|
|
447
|
+
} else if (valign === 2) {
|
|
448
|
+
// DXF Middle: 使用字形上下边界中心,而不是 Konva 文本框中心
|
|
449
|
+
anchorY = (ascent + descent) / 2;
|
|
450
|
+
} else if (valign === 1) {
|
|
451
|
+
anchorY = ascent + descent;
|
|
479
452
|
|
|
480
|
-
// 支持 DXF 垂直对齐(valign),仅在未旋转时按插入点对齐
|
|
481
|
-
if (entity.valign === 2) { // Middle
|
|
482
|
-
dim.attrs.y = -parseFloat(y) - fontSize / 2;
|
|
483
|
-
} else if (entity.valign === 3) { // Top
|
|
484
|
-
dim.attrs.y = -parseFloat(y);
|
|
485
|
-
} else { // Baseline / Bottom 或未设置,保持原逻辑
|
|
486
|
-
dim.attrs.y = -parseFloat(y) - fontSize;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
if (entity.xScale) {
|
|
490
|
-
dim.attrs.fontSize =(fontSize+0.35)* entity.xScale;
|
|
491
453
|
}
|
|
492
454
|
|
|
455
|
+
dim.x(-anchorX);
|
|
456
|
+
dim.y(-anchorY);
|
|
493
457
|
|
|
458
|
+
const rotation = Number(entity.rotation || 0);
|
|
459
|
+
const g = new Konva.Group({
|
|
460
|
+
x: parseFloat(insert.x),
|
|
461
|
+
y: -parseFloat(insert.y),
|
|
462
|
+
rotation: 360 - rotation,
|
|
463
|
+
name: key.replace(/\s*/g, ""),
|
|
464
|
+
entityId: key,
|
|
465
|
+
visible: configParams ? configParams.visible : true,
|
|
466
|
+
customColor: configParams ? configParams.color : "",
|
|
467
|
+
});
|
|
468
|
+
g.add(dim);
|
|
494
469
|
|
|
495
|
-
//dim.attrs.x= dim.attrs.x-parseFloat(2);
|
|
496
470
|
group.push({
|
|
497
471
|
"type":'text',
|
|
498
|
-
'obj':
|
|
472
|
+
'obj': g,
|
|
499
473
|
})
|
|
500
474
|
// group.add(dim);
|
|
501
475
|
}
|