public void ConstructorTest() { ICanvas canvas = new SimpleCanvas(3, 4); Assert.Equal(3, canvas.Width); Assert.Equal(4, canvas.Height); }
public void PrintToOutputStream() { var OutputMock = new Mock <TextWriter>(); string outbuffer = ""; OutputMock.Setup(console => console.Write(It.IsAny <string>())) .Callback((string s) => outbuffer += s); OutputMock.Setup(console => console.WriteLine(It.IsAny <string>())) .Callback((string s) => outbuffer += s + Environment.NewLine); OutputMock.Setup(console => console.WriteLine()) .Callback(() => outbuffer += Environment.NewLine); var printer = new CanvasPrinter(OutputMock.Object); ICanvas canvas = new SimpleCanvas(2, 2); printer.Print(canvas); string expected = "----" + Environment.NewLine + "| |" + Environment.NewLine + "| |" + Environment.NewLine + "----" + Environment.NewLine + Environment.NewLine; Assert.Equal(expected, outbuffer); }
public void Setup(int canvasW, int canvasH) { //-------------------------------------- //TODO: review here again DrawingGL.Text.Utility.SetLoadFontDel( fontfile => { if (File.Exists("DroidSans.ttf")) { using (Stream s = new FileStream("DroidSans.ttf", FileMode.Open, FileAccess.Read)) using (var ms = new MemoryStream()) // This is a simple hack because on Xamarin.Android, a `Stream` created by `AssetManager.Open` is not seekable. { s.CopyTo(ms); return(new MemoryStream(ms.ToArray())); } } return(null); }); //-------------------------------------- simpleCanvas = new SimpleCanvas(canvasW, canvasH); var text = "Typography"; //optional .... //var directory = AndroidOS.Environment.ExternalStorageDirectory; //var fullFileName = Path.Combine(directory.ToString(), "TypographyTest.txt"); //if (File.Exists(fullFileName)) //{ // text = File.ReadAllText(fullFileName); //} //-------------------------------------------------------------------------- //we want to create a prepared visual object *** //textContext = new TypographyTextContext() //{ // FontFamily = "DroidSans.ttf", //corresponding to font file Assets/DroidSans.ttf // FontSize = 64,//size in Points // FontStretch = FontStretch.Normal, // FontStyle = FontStyle.Normal, // FontWeight = FontWeight.Normal, // Alignment = DrawingGL.Text.TextAlignment.Leading //}; //-------------------------------------------------------------------------- //create blank text run textRun = new TextRun(); //generate glyph run inside text text run TextPrinter textPrinter = simpleCanvas.TextPrinter; textPrinter.FontFilename = "DroidSans.ttf"; //corresponding to font file Assets/DroidSans.ttf textPrinter.FontSizeInPoints = 64; // simpleCanvas.TextPrinter.GenerateGlyphRuns(textRun, text.ToCharArray(), 0, text.Length); //-------------------------------------------------------------------------- }
public void ShouldCreateBucketFill() { ICanvas canvas = new SimpleCanvas(10, 10); var canvasFactory = new Mock <ICanvasFactory>(); var cmdFactory = new Mock <ICommandFactory>(); canvasFactory.Setup(canvasF => canvasF.CreateCanvas(10, 10)).Returns(canvas); cmdFactory.Setup(cmdF => cmdF.CreateBucketFill(canvas, 0, 0, 100)); var service = new DrawingServiceBase(canvasFactory.Object, cmdFactory.Object); service.CreateCanvas(10, 10); service.BucketFill(0, 0, 100); cmdFactory.Verify(cmdF => cmdF.CreateBucketFill(canvas, 0, 0, 100), Times.Once()); }
public void Setup(int canvasW, int canvasH) { //-------------------------------------- //TODO: review here again DrawingGL.Text.Utility.SetLoadFontDel( fontfile => { return(null); }); //-------------------------------------- simpleCanvas = new SimpleCanvas(canvasW, canvasH); var text = "Typography"; //optional .... //var directory = AndroidOS.Environment.ExternalStorageDirectory; //var fullFileName = Path.Combine(directory.ToString(), "TypographyTest.txt"); //if (File.Exists(fullFileName)) //{ // text = File.ReadAllText(fullFileName); //} //-------------------------------------------------------------------------- //we want to create a prepared visual object *** textContext = new TypographyTextContext() { FontFamily = "DroidSans.ttf", //corresponding to font file Assets/DroidSans.ttf FontSize = 64, //size in Points FontStretch = FontStretch.Normal, FontStyle = FontStyle.Normal, FontWeight = FontWeight.Normal, Alignment = DrawingGL.Text.TextAlignment.Leading }; //-------------------------------------------------------------------------- //create blank text run textRun = new TextRun(); //generate glyph run inside text text run textContext.GenerateGlyphRuns(textRun, text); //-------------------------------------------------------------------------- }