Ejemplo n.º 1
0
        public void TryLoadFromUrlStream()
        {
            ITypefaceInfo info;
            bool          result;

            using (var reader = new TypefaceReader())
            {
                var path = RootUrl;

                //valid path
                path = path + UrlPath;

                using (var http = new HttpClient())
                {
                    //We need a seekable stream, so download to a buffer and use that.
                    var data = http.GetByteArrayAsync(path).Result;

                    using (var stream = new MemoryStream(data))
                        result = reader.TryReadTypeface(stream, path, out info);

                    Assert.IsTrue(result, "Reported as false, to read the input from a stream");
                    Assert.IsNotNull(info, "Info was not returned");
                    Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                    //check the info
                    ValidateHelvetica.AssertInfo(info, path, 3);
                }
            }
        }
Ejemplo n.º 2
0
        public void LoadInfoWithHttp()
        {
            TypefaceReader reader;
            StreamLoader   loader;

            using (var http = new System.Net.Http.HttpClient())
            {
                using (reader = new TypefaceReader(http))
                {
                    Assert.IsNotNull(reader.Loader.Client, "The loader SHOULD have a client as it was provided");

                    var path = RootUrl;
                    path = path + UrlPath;
                    var info = reader.ReadTypeface(path);
                    ValidateHelvetica.AssertInfo(info, path, 8);

                    //check http is set
                    Assert.IsNotNull(reader.Loader.Client, "The loader should STILL have a client as it was provided");
                    Assert.IsFalse(reader.Loader.OwnsClient, "The loader should NOT own the client as it was  provided");

                    loader = reader.Loader;
                }
                //check clean up
                Assert.IsNull(reader.Loader, "The readers loader should have been set to null");
                Assert.IsNull(loader.Client, "The loaders http should have been set to null, but not disposed");

                //Simple check to make sure we are still able to use the http client
                var data = http.GetStringAsync(CheckAliveUrl).Result;
                Assert.IsNotNull(data);
                Assert.IsTrue(data.StartsWith("<Project "));
            }
        }
Ejemplo n.º 3
0
        public void GetHelveticaMetrics()
        {
            var path      = new FileInfo(Path.Combine(System.Environment.CurrentDirectory, ValidateHelvetica.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);


                ValidateHelvetica.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.53, Math.Round(size.RequiredWidth, 2), "The width of the string was not as statically caclulated");

                //checked height of a line to 12
                Assert.AreEqual(12.0, size.RequiredHeight, "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(83.84, Math.Round(size.RequiredWidth, 2), "The width of the restricted string was not as statically calculated");
                Assert.AreEqual(12.0, size.RequiredHeight, "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.17, Math.Round(size.RequiredWidth, 2), "The width of the restricted string was not as statically calculated");
                Assert.AreEqual(12.0, size.RequiredHeight, "The height of the string was not as statically calculated");

                //check 4
                //set the offset to last fitted and measure the rest
                offset = size.CharsFitted;
                size   = metrics.MeasureLine(words, offset, fontSize, available, options);
                Assert.AreEqual(words.Length - offset, size.CharsFitted, "Expected to fit all the remaining characters on the next measure (line)");
            }
        }
Ejemplo n.º 4
0
        public void LoadInfoFromFilePath()
        {
            using (var reader = new TypefaceReader())
            {
                var path = System.Environment.CurrentDirectory;
                path = Path.Combine(path, PartialFilePath);

                var info = reader.ReadTypeface(path);
                ValidateHelvetica.AssertInfo(info, path, 2);
            }
        }
Ejemplo n.º 5
0
        public void LoadInfoFromFullUrl()
        {
            var path = RootUrl;

            using (var reader = new TypefaceReader())
            {
                path = path + UrlPath;
                var info = reader.ReadTypeface(path);
                ValidateHelvetica.AssertInfo(info, path, 5);
            }
        }
Ejemplo n.º 6
0
        public void LoadInfoFromDirectoryAndPath()
        {
            var path = System.Environment.CurrentDirectory;
            var di   = new System.IO.DirectoryInfo(path);

            using (var reader = new TypefaceReader(di))
            {
                path = PartialFilePath;
                var info = reader.ReadTypeface(path);
                ValidateHelvetica.AssertInfo(info, path, 4);
            }
        }
        public void ValidGetFirstFontHelveticaPath()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

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

                var face = reader.GetFirstFont(file);
                Assert.IsNotNull(face);

                ValidateHelvetica.AssertTypeface(face);
            }
        }
        public void ValidGetFirstFontHelveticaUrl()
        {
            var path = new Uri(ValidateHelvetica.RootUrl);

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

                var face = reader.GetFirstFont(url);


                ValidateHelvetica.AssertTypeface(face);
            }
        }
