public void TypeMeasureOptions_FontUnitTypo()
        {
            var options = TypeMeasureOptions.BreakOnWords;

            options.IgnoreStartingWhiteSpace = true;
            options.FontUnits = FontUnitType.UseTypographicMetrics;

            Assert.IsFalse(options.CharacterSpacing.HasValue);
            Assert.IsFalse(options.WordSpacing.HasValue);

            Assert.IsTrue(options.BreakOnWordBoundaries, "The static break on words should have this flag as true");
            Assert.IsTrue(options.IgnoreStartingWhiteSpace, "The starting white space should be ignored");
            Assert.AreEqual(FontUnitType.UseTypographicMetrics, options.FontUnits, "The font units should be the header metrics");


            using (var reader = new TypefaceReader())
            {
                ITypefaceFont font = reader.GetFirstFont(path);

                Assert.IsNotNull(font);
                Assert.IsTrue(font.FamilyName == ValidateHelvetica.FamilyName);

                var metrics = font.GetMetrics(options);
                Assert.IsNotNull(metrics);

                var size = metrics.MeasureLine(TextToMeasure, 0, fontSize, availableWidth, options);

                Assert.AreEqual(TextToMeasure.Length, size.CharsFitted, "Should have fitted all the characters");
                Assert.IsFalse(size.OnWordBoudary, "Should not be breaking on a word boundary, as eveything fitted");
                Assert.AreEqual(11.4, Math.Round(size.RequiredHeight, 1), "Should use the typographic size, rather than header.");
            }
        }
Exemple #2
0
 public static void AssertMatches(FontFace expected, ITypefaceFont font)
 {
     Assert.IsNotNull(font);
     Assert.AreEqual(FamilyName, font.FamilyName);
     Assert.AreEqual(expected.Weight, font.FontWeight);
     Assert.AreEqual(expected.Width, font.FontWidth);
     Assert.AreEqual(expected.Selection, font.Selections);
 }
