Exemplo n.º 1
0
        public void GetRobotoMetrics()
        {
            var path      = new FileInfo(Path.Combine(System.Environment.CurrentDirectory, ValidateRoboto.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.GetFirstFont(path);

                metrics = font.GetMetrics(options);


                ValidateRoboto.AssertMetrics(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(140.95, 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.06, 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 text t
                Assert.AreEqual(18, size.CharsFitted);
                Assert.AreEqual(84.52, Math.Round(size.RequiredWidth, 2), "The width of the restricted string was not as statically calculated");
                Assert.AreEqual(14.06, 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 text
                Assert.AreEqual(16, size.CharsFitted);
                Assert.AreEqual(77.62, Math.Round(size.RequiredWidth, 2), "The width of the restricted string was not as statically calculated");
                Assert.AreEqual(14.06, Math.Round(size.RequiredHeight, 2), "The height of the string was not as statically calculated");
            }
        }
Exemplo n.º 2
0
        public void ValidGetTypefacesRobotoFile()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

            using (var reader = new TypefaceReader(path))
            {
                var file = new FileInfo(ValidateRoboto.UrlPath);

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

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

                ValidateRoboto.AssertTypeface(all[0]);
            }
        }