示例#1
0
        public void FontCollection_TestAddFontWithSameId_ReturnsFalse()
        {
            var messenger      = Substitute.For <IFrameworkMessenger>();
            var surfaceManager = Substitute.For <IGpuSurfaceManager>();

            IFontCollection collection = new FontCollection(messenger, surfaceManager);

            collection.Add(12, Substitute.For <IFontModel>());
            Assert.False(collection.Add(12, Substitute.For <IFontModel>()));
        }
示例#2
0
        public void FontCollection_TestAddFont_ReturnCorrectCount()
        {
            var messenger      = Substitute.For <IFrameworkMessenger>();
            var surfaceManager = Substitute.For <IGpuSurfaceManager>();

            IFontCollection collection = new FontCollection(messenger, surfaceManager);

            collection.Add(0, Substitute.For <IFontModel>());
            collection.Add(1, Substitute.For <IFontModel>());
            collection.Add(2, Substitute.For <IFontModel>());
            collection.Add(3, Substitute.For <IFontModel>());
            collection.Add(4, Substitute.For <IFontModel>());

            Assert.Equal(5, collection.Count);
        }
示例#3
0
        private static Font CreateFont(string fontName, int size)
        {
            var    fontCollection = new FontCollection();
            string fontPath       = TestFontUtilities.GetPath(fontName);

            return(fontCollection.Add(fontPath).CreateFont(size));
        }
示例#4
0
        protected override void ProcessResource(FontCollection aFonts)
        {
            var files = GetXmlFiles(Directories.Fonts);

            if (files.Any())
            {
                OnCategoryProcessing(ResourceTypes.Fonts);
                var previous = SetCurrentDirectory(Directories.Fonts);

                foreach (var file in files)
                {
                    var document = LoadXml(file);

                    if (document != null)
                    {
                        aFonts.Add(new Font()
                        {
                            Name               = GetElement(document, "Name").Value,
                            ID                 = GetElementValue <int>(document, "ID"),
                            FontFamily         = GetElement(document, "FontFamily").Value,
                            Size               = GetElementValue <int>(document, "Size"),
                            Bold               = GetElementValue <bool>(document, "Bold"),
                            Italic             = GetElementValue <bool>(document, "Italic"),
                            CharacterRangeLow  = GetElementValue <ushort>(document, "CharacterRangeLow"),
                            CharacterRangeHigh = GetElementValue <ushort>(document, "CharacterRangeHigh"),
                            CharacterSet       = GetElementValue <Charset>(document, "CharacterSet"),
                            AntiAliasing       = GetElementValue <byte>(document, "AntiAliasing")
                        });
                    }
                }

                OnCategoryProcessed(ResourceTypes.Fonts);
                SetCurrentDirectory(previous);
            }
        }
示例#5
0
        public void GlyphMetricsVerticalMatchesReference()
        {
            // Compared to EveryFonts TTFDump metrics
            // https://everythingfonts.com/ttfdump
            var        collection = new FontCollection();
            FontFamily family     = collection.Add(TestFonts.NotoSansSCThinFile);
            Font       font       = family.CreateFont(12);

            var          codePoint     = new CodePoint('A');
            GlyphMetrics glyphMetrics  = font.FontMetrics.GetGlyphMetrics(codePoint, ColorFontSupport.None).First();
            GlyphMetrics glyphMetrics1 = font.GetGlyphs(codePoint, ColorFontSupport.None).First().GlyphMetrics;

            Assert.Equal(glyphMetrics, glyphMetrics1);

            // Position 0.
            Assert.Equal(codePoint, glyphMetrics.CodePoint);
            Assert.Equal(font.FontMetrics.UnitsPerEm, glyphMetrics.UnitsPerEm);
            Assert.Equal(glyphMetrics.UnitsPerEm * 72F, glyphMetrics.ScaleFactor);
            Assert.Equal(364, glyphMetrics.AdvanceWidth);
            Assert.Equal(1000, glyphMetrics.AdvanceHeight);
            Assert.Equal(265, glyphMetrics.Width);
            Assert.Equal(666, glyphMetrics.Height);
            Assert.Equal(33, glyphMetrics.LeftSideBearing);
            Assert.Equal(134, glyphMetrics.TopSideBearing);
            Assert.Equal(GlyphType.Fallback, glyphMetrics.GlyphType);
        }
