Exemplo n.º 1
0
        public void GetGillSansBlackMetrics()
        {
            var path      = new FileInfo(Path.Combine(System.Environment.CurrentDirectory, ValidateGillSans.UrlPath));
            var words     = TextToMeasure;
            var offset    = 0;
            var fontSize  = 12.0;
            var available = 1000; //fit all characters
            var options   = TypeMeasureOptions.Default;

            IFontMetrics metrics;

            using (var reader = new TypefaceReader())
            {
                var font = reader.GetFont(path, ValidateGillSans.BlackRegularIndex);

                metrics = font.GetMetrics(options);


                ValidateGillSans.AssertBlackMetrics(metrics);
                var size = metrics.MeasureLine(words, offset, fontSize, available, options);


                Assert.AreEqual(12.0, fontSize, "The measurements are for a point size of 12");
                Assert.AreEqual(words.Length, size.CharsFitted, "Should be able to fit everything in the first measurement");

                //checked to fit all at 140.53125
                Assert.AreEqual(199.46, Math.Round(size.RequiredWidth, 2), "The width of the string was not as statically caclulated");

                //checked height of a line to 12
                Assert.AreEqual(14.95, Math.Round(size.RequiredHeight, 2), "The height of the string was not as statically calculated");

                // check 2
                //reduce the size so not all characters can fit.
                //expected 90.50 and fitted 19
                available = 90;
                size      = metrics.MeasureLine(words, offset, fontSize, available, options);

                //This is the t
                Assert.AreEqual(13, size.CharsFitted);
                Assert.AreEqual(86.06, Math.Round(size.RequiredWidth, 2), "The width of the restricted string was not as statically calculated");
                Assert.AreEqual(14.95, Math.Round(size.RequiredHeight, 2), "The height of the string was not as statically calculated");


                // check 3
                //now set breaking on words only
                options.BreakOnWordBoundaries = true;

                size = metrics.MeasureLine(words, offset, fontSize, available, options);
                //This is the
                Assert.AreEqual(11, size.CharsFitted);
                Assert.AreEqual(75.30, Math.Round(size.RequiredWidth, 2), "The width of the restricted string was not as statically calculated");
                Assert.AreEqual(14.95, Math.Round(size.RequiredHeight, 2), "The height of the string was not as statically calculated");
            }
        }
        public void ValidGetFirstFontGillSansUrl()
        {
            var path = new Uri(ValidateGillSans.RootUrl);

            using (var reader = new TypefaceReader(path))
            {
                var url = new Uri(ValidateGillSans.UrlPath, UriKind.Relative);

                var face = reader.GetFirstFont(url);

                ValidateGillSans.AssertMatches(ValidateGillSans.FontTypefaces[0], face);
            }
        }
        public void ValidGetFirstFontGillSansPath()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

            using (var reader = new TypefaceReader(path))
            {
                var url = new FileInfo(ValidateGillSans.UrlPath);

                var face = reader.GetFirstFont(url);

                ValidateGillSans.AssertMatches(ValidateGillSans.FontTypefaces[0], face);
            }
        }
        public async Task GetFontsAsyncFromFile()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);
            var file = new FileInfo(System.IO.Path.Combine(path.FullName, ValidateGillSans.UrlPath));


            using (var reader = new TypefaceReader())
            {
                var faces = await reader.GetFontsAsync(file);

                ValidateGillSans.AssertTypefaces(faces.ToArray());
            }
        }
        public async Task GetFontsAsyncFromUri()
        {
            var path = new Uri(ValidateGillSans.RootUrl + ValidateGillSans.UrlPath);

            //Clean reader with a file stream

            using (var reader = new TypefaceReader())
            {
                var faces = await reader.GetFontsAsync(path);

                ValidateGillSans.AssertTypefaces(faces.ToArray());
            }
        }
        public void ValidGetFontGillSansBold()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

            using (var reader = new TypefaceReader(path))
            {
                var file  = new FileInfo(ValidateGillSans.UrlPath);
                var index = ValidateGillSans.BoldRegularIndex;

                var face = reader.GetFont(file, index);
                Assert.IsNotNull(face);

                ValidateGillSans.AssertMatches(ValidateGillSans.FontTypefaces[index], face);
            }
        }
        public async Task GetFontsAsyncFromRelativeUrl()
        {
            var path = new Uri(ValidateGillSans.RootUrl);

            //Set the base url

            using (var reader = new TypefaceReader(path))
            {
                //Set the relative path
                path = new Uri(ValidateGillSans.UrlPath, UriKind.Relative);

                var faces = await reader.GetFontsAsync(path);

                ValidateGillSans.AssertTypefaces(faces.ToArray());
            }
        }
        public async Task ValidGetFontGillSansSemiBoldItalic()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

            using (var reader = new TypefaceReader(path))
            {
                var file  = new FileInfo(ValidateGillSans.UrlPath);
                var index = ValidateGillSans.SemiBoldItalicIndex;

                var face = await reader.GetFontAsync(file, index);

                Assert.IsNotNull(face);

                ValidateGillSans.AssertMatches(ValidateGillSans.FontTypefaces[index], face);
            }
        }