Ejemplo n.º 9
0
        public void LoadInfoFromFileStream()
        {
            using (var reader = new TypefaceReader())
            {
                var path = System.Environment.CurrentDirectory;
                path = Path.Combine(path, PartialFilePath);

                using (var stream = new FileStream(path, FileMode.Open))
                {
                    var info = reader.ReadTypeface(stream, path);
                    ValidateHelvetica.AssertInfo(info, path, 1);
                }
            }
        }
        public async Task ValidGetFontHelveticaUrlAndIndex()
        {
            var path = new Uri(ValidateHelvetica.RootUrl);

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

                var face = await reader.GetFontAsync(url, 0);

                Assert.IsNotNull(face);

                ValidateHelvetica.AssertTypeface(face);
            }
        }
        public async Task ValidGetFontHelveticaPathAndIndex()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

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

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

                Assert.IsNotNull(face);


                ValidateHelvetica.AssertTypeface(face);
            }
        }
        public void ValidGetFontHelveticaUrlInfoAndIndex()
        {
            var path = new Uri(ValidateHelvetica.RootUrl);

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

                var info = reader.ReadTypeface(file);

                var face = reader.GetFont(info, 0);
                Assert.IsNotNull(face);

                ValidateHelvetica.AssertTypeface(face);
            }
        }
Ejemplo n.º 13
0
        public void ValidGetTypefacesHelveticaUrl()
        {
            var path = new Uri(ValidateHelvetica.RootUrl);

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

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

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

                ValidateHelvetica.AssertTypeface(all[0]);
            }
        }
Ejemplo n.º 14
0
        public void ValidGetTypefacesHelveticaPath()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

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

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

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

                ValidateHelvetica.AssertTypeface(all[0]);
            }
        }
        public void ValidGetFontHelveticaUrlAndReference()
        {
            var path = new Uri(ValidateHelvetica.RootUrl);

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

                var info = reader.ReadTypeface(uri);
                var fref = info.Fonts[0];

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

                ValidateHelvetica.AssertTypeface(face);
            }
        }
Ejemplo n.º 16
0
        public async Task AsyncLoadFromRelativeUrlString()
        {
            ITypefaceInfo info;

            var path = RootUrl;

            using (var reader = new TypefaceReader(new Uri(path)))
            {
                //valid path
                path = UrlPath;

                info = await reader.ReadTypefaceAsync(path);

                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info - but not the path
                ValidateHelvetica.AssertInfo(info, null, 6);
            }
        }
        public void ValidGetFontHelveticaFileInfoAndIndex()
        {
            var path = new DirectoryInfo(System.Environment.CurrentDirectory);

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

                var info = reader.ReadTypeface(file);

                //Get the font with the info and an index of 0
                var face = reader.GetFont(info, 0);

                Assert.IsNotNull(face);


                ValidateHelvetica.AssertTypeface(face);
            }
        }
Ejemplo n.º 18
0
        public async Task AsyncLoadFromAbsoluteUrl()
        {
            ITypefaceInfo info;

            using (var reader = new TypefaceReader())
            {
                var path = RootUrl;

                //valid path
                path = path + UrlPath;
                var uri = new Uri(path);

                info = await reader.ReadTypefaceAsync(uri);

                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info
                ValidateHelvetica.AssertInfo(info, path, 5);
            }
        }
