Open achuan666 opened 5 months ago
Would be helpful to write the issue in a compatible language :D. Can you share a dxf that I could use to test chinese characters?
镗孔夹具_A03.zip This is my model, in Chinese, but when I display it using three-dxf-viewer, some details seem to be missing, as well as garbled characters
Thanks~
modify function _getTextGeometry
in src/entites/textEntity
to
_getTextGeometry( entity ) {
let strings = this._getTextStrings( entity );
//TODO: if any string's width exceeds entity.refRectangleWidth we must cut it
let text = strings.join( '' );
// unicode转中文
text = text.replace(/\\u\+([\dA-F]{4})/gi, (match, grp) => {
return String.fromCharCode(parseInt(grp, 16));
});
if( Properties.onBeforeTextDraw ) {
let json = { text: text };
Properties.onBeforeTextDraw( json );
text = json.text;
}
//get size
let textSize = this._getTextHeight( entity );
//generate shape
let shapes = this._font.generateShapes( text, textSize );
return new ShapeGeometry( shapes );
}
and then modify font
in src/example/layer/index.js
to a Chinese font json. This is one can be used and I have tested.
Microsoft_YaHei_Regular.json.zip
run npm run dev
and enjoy yourself.
By the way, you'd better modify function _getTextHeight
in src/entites/textEntity
to
_getTextHeight( entity ) {
let textSize = 12;
if ( typeof entity.nominalTextHeight !== 'undefined' )
textSize = entity.nominalTextHeight;
else if ( typeof entity.textHeight !== 'undefined' )
textSize = entity.textHeight;
textSize = textSize * 0.8; // downsize the text size to have better layout
return textSize;
}
dxf文件已经渲染出来了,但是文件里面的中文以问号线上,请问下怎么设置可以识别中文字符