Exemple #3
0
 public static void AssertTypeface(ITypefaceFont typeface)
 {
     Assert.IsNotNull(typeface);
     Assert.AreEqual(FamilyName, typeface.FamilyName, "The font names did not match for the typeface " + typeface);
     Assert.AreEqual(Weight, typeface.FontWeight, "The font weights did not match for test " + typeface);
     Assert.AreEqual(Width, typeface.FontWidth, "The font widths did not match for test " + typeface);
     Assert.AreEqual(Restrictions, typeface.Restrictions, "The font restrictions did not match for test " + typeface);
     Assert.AreEqual(Selections, typeface.Selections, "The font selctions did not match for test " + typeface);
     Assert.AreEqual(DataFormat.TTF, typeface.SourceFormat);
 }
        public void TypeMeasureOptions_IgnoreStartingWhitespace()
        {
            var options = TypeMeasureOptions.BreakOnWords;

            options.IgnoreStartingWhiteSpace = true;

            Assert.IsFalse(options.CharacterSpacing.HasValue);
            Assert.IsFalse(options.WordSpacing.HasValue);

            Assert.IsTrue(options.BreakOnWordBoundaries, "The static break on words should have this flag as true");
            Assert.IsTrue(options.IgnoreStartingWhiteSpace, "The starting white space should be ignored");
            Assert.AreEqual(FontUnitType.UseFontPreference, options.FontUnits);


            using (var reader = new TypefaceReader())
            {
                ITypefaceFont font = reader.GetFirstFont(path);

                Assert.IsNotNull(font);
                Assert.IsTrue(font.FamilyName == ValidateHelvetica.FamilyName);

                var metrics = font.GetMetrics(options);
                Assert.IsNotNull(metrics);

                var size = metrics.MeasureLine(TextToMeasure, 0, fontSize, availableWidth, options);

                Assert.AreEqual(TextToMeasure.Length, size.CharsFitted, "Should have fitted all the characters");
                Assert.IsFalse(size.OnWordBoudary, "Should not be breaking on a word boundary, as eveything fitted");
                Assert.AreEqual(12.0, size.RequiredHeight, "Helvetica font preferences should use the font header size, rather than typographic.");


                //Check the smaller size

                // "This is the text"
                // "to measure"

                size = metrics.MeasureLine(TextToMeasure, 0, fontSize, smallWidth, options);

                Assert.AreEqual(16, size.CharsFitted, "Can only fit 16 chars on smaller width with word break");
                Assert.IsTrue(size.OnWordBoudary, "Breaking on word boundary should be true");
                Assert.AreEqual(12.0, size.RequiredHeight, "Helvetica font preferences should use the font header size, rather than typographic.");

                //Check the remaining text
                size = metrics.MeasureLine(TextToMeasure, size.CharsFitted, fontSize, smallWidth, options);

                Assert.AreEqual(17, size.FirstCharacter, "The space should be ignored and the first character should be the 't' at index 17");
                Assert.AreEqual(TextToMeasure.Length - size.FirstCharacter, size.CharsFitted, "Should have been able to fit the remaining text");
            }
        }
        public void TypeMeasureOptions_Default()
        {
            var options = TypeMeasureOptions.Default;

            Assert.IsFalse(options.CharacterSpacing.HasValue);
            Assert.IsFalse(options.WordSpacing.HasValue);

            Assert.IsFalse(options.BreakOnWordBoundaries);
            Assert.IsFalse(options.IgnoreStartingWhiteSpace);
            Assert.AreEqual(FontUnitType.UseFontPreference, options.FontUnits);


            using (var reader = new TypefaceReader())
            {
                ITypefaceFont font = reader.GetFirstFont(path);

                Assert.IsNotNull(font);
                Assert.IsTrue(font.FamilyName == ValidateHelvetica.FamilyName);

                var metrics = font.GetMetrics(options);
                Assert.IsNotNull(metrics);

                var size = metrics.MeasureLine(TextToMeasure, 0, fontSize, availableWidth, options);

                Assert.AreEqual(TextToMeasure.Length, size.CharsFitted, "Should have fitted all the characters");
                Assert.IsFalse(size.OnWordBoudary, "Should not be breaking on a word boundary");
                Assert.AreEqual(12.0, size.RequiredHeight, "Helvetica font preferences should use the font header size, rather than typographic.");


                //Check the smaller size

                // "This is the text t"
                // "o measure"

                size = metrics.MeasureLine(TextToMeasure, 0, fontSize, smallWidth, options);

                Assert.AreEqual(18, size.CharsFitted, "Can only fit 18 chars on smaller width");
                Assert.IsFalse(size.OnWordBoudary, "Breaking on word boundary should be false");
                Assert.AreEqual(12.0, size.RequiredHeight, "Helvetica font preferences should use the font header size, rather than typographic.");
            }
        }
        public void TypeMeasureOptions_CharacterAndWordSpacing()
        {
            var options = TypeMeasureOptions.Default;

            Assert.IsFalse(options.CharacterSpacing.HasValue);
            Assert.IsFalse(options.WordSpacing.HasValue);

            Assert.IsFalse(options.BreakOnWordBoundaries);
            Assert.IsFalse(options.IgnoreStartingWhiteSpace);
            Assert.AreEqual(FontUnitType.UseFontPreference, options.FontUnits);


            using (var reader = new TypefaceReader())
            {
                ITypefaceFont font = reader.GetFirstFont(path);

                Assert.IsNotNull(font);
                Assert.IsTrue(font.FamilyName == ValidateHelvetica.FamilyName);

                var metrics = font.GetMetrics(options);
                Assert.IsNotNull(metrics);

                //Without spacing should be 140.53 wide
                var size = metrics.MeasureLine(TextToMeasure, 0, fontSize, availableWidth, options);

                Assert.AreEqual(TextToMeasure.Length, size.CharsFitted, "Should have fitted all the characters");
                Assert.IsFalse(size.OnWordBoudary, "Should not be breaking on a word boundary");
                Assert.AreEqual(12.0, size.RequiredHeight, "Helvetica font preferences should use the font header size, rather than typographic.");
                Assert.AreEqual(140.53, Math.Round(size.RequiredWidth, 2), "The width of the string was not as statically caclulated");

                options.CharacterSpacing = 2.0;
                options.WordSpacing      = 5.0;
                var extra = (options.CharacterSpacing * 22.0) + (options.WordSpacing * 5); // 22 character spaces + 5 word spaces in the text to measure


                size = metrics.MeasureLine(TextToMeasure, 0, fontSize, availableWidth, options);

                Assert.AreEqual(TextToMeasure.Length, size.CharsFitted, "Should have fitted all the characters");
                Assert.IsFalse(size.OnWordBoudary, "Should not be breaking on a word boundary");
                Assert.AreEqual(12.0, size.RequiredHeight, "Helvetica font preferences should use the font header size, rather than typographic.");
                Assert.AreEqual(140.53 + extra, Math.Round(size.RequiredWidth, 2), "The width of the string did not match with the expected word and character spacing");


                //Check the smaller size with the extra spacing

                // "This is the tex"
                // "t to measure"

                size = metrics.MeasureLine(TextToMeasure, 0, fontSize, smallWidth, options);

                Assert.AreEqual(11, size.CharsFitted, "Can only fit 11 chars on smaller width with extra character and word space");
                Assert.IsFalse(size.OnWordBoudary, "Breaking on word boundary should be false");
                Assert.AreEqual(12.0, size.RequiredHeight, "Helvetica font preferences should use the font header size, rather than typographic.");


                //Check the smaller size with the extra spacing and break on words

                // "This is the"
                // " text to measure"

                options.BreakOnWordBoundaries = true;

                size = metrics.MeasureLine(TextToMeasure, 0, fontSize, smallWidth, options);

                Assert.AreEqual(11, size.CharsFitted, "Can only fit 11 chars on smaller width with extra character space and breaking on words");
                Assert.IsTrue(size.OnWordBoudary, "Breaking on word boundary should be true");
                Assert.AreEqual(12.0, size.RequiredHeight, "Helvetica font preferences should use the font header size, rather than typographic.");
            }
        }