gemini-viewer-examples icon indicating copy to clipboard operation
gemini-viewer-examples copied to clipboard

中文字体乱码问题

Open woshichen62 opened this issue 1 year ago • 10 comments

image 上传了带有中文字体的dxf文件后,出现字体问题,我看到#85的Issues有相关的问题,需要设置编码格式为unicode,但是不知道是如何解决的,请指导以下,谢谢

woshichen62 avatar Oct 28 '24 02:10 woshichen62

const modelCfg: ModelConfig = {
    modelId: "id_0",
    name: "sample",
    src: "http://www.abc.com/sample.dxf",
    encoding: "gb2312",
}

yanzexuan1 avatar Oct 28 '24 06:10 yanzexuan1

已经解决了,谢谢

woshichen62 avatar Oct 29 '24 01:10 woshichen62

还有一个小问题: const modelUploader = new LocalDxfUploader(viewer); 通过LocalDxfUploader上传的dxf文件,该如何设置viewer的modelCfg呢?

woshichen62 avatar Oct 29 '24 01:10 woshichen62

以下是通过demo预览的效果 image 以下是通过CAD打开的效果,dxf文档中的图片在demo中不显示,是需要哪方面的设置吗?

woshichen62 avatar Oct 29 '24 02:10 woshichen62

image 补充CAD预览效果

woshichen62 avatar Oct 29 '24 02:10 woshichen62

This can be fixed, there is no image in the dxf file. When you process DWG file, you should put image somewhere, so you can access it with a url, then can be rendered properly,

yanzexuan1 avatar Nov 13 '24 14:11 yanzexuan1

谢谢,我是用libredwg做的转换,同样的dxf文件在AutoCad中是可以看到图片,在咱们的demo中是看不到的,上文说的图片路径是需要单独在demo工程设置吗?能否给一个示例性代码呢…… 再次谢谢。

woshichen62 avatar Nov 14 '24 00:11 woshichen62

const modelCfg: ModelConfig = {
    modelId: "id_0",
    name: "sample",
    src: "http://www.abc.com/sample.dxf",
    encoding: "gb2312",
}

老哥 这个怎么使用的,求指导一下。我这个还是打开后显示的乱码

Image

ZhuHongji626 avatar Nov 02 '25 09:11 ZhuHongji626

You need to find out your file's encoding, which can be gb231, etc. If you don't know, then probably need to try several common ones. Try different encodings here:

const viewerCfg: DxfViewerConfig = {
    containerId: "myCanvas",
    enableSpinner: true,
    enableLayoutBar: true,
};
const modelCfg: ModelConfig = {
    modelId: "id_0",
    name: "sample",
    src: "http://www.abc.com/sample.dxf",
    encoding: "gb2312",
}
const fontFiles = ["http://www.abc.com/hztxt.shx", "http://www.abc.com/simplex.shx"];

const viewer = new DxfViewer(viewerCfg);
await viewer.setFont(fontFiles);
await viewer.loadModelAsync(modelCfg, (event) => {
    const progress = (event.loaded * 100) / event.total;
    console.log(`${event.type}: ${progress}%`);
});

yanzexuan1 avatar Nov 04 '25 09:11 yanzexuan1

You need to find out your file's encoding, which can be gb231, etc. If you don't know, then probably need to try several common ones. Try different encodings here:

const viewerCfg: DxfViewerConfig = {
    containerId: "myCanvas",
    enableSpinner: true,
    enableLayoutBar: true,
};
const modelCfg: ModelConfig = {
    modelId: "id_0",
    name: "sample",
    src: "http://www.abc.com/sample.dxf",
    encoding: "gb2312",
}
const fontFiles = ["http://www.abc.com/hztxt.shx", "http://www.abc.com/simplex.shx"];

const viewer = new DxfViewer(viewerCfg);
await viewer.setFont(fontFiles);
await viewer.loadModelAsync(modelCfg, (event) => {
    const progress = (event.loaded * 100) / event.total;
    console.log(`${event.type}: ${progress}%`);
});

OK thanks

ZhuHongji626 avatar Nov 15 '25 07:11 ZhuHongji626

谢谢楼上各位朋友呀,如果使用LocalDxfUploader组价, modelUploader.openFileBrowserToUpload()

该怎么传入modelConfig啊

yuleigit avatar Dec 04 '25 01:12 yuleigit

可不一块自己动辨别utf8和gbk?

yuleigit avatar Dec 04 '25 01:12 yuleigit

您好,您的来信已收到,我将会尽快给您回复,谢谢~~

lkx007 avatar Dec 04 '25 01:12 lkx007

我轮流试了下,utf8的时候有部分字体是乱码,gb2312时候都是乱码。。

yuleigit avatar Dec 04 '25 02:12 yuleigit