示例#6
0
        public void GlyphMetricsMatchesReference_WithWoff1format()
        {
            // Compared to EveryFonts TTFDump metrics
            // https://everythingfonts.com/ttfdump
            var        collection = new FontCollection();
            FontFamily family     = collection.Add(TestFonts.OpenSansFileWoff1);
            Font       font       = family.CreateFont(12);

            var          codePoint     = new CodePoint('A');
            GlyphMetrics glyphMetrics  = font.FontMetrics.GetGlyphMetrics(codePoint, ColorFontSupport.None).First();
            GlyphMetrics glyphMetrics1 = font.GetGlyphs(codePoint, ColorFontSupport.None).First().GlyphMetrics;

            Assert.Equal(glyphMetrics, glyphMetrics1);

            Assert.Equal(codePoint, glyphMetrics.CodePoint);
            Assert.Equal(font.FontMetrics.UnitsPerEm, glyphMetrics.UnitsPerEm);
            Assert.Equal(glyphMetrics.UnitsPerEm * 72F, glyphMetrics.ScaleFactor);
            Assert.Equal(1295, glyphMetrics.AdvanceWidth);
            Assert.Equal(2789, glyphMetrics.AdvanceHeight);
            Assert.Equal(1293, glyphMetrics.Width);
            Assert.Equal(1468, glyphMetrics.Height);
            Assert.Equal(0, glyphMetrics.LeftSideBearing);
            Assert.Equal(721, glyphMetrics.TopSideBearing);
            Assert.Equal(GlyphType.Standard, glyphMetrics.GlyphType);
        }
示例#7
0
        public void FontCollection_TestRetrieveNonExisting_ReturnNull()
        {
            var messenger      = Substitute.For <IFrameworkMessenger>();
            var surfaceManager = Substitute.For <IGpuSurfaceManager>();

            IFontCollection collection = new FontCollection(messenger, surfaceManager);

            collection.Add(0, Substitute.For <IFontModel>());
            collection.Add(1, Substitute.For <IFontModel>());
            collection.Add(3, Substitute.For <IFontModel>());
            collection.Add(4, Substitute.For <IFontModel>());


            var font = collection.Retrieve(2);

            Assert.Null(font);
        }
示例#8
0
        public MemoryStream AddWatermark(string watermarkText, string ttfFontPath, int fontSize, Color color, WatermarkPosition watermarkPosition = WatermarkPosition.BottomRight, int textPadding = 10)
        {
            var fonts      = new FontCollection();
            var fontFamily = fonts.Add(ttfFontPath); //字体的路径(电脑自带字体库,去copy出来)
            var font       = new Font(fontFamily, fontSize, FontStyle.Bold);

            return(AddWatermark(watermarkText, font, color, watermarkPosition, textPadding));
        }
示例#9
0
 public void LoadFont(string path)
 {
     using var fontStream  = Loader.LoadStream(path);
     using MemoryStream ms = new MemoryStream();
     fontStream.CopyTo(ms);
     ms.Position = 0;
     var ffamily = fontCollection.Add(ms);
 }
示例#10
0
        public void AddViaPathReturnsDescription()
        {
            var sut = new FontCollection();

            sut.Add(TestFonts.CarterOneFile, out FontDescription description);

            Assert.NotNull(description);
            Assert.Equal("Carter One", description.FontFamilyInvariantCulture);
            Assert.Equal("Regular", description.FontSubFamilyNameInvariantCulture);
            Assert.Equal(FontStyle.Regular, description.Style);
        }
        private Font getFont(string fontName, float fontSize)
        {
            if (string.IsNullOrWhiteSpace(_options.CustomFontPath))
            {
                var fontFamily = SystemFonts.Get(fontName, CultureInfo.InvariantCulture);
                return(new Font(fontFamily, fontSize));
            }

            var fontCollection = new FontCollection();

            return(fontCollection.Add(_options.CustomFontPath, CultureInfo.InvariantCulture).CreateFont(fontSize));
        }
示例#12
0
        public void AddViaStreamReturnsDescription()
        {
            var sut = new FontCollection();

            using Stream s = TestFonts.CarterOneFileData();
            FontFamily family = sut.Add(s, out FontDescription description);

            Assert.NotNull(description);
            Assert.Equal("Carter One", description.FontFamilyInvariantCulture);
            Assert.Equal("Regular", description.FontSubFamilyNameInvariantCulture);
            Assert.Equal(FontStyle.Regular, description.Style);
        }
