Skip to content

fix embeddedObject show problem #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion src/DxfScene.js
Original file line number Diff line number Diff line change
Expand Up @@ -881,7 +881,14 @@ export class DxfScene {
attachment: entity.attachmentPoint,
lineSpacing: entity.lineSpacing,
width: entity.width,
color, layer
color, layer,
boxHeight: entity?.boxHeight,
embeddedObject: entity?.embeddedObject,
// for future use: wrap text
embeddedObjectWidth: entity?.embeddedObjectWidth,
// for future use: wrap text
embeddedObjectGutterWidth: entity?.embeddedObjectGutterWidth,
embeddedObjectColumn: entity?.embeddedObjectColumn
})
}

Expand Down
16 changes: 13 additions & 3 deletions src/TextRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,12 @@ export class TextRenderer {
* glyph.
*/
*RenderMText({formattedText, position, fontSize, width = null, rotation = 0, direction = null,
attachment, lineSpacing = 1, color, layer = null}) {
attachment, lineSpacing = 1, color, layer = null, embeddedObject = false, boxHeight = 0,
embeddedObjectWidth = 0, embeddedObjectGutterWidth = 0, embeddedObjectColumn = 1}) {
const box = new TextBox(fontSize, this._GetCharShape.bind(this))
box.FeedText(formattedText)
yield* box.Render(position, width, rotation, direction, attachment, lineSpacing, color,
layer)
layer, boxHeight, embeddedObject, embeddedObjectWidth, embeddedObjectGutterWidth, embeddedObjectColumn)
}

/** @return {CharShape} Shape for the specified character.
Expand Down Expand Up @@ -499,7 +500,7 @@ class TextBox {
}
}

*Render(position, width, rotation, direction, attachment, lineSpacing, color, layer) {
*Render(position, width, rotation, direction, attachment, lineSpacing, color, layer, boxHeight = 0, embeddedObject = false, embeddedObjectWidth = 0, embeddedObjectGutterWidth = 0, embeddedObjectColumn = 1) {
for (const p of this.paragraphs) {
p.BuildLines(width)
}
Expand Down Expand Up @@ -596,6 +597,7 @@ class TextBox {
.rotate(-rotation * Math.PI / 180).translate(position.x, position.y)

let y = -this.fontSize
let changeXCount = 0;
for (const p of this.paragraphs) {
if (p.lines === null) {
y -= lineHeight
Expand All @@ -612,6 +614,14 @@ class TextBox {
if (chunkIdx === 0 || chunkIdx !== line.startChunkIdx) {
x += chunk.GetSpacingWidth()
}
// embeddedObject
if(embeddedObject){
if(Math.abs(y) >= boxHeight){
y = -this.fontSize
changeXCount++;
}
x += changeXCount*embeddedObjectWidth
}
const v = new Vector2(x, y)
v.applyMatrix3(transform)
if (chunk.block) {
Expand Down
111 changes: 71 additions & 40 deletions src/parser/entities/mtext.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,79 @@ export default function EntityParser() {}

EntityParser.ForEntityName = 'MTEXT';

EntityParser.prototype.parseEntity = function(scanner, curr) {
var entity = { type: curr.value };
EntityParser.prototype.parseEntity = function (scanner, curr) {
var entity = {type: curr.value, embeddedObject: false};
curr = scanner.next();
while(curr !== 'EOF') {
if(curr.code === 0) break;
while (curr !== 'EOF') {
if (curr.code === 0) break;

switch(curr.code) {
case 3:
case 1:
entity.text ? entity.text += curr.value : entity.text = curr.value;
break;
case 10:
entity.position = helpers.parsePoint(scanner);
break;
case 11:
entity.direction = helpers.parsePoint(scanner);
break;
case 40:
//Note: this is the text height
entity.height = curr.value;
break;
case 41:
entity.width = curr.value;
break;
case 44:
entity.lineSpacing = curr.value;
break;
case 50:
entity.rotation = curr.value;
break;
case 71:
entity.attachmentPoint = curr.value;
break;
case 72:
entity.drawingDirection = curr.value;
break;
case 101:
helpers.skipEmbeddedObject(scanner);
break;
default:
helpers.checkCommonEntityProperties(entity, curr, scanner);
break;
switch (curr.code) {
case 3:
case 1:
entity.text ? entity.text += curr.value : entity.text = curr.value;
break;
case 10:
if(!entity.embeddedObject){
entity.position = helpers.parsePoint(scanner);
}
break;
case 11:
if(!entity.embeddedObject){
entity.direction = helpers.parsePoint(scanner);
}
break;
case 40:
//Note: this is the text height
if(!entity.embeddedObject){
entity.height = curr.value;
}
break;
case 41:
if(!entity.embeddedObject){
entity.width = curr.value;
}
break;
case 44:
if(!entity.embeddedObject){
entity.lineSpacing = curr.value;
}else{
// this is the width of each column
entity.embeddedObjectWidth = curr.value;
}
break;
case 45:
if(entity.embeddedObject){
entity.embeddedObjectGutterWidth = curr.value;
}
break;
case 46:
if(!entity.embeddedObject){
entity.boxHeight = curr.value;
}
break;
case 50:
entity.rotation = curr.value;
break;
case 71:
if(!entity.embeddedObject){
entity.attachmentPoint = curr.value;
}
break;
case 72:
if(!entity.embeddedObject){
entity.drawingDirection = curr.value;
}else{
// this is numbers of columns
entity.embeddedObjectColumn = curr.value;
}
break;
case 101:
entity.embeddedObject = true;
// helpers.skipEmbeddedObject(scanner);
break;
default:
helpers.checkCommonEntityProperties(entity, curr, scanner);
break;
}
curr = scanner.next();
}
Expand Down