Example #1
0
        internal static DxfHeaderSection HeaderSectionFromBuffer(DxfCodePairBufferReader buffer)
        {
            var                section     = new DxfHeaderSection();
            string             keyName     = null;
            Func <short, bool> shortToBool = value => value != 0;

            while (buffer.ItemsRemain)
            {
                var pair = buffer.Peek();
                buffer.Advance();
                if (DxfCodePair.IsSectionEnd(pair))
                {
                    // done reading settings
                    break;
                }

                if (pair.Code == 9)
                {
                    // what setting to get
                    keyName = pair.StringValue;
                }
                else
                {
                    section.Header.SetHeaderVariable(keyName, pair);
                    if (string.Compare(keyName, "$DWGCODEPAGE", StringComparison.OrdinalIgnoreCase) == 0 && section.Header.Version <= DxfAcadVersion.R2004)
                    {
                        // R2004 and before should honor the specified code page
                        if (DxfEncodingHelper.TryParseEncoding(pair.StringValue, out var codePage))
                        {
                            var encoding = Encoding.GetEncoding(codePage);
                            buffer.SetReaderEncoding(encoding);
                        }
                    }
                    else if (string.Compare(keyName, "$ACADVER", StringComparison.OrdinalIgnoreCase) == 0 && section.Header.Version >= DxfAcadVersion.R2007)
                    {
                        // R2007 and up should switch to a UTF8 reader
                        buffer.SetReaderEncoding(Encoding.UTF8);
                    }
                }
            }

            return(section);
        }
Example #2
0
 public void ParseCodePageTest(string dxfLine, int expectedCodePage)
 {
     Assert.True(DxfEncodingHelper.TryParseEncoding(dxfLine, out var actualCodePage));
     Assert.Equal(expectedCodePage, actualCodePage);
 }