示例#13
0
        public void AddViaPathAddFontFileInstances()
        {
            var        sut    = new FontCollection();
            FontFamily family = sut.Add(TestFonts.CarterOneFile, out FontDescription descriptions);

            IEnumerable <FontMetrics> allInstances = ((IReadOnlyFontMetricsCollection)sut).GetAllMetrics(family.Name, CultureInfo.InvariantCulture);

            Assert.All(allInstances, i =>
            {
                FileFontMetrics font = Assert.IsType <FileFontMetrics>(i);
            });
        }
        public void FontClassWithPath_SetProperties()
        {
            var        collection = new FontCollection();
            FontFamily family     = collection.Add(TestFonts.CarterOneFile);
            var        font       = new Font(family, 12);

            Assert.Equal("Carter One", font.Name);
            Assert.Equal(12, font.Size);
            Assert.Equal(FontStyle.Regular, font.RequestedStyle);
            Assert.False(font.IsBold);
            Assert.False(font.IsItalic);
            Assert.True(font.TryGetPath(out string path));
            Assert.NotNull(path);
        }
示例#15
0
        public void FontCollection_TestRetrieveExisting_ReturnCorrectFont()
        {
            var messenger      = Substitute.For <IFrameworkMessenger>();
            var surfaceManager = Substitute.For <IGpuSurfaceManager>();

            IFontCollection collection = new FontCollection(messenger, surfaceManager);

            collection.Add(0, Substitute.For <IFontModel>());
            collection.Add(1, Substitute.For <IFontModel>());

            var fnt  = Substitute.For <IFontModel>();
            var code = fnt.GetHashCode();

            collection.Add(2, fnt);

            collection.Add(3, Substitute.For <IFontModel>());
            collection.Add(4, Substitute.For <IFontModel>());


            var font = collection.Retrieve(2);

            Assert.Equal(code, font.GetHashCode());
        }
示例#16
0
        public void FontMetricsMatchesReference()
        {
            // Compared to FontForge metrics.
            var        collection = new FontCollection();
            FontFamily family     = collection.Add(TestFonts.OpenSansFile);
            Font       font       = family.CreateFont(12);

            Assert.Equal(2048, font.FontMetrics.UnitsPerEm);
            Assert.Equal(2189, font.FontMetrics.Ascender);
            Assert.Equal(-600, font.FontMetrics.Descender);
            Assert.Equal(0, font.FontMetrics.LineGap);
            Assert.Equal(2789, font.FontMetrics.LineHeight);
            Assert.Equal(2470, font.FontMetrics.AdvanceWidthMax);
            Assert.Equal(font.FontMetrics.LineHeight, font.FontMetrics.AdvanceHeightMax);

            Assert.False(font.IsBold);
            Assert.False(font.IsItalic);
        }
示例#17
0
        public void FontMetricsVerticalFontMatchesReference()
        {
            // Compared to EveryFonts TTFDump metrics
            // https://everythingfonts.com/ttfdump
            var        collection = new FontCollection();
            FontFamily family     = collection.Add(TestFonts.NotoSansSCThinFile);
            Font       font       = family.CreateFont(12);

            Assert.Equal(1000, font.FontMetrics.UnitsPerEm);
            Assert.Equal(806, font.FontMetrics.Ascender);
            Assert.Equal(-256, font.FontMetrics.Descender);
            Assert.Equal(90, font.FontMetrics.LineGap);
            Assert.Equal(1152, font.FontMetrics.LineHeight);
            Assert.Equal(1000, font.FontMetrics.AdvanceWidthMax);
            Assert.Equal(1000, font.FontMetrics.AdvanceHeightMax);

            Assert.False(font.IsBold);
            Assert.False(font.IsItalic);
        }
示例#18
0
        public void FontCollection_TestRemoveFontAndReUseIndex_ReturnCorrectCountAndAddSuccessfully()
        {
            var messenger      = Substitute.For <IFrameworkMessenger>();
            var surfaceManager = Substitute.For <IGpuSurfaceManager>();

            IFontCollection collection = new FontCollection(messenger, surfaceManager);

            collection.Add(0, Substitute.For <IFontModel>());
            collection.Add(1, Substitute.For <IFontModel>());
            collection.Add(2, Substitute.For <IFontModel>());
            collection.Add(3, Substitute.For <IFontModel>());
            collection.Add(4, Substitute.For <IFontModel>());

            collection.Destroy(3, false);
            Assert.Equal(4, collection.Count);
            Assert.True(collection.Add(3, Substitute.For <IFontModel>()));
        }
