Пример #1
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);
        }
        internal static DxfThumbnailImageSection ThumbnailImageSectionFromBuffer(DxfCodePairBufferReader buffer)
        {
            if (buffer.ItemsRemain)
            {
                var lengthPair = buffer.Peek();
                buffer.Advance();

                if (lengthPair.Code != 90)
                {
                    return(null);
                }

                var length = lengthPair.IntegerValue;
                var lines  = new List <string>();
                while (buffer.ItemsRemain)
                {
                    var pair = buffer.Peek();
                    buffer.Advance();

                    if (DxfCodePair.IsSectionEnd(pair))
                    {
                        break;
                    }

                    Debug.Assert(pair.Code == 310);
                    lines.Add(pair.StringValue);
                }

                var section = new DxfThumbnailImageSection();
                section.Clear();
                section.RawData = DxfCommonConverters.HexBytes(string.Join(string.Empty, lines.ToArray()));
                return(section);
            }

            return(null);
        }
        internal static DxfThumbnailImageSection ThumbnailImageSectionFromBuffer(DxfCodePairBufferReader buffer)
        {
            if (buffer.ItemsRemain)
            {
                var lengthPair = buffer.Peek();
                buffer.Advance();

                if (lengthPair.Code != 90)
                {
                    return(null);
                }

                var length  = lengthPair.IntegerValue;
                var rawData = new List <byte>();
                while (buffer.ItemsRemain)
                {
                    var pair = buffer.Peek();
                    buffer.Advance();

                    if (DxfCodePair.IsSectionEnd(pair))
                    {
                        break;
                    }

                    Debug.Assert(pair.Code == 310);
                    rawData.AddRange(pair.BinaryValue);
                }

                var section = new DxfThumbnailImageSection();
                section.Clear();
                section.RawData = rawData.ToArray();
                return(section);
            }

            return(null);
        }
Пример #4
0
 /// <summary>
 /// Sets the bitmap thumbnail.
 /// </summary>
 /// <param name="thumbnail">Raw data of the thumbnail image.  Should be a 256-color bitmap, 180 pixels wide, any height.</param>
 public void SetThumbnailBitmap(byte[] thumbnail)
 {
     if (ThumbnailImageSection == null)
         ThumbnailImageSection = new DxfThumbnailImageSection();
     ThumbnailImageSection.SetThumbnailBitmap(thumbnail);
 }
Пример #5
0
        internal static DxfThumbnailImageSection ThumbnailImageSectionFromBuffer(DxfCodePairBufferReader buffer)
        {
            if (buffer.ItemsRemain)
            {
                var lengthPair = buffer.Peek();
                buffer.Advance();

                if (lengthPair.Code != 90)
                {
                    return null;
                }

                var length = lengthPair.IntegerValue;
                var lines = new List<string>();
                while (buffer.ItemsRemain)
                {
                    var pair = buffer.Peek();
                    buffer.Advance();

                    if (DxfCodePair.IsSectionEnd(pair))
                    {
                        break;
                    }

                    Debug.Assert(pair.Code == 310);
                    lines.Add(pair.StringValue);
                }

                var section = new DxfThumbnailImageSection();
                section.RawData = DxfCommonConverters.HexBytes(string.Join(string.Empty, lines));
                return section;
            }

            return null;
        }