Free, open-source file converter. Convert 263 formats offline by drag & drop — images, PDF, Word, Excel, PowerPoint, HWP/HWPX, video, audio, e-books and archives. No upload, no Office needed.
C# audio-converteravaloniabatch-conversionconvertercsharpdocument-converterdocx-to-pdfdotnetdrag-and-dropfile-conversionfile-converterheic-converterhwphwpximage-converterlinuxmacospdf-convertervideo-converterwindows
CAD code pages: count and escape names, one ? per emoji (#497 review)
cre8ive-marketingb75684c3af73
diff --git a/src/Filee.Engines/Cad/CadCodePages.cs b/src/Filee.Engines/Cad/CadCodePages.csindex 25047707..8a52e611 100644--- a/src/Filee.Engines/Cad/CadCodePages.cs+++ b/src/Filee.Engines/Cad/CadCodePages.cs@@ -70,8 +70,10 @@ internal static class CadCodePages{if (c <= 0x7F || Holds(encoding, c))result.Append(c);- else if (char.IsSurrogate(c))- result.Append('?'); // \U+ takes four hex digits: nothing outside the BMP fits+ else if (char.IsHighSurrogate(c))+ result.Append('?'); // \U+ takes four hex digits: nothing outside the BMP fits, one ? per character+ else if (char.IsLowSurrogate(c))+ continue;elseresult.Append($"\\U+{(int)c:X4}");}@@ -98,14 +100,36 @@ internal static class CadCodePages_ => null,};- /// <summary>Every text a drawing shows: TEXT and attributes, MTEXT, dimension text, attributes of inserts.</summary>+ /// <summary>+ /// Every text a drawing holds in its code page: TEXT and attributes (values and tags), MTEXT, dimension text, and+ /// the names of layers, blocks, text and dimension styles, linetypes and layouts. Korean layer names with English+ /// labels are common, so names count when the code page is picked, and are escaped like text.+ /// </summary>private static IEnumerable<(Func<string> Get, Action<string> Set)> Texts(CadDocument document){+ foreach (var layer in document.Layers)+ yield return (() => layer.Name, v => layer.Name = v);+ foreach (var style in document.TextStyles)+ yield return (() => style.Name, v => style.Name = v);+ foreach (var style in document.DimensionStyles)+ yield return (() => style.Name, v => style.Name = v);+ foreach (var lineType in document.LineTypes)+ yield return (() => lineType.Name, v => lineType.Name = v);+ foreach (var layout in document.Layouts)+ yield return (() => layout.Name, v => layout.Name = v);foreach (var record in document.BlockRecords)+ {+ // *Model_Space, *Paper_Space and anonymous blocks are ASCII by definition.+ if (!record.Name.StartsWith('*'))+ yield return (() => record.Name, v => record.Name = v);foreach (var entity in record.Entities){switch (entity){+ case AttributeDefinition definition:+ yield return (() => definition.Value ?? "", v => definition.Value = v);+ yield return (() => definition.Tag ?? "", v => definition.Tag = v);+ break;case TextEntity text:yield return (() => text.Value ?? "", v => text.Value = v);break;@@ -117,9 +141,13 @@ internal static class CadCodePagesbreak;case Insert insert:foreach (var attribute in insert.Attributes)+ {yield return (() => attribute.Value ?? "", v => attribute.Value = v);+ yield return (() => attribute.Tag ?? "", v => attribute.Tag = v);+ }break;}}+ }}}diff --git a/tests/Filee.Engines.Tests/CadVersionTests.cs b/tests/Filee.Engines.Tests/CadVersionTests.csindex 5b38f127..158d43f1 100644--- a/tests/Filee.Engines.Tests/CadVersionTests.cs+++ b/tests/Filee.Engines.Tests/CadVersionTests.cs@@ -94,6 +94,53 @@ public class CadVersionTests(EngineFixture fx) : IClassFixture<EngineFixture>Assert.Contains(@"\U+8FD9", raw); // 这 isn't in CP949}+ [Theory]+ [InlineData("dxf", CadVersion.AutoCad2000)]+ [InlineData("dxf", CadVersion.AutoCad2004)]+ [InlineData("dwg", CadVersion.AutoCad2000)]+ [InlineData("dwg", CadVersion.AutoCad2004)]+ public async Task Korean_names_pick_the_code_page_even_with_english_text(string format, CadVersion version)+ {+ // A layer and a block named in Korean, an attribute tag too, and only English text: common in Korean drawings.+ var doc = new CadDocument();+ doc.Header.CodePage = "ANSI_1252";+ var wall = new Layer("벽체") { Color = CadBuilder.Visible };+ doc.Layers.Add(wall);+ CadBuilder.Add(doc, wall, new Line(new XYZ(0, 0, 0), new XYZ(100, 0, 0)));+ CadBuilder.Add(doc, wall, new TextEntity("Wall A") { InsertPoint = new XYZ(0, 5, 0), Height = 3 });+ CadBuilder.Add(doc, wall, new AttributeDefinition { Tag = "도면번호", Value = "A-101", Height = 3 });+ var source = format == "dxf" ? CadBuilder.SaveDxf(doc, fx.NewFolder(), "walls.dxf") : SaveDwg(doc, "walls.dwg");++ var back = ReadBack(await ConvertAsync(source, format, version));++ Assert.Contains(back.Layers, l => l.Name == "벽체");+ Assert.Contains(back.Entities.OfType<AttributeDefinition>(), a => a.Tag == "도면번호");+ Assert.Contains("Wall A", Shown(back));+ }++ [Fact]+ public async Task Names_and_text_the_code_page_cant_hold_are_escaped_and_an_emoji_is_one_question_mark()+ {+ var doc = new CadDocument();+ doc.Header.CodePage = "ANSI_1252";+ var layer = new Layer("평면 这") { Color = CadBuilder.Visible };+ doc.Layers.Add(layer);+ CadBuilder.Add(doc, layer, new TextEntity("한글 도면 😀 끝") { InsertPoint = new XYZ(0, 0, 0), Height = 3 });+ var source = CadBuilder.SaveDxf(doc, fx.NewFolder(), "mixed.dxf");++ var back = ReadBack(await ConvertAsync(source, "dxf", CadVersion.AutoCad2004));++ Assert.Contains(back.Layers, l => CadTextCodes.DecodeText(l.Name) == "평면 这");+ Assert.Contains("한글 도면 ? 끝", Shown(back));+ }++ private string SaveDwg(CadDocument doc, string name)+ {+ var path = Path.Combine(fx.NewFolder(), name);+ DwgWriter.Write(path, doc);+ return path;+ }+[Fact]public void The_code_page_follows_the_text(){