Esempio n. 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, "$ACADVER", StringComparison.OrdinalIgnoreCase) == 0 && section.Header.Version >= DxfAcadVersion.R2007)
                    {
                        // R2007 and up should switch to a UTF8 reader
                        buffer.SetUtf8Reader();
                    }
                }
            }

            return(section);
        }
Esempio n. 2
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);
                }
            }

            return(section);
        }
Esempio n. 3
0
        internal static DxfSection FromBuffer(DxfCodePairBufferReader buffer, DxfAcadVersion version)
        {
            Debug.Assert(buffer.ItemsRemain);
            var sectionType = buffer.Peek();

            buffer.Advance();
            if (sectionType.Code != 2)
            {
                throw new DxfReadException($"Expected code 2, got {sectionType.Code}", sectionType);
            }

            DxfSection section;

            switch (sectionType.StringValue)
            {
            case BlocksSectionText:
                section = DxfBlocksSection.BlocksSectionFromBuffer(buffer, version);
                break;

            case ClassesSectionText:
                section = DxfClassesSection.ClassesSectionFromBuffer(buffer, version);
                break;

            case EntitiesSectionText:
                section = DxfEntitiesSection.EntitiesSectionFromBuffer(buffer);
                break;

            case HeaderSectionText:
                section = DxfHeaderSection.HeaderSectionFromBuffer(buffer);
                break;

            case ObjectsSectionText:
                section = DxfObjectsSection.ObjectsSectionFromBuffer(buffer);
                break;

            case TablesSectionText:
                section = DxfTablesSection.TablesSectionFromBuffer(buffer);
                break;

            case ThumbnailImageSectionText:
                section = DxfThumbnailImageSection.ThumbnailImageSectionFromBuffer(buffer);
                break;

            default:
                SwallowSection(buffer);
                section = null;
                break;
            }

            return(section);
        }
Esempio n. 4
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);
        }