Exemplo n.º 9
0
        public void ValidGetTypefacesGillSansUrl()
        {
            var path = new Uri(ValidateGillSans.RootUrl);

            using (var reader = new TypefaceReader(path))
            {
                var url = new Uri(ValidateGillSans.UrlPath, UriKind.Relative);

                var faces = reader.GetFonts(url);
                Assert.IsNotNull(faces);

                var all = faces.ToArray();
                Assert.AreEqual(9, all.Length);

                ValidateGillSans.AssertTypefaces(all);
            }
        }
Exemplo n.º 10
0
        public void ValidGetTypefacesGillSansPath()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

            using (var reader = new TypefaceReader(path))
            {
                var url = new FileInfo(ValidateGillSans.UrlPath);

                var faces = reader.GetFonts(url);
                Assert.IsNotNull(faces);

                var all = faces.ToArray();
                Assert.AreEqual(9, all.Length);

                ValidateGillSans.AssertTypefaces(all);
            }
        }
        public void ValidGetFontGillSansSemiBoldItalicFileInfoAndReference()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

            using (var reader = new TypefaceReader(path))
            {
                var file  = new FileInfo(ValidateGillSans.UrlPath);
                var index = ValidateGillSans.SemiBoldItalicIndex;

                var info = reader.ReadTypeface(file);
                var fref = info.Fonts[index];

                //Load from a known file and a font reference
                var face = reader.GetFont(file, fref);
                Assert.IsNotNull(face);

                ValidateGillSans.AssertMatches(ValidateGillSans.FontTypefaces[index], face);
            }
        }
        public async Task FailGetFontsAsyncFromRelativeUrl()
        {
            var path = new Uri(ValidateHelvetica.RootUrl);

            //Set the base url

            using (var reader = new TypefaceReader(path))
            {
                //Set the relative path
                path = new Uri("INVALID/" + ValidateHelvetica.UrlPath, UriKind.Relative);

                await Assert.ThrowsExceptionAsync <HttpRequestException>(async() =>
                {
                    var faces = await reader.GetFontsAsync(path);

                    ValidateGillSans.AssertTypefaces(faces.ToArray());
                });
            }
        }
        public void FailGetFontsFromRelativePath()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

            //Set the base url

            using (var reader = new TypefaceReader(path))
            {
                //Set the relative path
                var file = new FileInfo("INVALID/" + ValidateHelvetica.UrlPath);

                Assert.ThrowsException <TypefaceReadException>(() =>
                {
                    var faces = reader.GetFonts(file);

                    ValidateGillSans.AssertTypefaces(faces.ToArray());
                });
            }
        }
        public void ValidGetFontGillSansBoldInfoAndRef()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

            using (var reader = new TypefaceReader(path))
            {
                var file  = new FileInfo(ValidateGillSans.UrlPath);
                var index = ValidateGillSans.BoldRegularIndex;

                var info = reader.ReadTypeface(file);
                var fref = info.Fonts[index];

                //Get the font with the info and the font reference
                var face = reader.GetFont(info, fref);

                Assert.IsNotNull(face);

                //Make sure the style matches
                var expected = ValidateGillSans.FontTypefaces[index];
                ValidateGillSans.AssertMatches(expected, face);
            }
        }