示例#19
0
        public async Task CreateVideoAsync()
        {
            Stopwatch totalStopWatch = Stopwatch.StartNew();

            Directory.CreateDirectory(OriginalImagesPath);
            Directory.CreateDirectory(FramesPath);
            Directory.CreateDirectory(TitleFramesPath);
            Directory.CreateDirectory(AssetsPath);
            Directory.CreateDirectory(FFmpgPath);

            MyFontFamily = MyFontCollection.Add(
                Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "verdana.ttf")
                );

            // Get all images that should be converted to a video.
            Console.WriteLine($"Getting images...");
            Stopwatch     getImagesStopWatch = Stopwatch.StartNew();
            List <string> orgimages          = await GetOriginalImagesAsync();

            Console.WriteLine($"Done. {getImagesStopWatch.Elapsed}");
            Console.WriteLine($"");

            // Read the first video to setup the dimensions.
            int width, weight;

            using (Image image = await Image.LoadAsync(orgimages[0]))
            {
                width  = image.Width;
                weight = image.Height;
            }

            // Create title images
            Console.WriteLine($"Creating title frames...");
            Stopwatch titlesStopWatch = Stopwatch.StartNew();
            var       titleimages     = await CreateTitleScreenAsync(width, weight);

            Console.WriteLine($"Done. {titlesStopWatch.Elapsed}");

            // Create overlays. This is the original images but with a
            // timestamp on each image. The first images will also be
            // fading from the last title image.
            Console.WriteLine();
            Console.WriteLine($"Creating frames...");
            Stopwatch overlaysStopWatch = Stopwatch.StartNew();
            var       overlayimages     = await CreateOverlayImagesAsync(orgimages, titleimages.Last());

            // Creat a pretty thumbnail image.
            string thumbnailImagePath = Path.Combine(OutputPath, "thumbnail.png");

            await CreateThumbnailImageAsync(orgimages[orgimages.Count / 2], thumbnailImagePath).ConfigureAwait(false);

            Console.WriteLine($"Done. {overlaysStopWatch.Elapsed}");


            Console.WriteLine();
            Console.WriteLine($"Rendering...");
            Console.WriteLine();

            // Combine all images
            List <string> images = new List <string>();

            images.AddRange(titleimages);
            images.AddRange(overlayimages);

            string    audioPath       = Path.Combine(AssetsPath, "background.mp3");
            Stopwatch renderStopWatch = Stopwatch.StartNew();

            // Render the video
            await RenderVideoAsync(FramesPerSecond, images,
                                   Path.Combine(FFmpgPath, "ffmpeg.exe"),
                                   audioPath,
                                   thumbnailImagePath,
                                   Path.Combine(OutputPath, "out.mp4")
                                   ).ConfigureAwait(false);

            Console.WriteLine();
            Console.WriteLine($"Done. {renderStopWatch.Elapsed}");

            Console.WriteLine();
            Console.WriteLine($"All steps completed in {totalStopWatch.Elapsed}");
        }