Ejemplo n.º 19
0
        public async Task AsyncLoadFromRelativeFile()
        {
            ITypefaceInfo info;

            var path = System.Environment.CurrentDirectory;

            using (var reader = new TypefaceReader(new DirectoryInfo(path)))
            {
                //valid path
                path = PartialFilePath;
                var file = new FileInfo(path);

                info = await reader.ReadTypefaceAsync(file);

                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info - but not the path, as this will be changed
                ValidateHelvetica.AssertInfo(info, null, 7);
            }
        }
Ejemplo n.º 20
0
        public void TryLoadFromRelativeUrl()
        {
            ITypefaceInfo info;
            bool          result;
            var           path = RootUrl;

            using (var reader = new TypefaceReader(new Uri(path)))
            {
                //valid path
                path = UrlPath;
                var uri = new Uri(path, UriKind.Relative);

                result = reader.TryReadTypeface(uri, out info);

                Assert.IsTrue(result, "Reported as false, to read the input from a stream");
                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info - but not the path
                ValidateHelvetica.AssertInfo(info, null, 6);
            }
        }
Ejemplo n.º 21
0
        public void TryLoadFromRelativeFile()
        {
            ITypefaceInfo info;
            bool          result;
            var           path = System.Environment.CurrentDirectory;

            using (var reader = new TypefaceReader(new DirectoryInfo(path)))
            {
                //valid path
                path = PartialFilePath;
                var file = new FileInfo(path);

                result = reader.TryReadTypeface(file, out info);

                Assert.IsTrue(result, "Reported as false, to read the input from a stream");
                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info - but not the path, as this will be changed
                ValidateHelvetica.AssertInfo(info, null, 7);
            }
        }
Ejemplo n.º 22
0
        public void TryLoadFromAbsoluteUrl()
        {
            ITypefaceInfo info;
            bool          result;

            using (var reader = new TypefaceReader())
            {
                var path = RootUrl;

                //valid path
                path = path + UrlPath;
                var uri = new Uri(path);

                result = reader.TryReadTypeface(uri, out info);

                Assert.IsTrue(result, "Reported as false, to read the input from a stream");
                Assert.IsNotNull(info, "Info was not returned");
                Assert.IsTrue(string.IsNullOrEmpty(info.ErrorMessage), "An Error message was returned");
                //check the info
                ValidateHelvetica.AssertInfo(info, path, 5);
            }
        }
Ejemplo n.º 23
0
        public void LoadInfoFromPartialUrl()
        {
            var            path = RootUrl;
            TypefaceReader reader;
            StreamLoader   loader;

            using (reader = new TypefaceReader(new Uri(path)))
            {
                path = UrlPath;
                var info = reader.ReadTypeface(path);
                ValidateHelvetica.AssertInfo(info, path, 6);

                //check http is set
                Assert.IsNotNull(reader.Loader.Client, "The loader should have a client as it was not provided, but needed");
                Assert.IsTrue(reader.Loader.OwnsClient, "The loader should own the client as it was not provided");

                loader = reader.Loader;
            }
            //check clean up
            Assert.IsNull(reader.Loader, "The readers loader should have been set to null");
            Assert.IsNull(loader.Client, "The loaders http should have been disposed and set to null");
        }
Ejemplo n.º 24
0
        public void TryLoadFromFileStream()
        {
            ITypefaceInfo info;
            bool          result;

            using (var reader = new TypefaceReader())
            {
                // Success
                FileStream stream;

                var path = System.Environment.CurrentDirectory;
                path = Path.Combine(path, PartialFilePath);

                using (stream = new FileStream(path, FileMode.Open))
                {
                    result = reader.TryReadTypeface(stream, path, out info);
                }

                Assert.IsTrue(result, "Could not read the valid input from a stream");
                Assert.IsNotNull(info, "The info was not returned for the try method");
                ValidateHelvetica.AssertInfo(info, path, 1);
            }
        }