示例#20
0
        public static void Main(string[] args)
        {
            var        fonts       = new FontCollection();
            var        woffFonts   = new FontCollection();
            FontFamily font        = fonts.Add(@"Fonts\SixLaborsSampleAB.ttf");
            FontFamily fontWoff    = woffFonts.Add(@"Fonts\SixLaborsSampleAB.woff");
            FontFamily fontWoff2   = woffFonts.Add(@"Fonts\OpenSans-Regular.woff2");
            FontFamily carter      = fonts.Add(@"Fonts\CarterOne.ttf");
            FontFamily wendyOne    = fonts.Add(@"Fonts\WendyOne-Regular.ttf");
            FontFamily whitneyBook = fonts.Add(@"Fonts\whitney-book.ttf");
            FontFamily colorEmoji  = fonts.Add(@"Fonts\Twemoji Mozilla.ttf");
            FontFamily font2       = fonts.Add(@"Fonts\OpenSans-Regular.ttf");
            FontFamily sunflower   = fonts.Add(@"Fonts\Sunflower-Medium.ttf");

#if OS_WINDOWS
            FontFamily emojiFont  = SystemFonts.Get("Segoe UI Emoji");
            FontFamily uiFont     = SystemFonts.Get("Segoe UI");
            FontFamily arabicFont = SystemFonts.Get("Dubai");

            FontFamily tahoma = SystemFonts.Get("Tahoma");
            RenderText(font2, "\uFB01", pointSize: 11.25F);
            RenderText(fontWoff2, "\uFB01", pointSize: 11.25F);
            RenderText(tahoma, "p", pointSize: 11.25F);
            RenderText(tahoma, "Lorem ipsum dolor sit amet", pointSize: 11.25F);
            return;

            RenderText(uiFont, "Soft\u00ADHyphen", pointSize: 72);
            FontFamily bugzilla = fonts.Add(@"Fonts\me_quran_volt_newmet.ttf");

            RenderText(uiFont, "Soft\u00ADHyphen", pointSize: 72);
            RenderText(bugzilla, "بِسْمِ ٱللَّهِ ٱلرَّحْمَٟنِ ٱلرَّحِيمِ", pointSize: 72);

            RenderText(uiFont, "first\n\n\n\nl", pointSize: 20, fallbackFonts: new[] { font2 });

            RenderText(uiFont, "first\n\n\n\nlast", pointSize: 20, fallbackFonts: new[] { font2 });
            RenderText(uiFont, "Testing", pointSize: 20);
            RenderText(emojiFont, "👩🏽‍🚒a", pointSize: 72, fallbackFonts: new[] { font2 });
            RenderText(arabicFont, "English اَلْعَرَبِيَّةُ English", pointSize: 20);
            RenderText(arabicFont, "English English", pointSize: 20);
            RenderText(arabicFont, "اَلْعَرَبِيَّةُ اَلْعَرَبِيَّةُ", pointSize: 20);
            RenderText(arabicFont, "اَلْعَرَبِيَّةُ", pointSize: 20);
            RenderText(arabicFont, "SS ص", pointSize: 20);
            RenderText(arabicFont, "S ص", pointSize: 20);
            RenderText(arabicFont, "English اَلْعَرَبِيَّةُ", pointSize: 20);

            RenderTextProcessorWithAlignment(emojiFont, "😀A😀", pointSize: 20, fallbackFonts: new[] { colorEmoji });
            RenderTextProcessorWithAlignment(uiFont, "this\nis\na\ntest", pointSize: 20, fallbackFonts: new[] { font2 });
            RenderTextProcessorWithAlignment(uiFont, "first\n\n\n\nlast", pointSize: 20, fallbackFonts: new[] { font2 });

            RenderText(emojiFont, "😀", pointSize: 72, fallbackFonts: new[] { font2 });
            RenderText(font2, string.Empty, pointSize: 72, fallbackFonts: new[] { emojiFont });
            RenderText(font2, "😀 Hello World! 😀", pointSize: 72, fallbackFonts: new[] { emojiFont });
#endif

            // fallback font tests
            RenderTextProcessor(colorEmoji, "a😀d", pointSize: 72, fallbackFonts: new[] { font2 });
            RenderText(colorEmoji, "a😀d", pointSize: 72, fallbackFonts: new[] { font2 });

            RenderText(colorEmoji, "😀", pointSize: 72, fallbackFonts: new[] { font2 });

            //// general
            RenderText(font, "abc", 72);
            RenderText(font, "ABd", 72);
            RenderText(fontWoff, "abe", 72);
            RenderText(fontWoff, "ABf", 72);
            RenderText(fontWoff2, "woff2", 72);
            RenderText(font2, "ov", 72);
            RenderText(font2, "a\ta", 72);
            RenderText(font2, "aa\ta", 72);
            RenderText(font2, "aaa\ta", 72);
            RenderText(font2, "aaaa\ta", 72);
            RenderText(font2, "aaaaa\ta", 72);
            RenderText(font2, "aaaaaa\ta", 72);
            RenderText(font2, "Hello\nWorld", 72);
            RenderText(carter, "Hello\0World", 72);
            RenderText(wendyOne, "Hello\0World", 72);
            RenderText(whitneyBook, "Hello\0World", 72);
            RenderText(sunflower, "í", 30);

            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 4
            }, "\t\tx");
            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 4
            }, "\t\t\tx");
            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 4
            }, "\t\t\t\tx");
            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 4
            }, "\t\t\t\t\tx");

            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 0
            }, "Zero\tTab");

            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 0
            }, "Zero\tTab");
            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 1
            }, "One\tTab");
            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 6
            }, "\tTab Then Words");
            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 1
            }, "Tab Then Words");
            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 1
            }, "Words Then Tab\t");
            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 1
            }, "                 Spaces Then Words");
            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 1
            }, "Words Then Spaces                 ");
            RenderText(new TextOptions(new Font(font2, 72))
            {
                TabWidth = 1
            }, "\naaaabbbbccccddddeeee\n\t\t\t3 tabs\n\t\t\t\t\t5 tabs");

#if OS_WINDOWS
            RenderText(new Font(SystemFonts.Get("Arial"), 20f, FontStyle.Regular), "á é í ó ú ç ã õ", 200, 50);
            RenderText(new Font(SystemFonts.Get("Arial"), 10f, FontStyle.Regular), "PGEP0JK867", 200, 50);
            RenderText(new TextOptions(SystemFonts.CreateFont("consolas", 72))
            {
                TabWidth = 4
            }, "xxxxxxxxxxxxxxxx\n\txxxx\txxxx\n\t\txxxxxxxx\n\t\t\txxxx");
            BoundingBoxes.Generate("a b c y q G H T", SystemFonts.CreateFont("arial", 40f));
            TextAlignmentSample.Generate(SystemFonts.CreateFont("arial", 50f));
            TextAlignmentWrapped.Generate(SystemFonts.CreateFont("arial", 50f));

            FontFamily simsum = SystemFonts.Get("SimSun");
            RenderText(simsum, "这是一段长度超出设定的换行宽度的文本,但是没有在设定的宽度处换行。这段文本用于演示问题。希望可以修复。如果有需要可以联系我。", 16);

            FontFamily jhengHei = SystemFonts.Get("Microsoft JhengHei");
            RenderText(jhengHei, " ,;:!¥()?{}-=+\|~!@#%&", 16);

            FontFamily arial = SystemFonts.Get("Arial");
            RenderText(arial, "ìíîï", 72);
#endif
            var sb = new StringBuilder();
            for (char c = 'a'; c <= 'z'; c++)
            {
                sb.Append(c);
            }

            for (char c = 'A'; c <= 'Z'; c++)
            {
                sb.Append(c);
            }

            for (char c = '0'; c <= '9'; c++)
            {
                sb.Append(c);
            }

            string text = sb.ToString();

            foreach (FontFamily f in fonts.Families)
            {
                RenderText(f, text, 72);
            }
        }
 /// <summary>
 /// Gets a font with the given name and size.
 /// </summary>
 /// <param name="collection">The collection to add the font to</param>
 /// <param name="name">The name of the font.</param>
 /// <param name="size">The font size.</param>
 /// <returns>The <see cref="Font"/></returns>
 public static Font GetFont(FontCollection collection, string name, float size)
 => collection.Add(GetPath(name)).CreateFont(size);
示例#22
0
        private void Load(CompoundFile doc)
        {
            Stream stream;
            try
            {
                // see if workbook works
                stream = doc.OpenStream("Workbook");
            }
            catch (IOException)
            {
                // see if book works, if not then leak the exception
                stream = doc.OpenStream("Book");
            }

            SstRecord sst = null;
            /* long sstPos = 0; */

            // record position dictionary
            SortedList<long, Biff> records = new SortedList<long, Biff>();

            _styles = new StyleCollection(this);
            _formats = new FormatCollection(this);
            _fonts = new FontCollection(this);
            _palette = new Palette(this);
            _hyperLinks = new HyperLinkCollection(this);

            while (stream.Length - stream.Position >= GenericBiff.MinimumSize)
            {
                // capture the current stream position
                long pos = stream.Position;

                // decode the record if possible
                Biff record = GetCorrectRecord(new GenericBiff(stream), stream, sst);

                // capture 
                // shared string table 
                if (record is SstRecord)
                {
                    Debug.Assert(sst == null);
                    sst = (SstRecord)record;
                    /* sstPos = pos; */
                }
                // formatting records
                else if (record is FormatRecord)
                {
                    FormatRecord f = (FormatRecord)record;
                    _formats.Add(f.Index, new Format(this, f));
                }
                else if (record is FontRecord)
                    _fonts.Add(new Font(this, (FontRecord)record));
                else if (record is PaletteRecord)
                    _palette.Initialize((PaletteRecord)record);
                else if (record is XfRecord)
                    _styles.Add(new Style(this, (XfRecord)record));
                else if (record is HyperLinkRecord)
                    _hyperLinks.Add((HyperLinkRecord)record);

                Debug.Assert(!records.ContainsKey(pos));
                // store the position and corresponding record
                records[pos] = record;
            }

            // generate the worksheets
            _sheets = new WorksheetCollection();
            foreach (Biff record in records.Values)
            {
                if (record is BoundSheetRecord)
                    _sheets.Add(new Worksheet(this, (BoundSheetRecord)record, records));
            }
        }