Exemple #1
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			TypeFacePrinter printer = new TypeFacePrinter();
			printer.DrawFromHintedCache = true;

			RectangleDouble Bounds = LocalBounds;

			double y = LocalBounds.Bottom + printer.TypeFaceStyle.EmSizeInPixels * (TOTOL_POW2 - 1) + 5;
			for (int index = lineCount; index < lineCount + TOTOL_POW2; index++)
			{
				if (y > LocalBounds.Top)
				{
					y -= printer.TypeFaceStyle.EmSizeInPixels;
					continue;
				}
				int arrayIndex = (index % TOTOL_POW2);
				if (lines[arrayIndex] != null)
				{
					printer.Text = lines[arrayIndex];
					printer.Origin = new Vector2(Bounds.Left + 2, y);
					printer.Render(graphics2D, TextColor);
				}
				y -= printer.TypeFaceStyle.EmSizeInPixels;
				if (y < -printer.TypeFaceStyle.EmSizeInPixels)
				{
					break;
				}
			}

			base.OnDraw(graphics2D);
		}
Exemple #2
0
        public TextWidget(string text, double x = 0, double y = 0, double pointSize = 12, Justification justification = Justification.Left, RGBA_Bytes textColor = new RGBA_Bytes(), bool ellipsisIfClipped = true, bool underline = false, RGBA_Bytes backgroundColor = new RGBA_Bytes())
        {
            Selectable = false;
            DoubleBuffer = DoubleBufferDefault;
            AutoExpandBoundsToText = false;
            EllipsisIfClipped = ellipsisIfClipped; 
            OriginRelativeParent = new Vector2(x, y);
            this.textColor = textColor;
            if (this.textColor.Alpha0To255 == 0)
            {
                // we assume it is the default if alpha 0.  Also there is no reason to make a text color of this as it will draw nothing.
                this.textColor = RGBA_Bytes.Black;
            }
            if (backgroundColor.Alpha0To255 != 0)
            {
                BackgroundColor = backgroundColor;
            }

            base.Text = text;
            StyledTypeFace typeFaceStyle = new StyledTypeFace(LiberationSansFont.Instance, pointSize, underline);
            printer = new TypeFacePrinter(text, typeFaceStyle, justification: justification);

            LocalBounds = printer.LocalBounds;

            MinimumSize = new Vector2(LocalBounds.Width, LocalBounds.Height);
        }
Exemple #3
0
		public override string[] WrapSingleLineOnWidth(string originalTextToWrap, double maxPixelWidth)
		{
			List<string> lines = new List<string>();

			if (maxPixelWidth > 0)
			{
				string textToWrap = originalTextToWrap;
				while (textToWrap.Length > 0)
				{
					TypeFacePrinter printer = new TypeFacePrinter(textToWrap, styledTypeFace);
					int remainingLength = textToWrap.Length;
					while (printer.GetSize().x > maxPixelWidth
						&& printer.Text.Length > 1)
					{
						remainingLength--;
						while (remainingLength > 1
							&& textToWrap.Substring(0, remainingLength).Contains(" ")
							&& textToWrap[remainingLength] != ' ')
						{
							remainingLength--;
						}

						printer.Text = textToWrap.Substring(0, remainingLength);
					}

					if (remainingLength >= 0)
					{
						lines.Add(textToWrap.Substring(0, remainingLength));
					}

					// check if we wrapped because of to long or a '\n'. If '\n' we only trim a leading space if to long.
					if (remainingLength > 1 // we have more than 2 charecters left
						&& textToWrap.Length > remainingLength // we are longer than the remaining text
						&& textToWrap[remainingLength] == ' ' // the first new character is a space
						&& textToWrap[remainingLength - 1] != '\n') // the character before the space was not a cr (wrapped because of length)
					{
						textToWrap = textToWrap.Substring(remainingLength + 1);
					}
					else
					{
						textToWrap = textToWrap.Substring(remainingLength);
					}
				}
			}
			else
			{
				lines.Add(originalTextToWrap);
			}

			return lines.ToArray();
		}
Exemple #4
0
        public override string[] WrapSingleLineOnWidth(string originalTextToWrap, double maxPixelWidth)
        {
            List <string> lines = new List <string>();

            if (maxPixelWidth > 0)
            {
                string textToWrap = originalTextToWrap;
                while (textToWrap.Length > 0)
                {
                    TypeFacePrinter printer         = new TypeFacePrinter(textToWrap, styledTypeFace);
                    int             remainingLength = textToWrap.Length;
                    while (printer.GetSize().x > maxPixelWidth &&
                           printer.Text.Length > 1)
                    {
                        remainingLength--;
                        while (remainingLength > 1 &&
                               textToWrap.Substring(0, remainingLength).Contains(" ") &&
                               textToWrap[remainingLength] != ' ')
                        {
                            remainingLength--;
                        }

                        printer.Text = textToWrap.Substring(0, remainingLength);
                    }

                    if (remainingLength >= 0)
                    {
                        lines.Add(textToWrap.Substring(0, remainingLength));
                    }

                    // check if we wrapped because of to long or a '\n'. If '\n' we only trim a leading space if to long.
                    if (remainingLength > 1 &&                  // we have more than 2 characters left
                        textToWrap.Length > remainingLength &&                         // we are longer than the remaining text
                        textToWrap[remainingLength] == ' ' &&                         // the first new character is a space
                        textToWrap[remainingLength - 1] != '\n')                            // the character before the space was not a cr (wrapped because of length)
                    {
                        textToWrap = textToWrap.Substring(remainingLength + 1);
                    }
                    else
                    {
                        textToWrap = textToWrap.Substring(remainingLength);
                    }
                }
            }
            else
            {
                lines.Add(originalTextToWrap);
            }

            return(lines.ToArray());
        }
Exemple #5
0
		private void DrawBigA(Graphics2D graphics2D)
		{
			ScanlineRasterizer m_ras = new ScanlineRasterizer();
			m_ras.SetVectorClipBox(0, 0, Width, Height);
			TypeFacePrinter bigAPrinter = new TypeFacePrinter("a", 150);
			FlattenCurves flattenedBigA = new FlattenCurves(bigAPrinter);
			VertexSourceApplyTransform scaleAndTranslate = new VertexSourceApplyTransform(flattenedBigA, Affine.NewTranslation(155, 55));
			ScanlineCachePacked8 m_sl = new ScanlineCachePacked8();
			ScanlineRenderer scanlineRenderer = new ScanlineRenderer();

#if false
            ImageProxySubpxelLcd24 clippingProxy = new ImageProxySubpxelLcd24(graphics2D.DestImage, new lcd_distribution_lut());
            VertexSourceApplyTransform scaledWide = new VertexSourceApplyTransform(scaleAndTranslate, Affine.NewScaling(3, 1));
            m_ras.add_path(scaledWide);
            scanlineRenderer.render_scanlines_aa_solid(clippingProxy, m_ras, m_sl, RGBA_Bytes.Black);
#else
			m_ras.add_path(scaleAndTranslate);
			ImageClippingProxy clippingProxy = new ImageClippingProxy(graphics2D.DestImage);
			scanlineRenderer.RenderSolid(clippingProxy, m_ras, m_sl, RGBA_Bytes.Black);
#endif
		}
		private void insertTextBackgroundWorker_DoWork(string currentText)
		{
			Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

			asynchMeshGroups.Clear();
			asynchMeshGroupTransforms.Clear();
			asynchPlatingDatas.Clear();

			TypeFacePrinter printer = new TypeFacePrinter(currentText, new StyledTypeFace(boldTypeFace, 12));
			Vector2 size = printer.GetSize(currentText);
			double centerOffset = -size.x / 2;

			double ratioPerMeshGroup = 1.0 / currentText.Length;
			double currentRatioDone = 0;
			for (int i = 0; i < currentText.Length; i++)
			{
				int newIndex = asynchMeshGroups.Count;

				TypeFacePrinter letterPrinter = new TypeFacePrinter(currentText[i].ToString(), new StyledTypeFace(boldTypeFace, 12));
				Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, 10 + (i % 2));

				if (textMesh.Faces.Count > 0)
				{
					asynchMeshGroups.Add(new MeshGroup(textMesh));

					PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

					newMeshInfo.xSpacing = printer.GetOffsetLeftOfCharacterIndex(i).x + centerOffset;
					asynchPlatingDatas.Add(newMeshInfo);
					asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());

					PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, newIndex, (double progress0To1, string processingState, out bool continueProcessing) =>
					{
						continueProcessing = true;
						int nextPercent = (int)((currentRatioDone + ratioPerMeshGroup * progress0To1) * 100);
						processingProgressControl.PercentComplete = nextPercent;
					});

					currentRatioDone += ratioPerMeshGroup;

					PlatingHelper.PlaceMeshGroupOnBed(asynchMeshGroups, asynchMeshGroupTransforms, newIndex);
				}

				processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length);
			}

			SetWordSpacing(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas);
			SetWordSize(asynchMeshGroups, asynchMeshGroupTransforms);
			SetWordHeight(asynchMeshGroups, asynchMeshGroupTransforms);

			if (createUnderline.Checked)
			{
				CreateUnderline(asynchMeshGroups, asynchMeshGroupTransforms, asynchPlatingDatas);
			}

			processingProgressControl.PercentComplete = 95;
		}
		private void AddCharacterMeshes(string currentText, TypeFacePrinter printer)
		{
			int newIndex = asyncMeshGroups.Count;
			StyledTypeFace typeFace = printer.TypeFaceStyle;

			for (int i = 0; i < currentText.Length; i++)
			{
				string letter = currentText[i].ToString();
				TypeFacePrinter letterPrinter = new TypeFacePrinter(letter, typeFace);

				if (CharacterHasMesh(letterPrinter, letter))
				{
#if true
					Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);
#else
					Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);
					// this is the code to make rounded tops
					// convert the letterPrinter to clipper polygons
					List<List<IntPoint>> insetPoly = VertexSourceToPolygon.CreatePolygons(letterPrinter);
					// inset them
					ClipperOffset clipper = new ClipperOffset();
					clipper.AddPaths(insetPoly, JoinType.jtMiter, EndType.etClosedPolygon);
					List<List<IntPoint>> solution = new List<List<IntPoint>>();
					clipper.Execute(solution, 5.0);
					// convert them back into a vertex source
					// merge both the inset and original vertex sources together
					// convert the new vertex source into a mesh (triangulate them)
					// offset the inner loop in z
					// create the polygons from the inner loop to a center point so that there is the rest of an approximation of the bubble
					// make the mesh for the bottom 
					// add the top and bottom together
					// done
#endif

					asyncMeshGroups.Add(new MeshGroup(textMesh));

					PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

					newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i);
					asyncPlatingDatas.Add(newMeshInfo);
					asyncMeshGroupTransforms.Add(Matrix4X4.Identity);

					PlatingHelper.CreateITraceableForMeshGroup(asyncPlatingDatas, asyncMeshGroups, newIndex, null);
					asyncMeshGroupTransforms[newIndex] *= Matrix4X4.CreateTranslation(new Vector3(0, 0, unscaledLetterHeight / 2));

					newIndex++;
				}

				processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length);
			}
		}
Exemple #8
0
		public override void OnDraw(Graphics2D graphics2D)
		{
			graphics2D.PushTransform();

			int numLines = Text.Split('\n').Length - 1;
			if (Text.Contains("\r"))
			{
				throw new Exception("These should have be converted to \n.");
			}

			double yOffsetForText = Printer.TypeFaceStyle.EmSizeInPixels * numLines;
			double xOffsetForText = 0;
			switch (printer.Justification)
			{
				case Justification.Left:
					break;

				case Justification.Center:
					xOffsetForText = (Width - Printer.LocalBounds.Width) / 2;
					break;

				case Justification.Right:
					xOffsetForText = Width - Printer.LocalBounds.Width;
					break;

				default:
					throw new NotImplementedException();
			}
			graphics2D.SetTransform(graphics2D.GetTransform() * Affine.NewTranslation(xOffsetForText, yOffsetForText));

			RGBA_Bytes currentColor = this.textColor;

			if (EllipsisIfClipped && Printer.LocalBounds.Width > LocalBounds.Width) // only do this if it's static text
			{
				TypeFacePrinter shortTextPrinter = Printer;
				shortTextPrinter.DrawFromHintedCache = Printer.DrawFromHintedCache;
				while (shortTextPrinter.LocalBounds.Width > LocalBounds.Width && shortTextPrinter.Text.Length > 4)
				{
					shortTextPrinter = new TypeFacePrinter(shortTextPrinter.Text.Substring(0, shortTextPrinter.Text.Length - 4).TrimEnd(spaceTrim) + "...", Printer);
				}
				shortTextPrinter.Render(graphics2D, currentColor);
			}
			else
			{
				// it all fits or it's editable (if editable it will need to be offset/scrolled sometimes).
				Printer.Render(graphics2D, currentColor);
			}

			if (debugIt)
			{
				graphics2D.Line(-5, 0, 5, 0, RGBA_Bytes.Blue);
				graphics2D.Line(0, -5, 0, 5, RGBA_Bytes.Blue);
			}

			graphics2D.PopTransform();

			if (debugIt)
			{
				graphics2D.Line(-5, 0, 5, 0, RGBA_Bytes.Red);
				graphics2D.Line(0, -5, 0, 5, RGBA_Bytes.Red);
			}

			base.OnDraw(graphics2D);
		}
Exemple #9
0
 public static SizeF MeasureStringStatic(string text, Font font, PointF origin, StringFormat format)
 {
     var tfp = new TypeFacePrinter(text, font.SizeInPoints);
     var bounds = tfp.LocalBounds;
     return new SizeF((float)bounds.Width,(float)bounds.Height);
 }
Exemple #10
0
		public void DrawString(string Text, double x, double y, double pointSize = 12,
			Justification justification = Justification.Left, Baseline baseline = Baseline.Text,
			RGBA_Bytes color = new RGBA_Bytes(), bool drawFromHintedCach = false, RGBA_Bytes backgroundColor = new RGBA_Bytes())
		{
			TypeFacePrinter stringPrinter = new TypeFacePrinter(Text, pointSize, new Vector2(x, y), justification, baseline);
			if (color.Alpha0To255 == 0)
			{
				color = RGBA_Bytes.Black;
			}

			if (backgroundColor.Alpha0To255 != 0)
			{
				FillRectangle(stringPrinter.LocalBounds, backgroundColor);
			}

			stringPrinter.DrawFromHintedCache = drawFromHintedCach;
			stringPrinter.Render(this, color);
		}
        public void SavingFunction()
        {
            currentlySaving = true;
            countThatHaveBeenSaved = 0;
            // first create images for all the parts
            foreach (FileNameAndPresentationName stlFileNames in stlFilesToPrint)
            {
                Mesh loadedMesh = StlProcessing.Load(stlFileNames.fileName);
                if (loadedMesh != null)
                {
                    AxisAlignedBoundingBox aabb = loadedMesh.GetAxisAlignedBoundingBox();
                    RectangleDouble bounds2D = new RectangleDouble(aabb.minXYZ.x, aabb.minXYZ.y, aabb.maxXYZ.x, aabb.maxXYZ.y);
                    double widthInMM = bounds2D.Width + PartMarginMM * 2;
                    double textSpaceMM = 5;
                    double heightMM = textSpaceMM + bounds2D.Height + PartMarginMM * 2;

                    TypeFacePrinter typeFacePrinter = new TypeFacePrinter(stlFileNames.presentationName, 28, Vector2.Zero, Justification.Center, Baseline.BoundsCenter);
                    double sizeOfNameX = typeFacePrinter.GetSize().x + PartMarginPixels * 2;
                    Vector2 sizeOfRender = new Vector2(widthInMM * PixelPerMM, heightMM * PixelPerMM);

                    ImageBuffer imageOfPart = new ImageBuffer((int)(Math.Max(sizeOfNameX, sizeOfRender.x)), (int)(sizeOfRender.y), 32, new BlenderBGRA());
                    typeFacePrinter.Origin = new Vector2(imageOfPart.Width / 2, (textSpaceMM / 2) * PixelPerMM);

                    Graphics2D partGraphics2D = imageOfPart.NewGraphics2D();

                    RectangleDouble rectBounds = new RectangleDouble(0, 0, imageOfPart.Width, imageOfPart.Height);
                    double strokeWidth = .5 * PixelPerMM;
                    rectBounds.Inflate(-strokeWidth / 2);
                    RoundedRect rect = new RoundedRect(rectBounds, PartMarginMM * PixelPerMM);
                    partGraphics2D.Render(rect, RGBA_Bytes.LightGray);
                    Stroke rectOutline = new Stroke(rect, strokeWidth);
                    partGraphics2D.Render(rectOutline, RGBA_Bytes.DarkGray);

                    PolygonMesh.Rendering.OrthographicZProjection.DrawTo(partGraphics2D, loadedMesh, new Vector2(-bounds2D.Left + PartMarginMM, -bounds2D.Bottom + textSpaceMM + PartMarginMM), PixelPerMM, RGBA_Bytes.Black);
                    partGraphics2D.Render(typeFacePrinter, RGBA_Bytes.Black);

                    partImagesToPrint.Add(new PartImage(imageOfPart));
                }
                countThatHaveBeenSaved++;
                if (UpdateRemainingItems != null)
                {
                    UpdateRemainingItems(this, new StringEventArgs(Path.GetFileName(stlFileNames.presentationName)));
                }
            }

            partImagesToPrint.Sort(BiggestToLittlestImages);

            PdfDocument document = new PdfDocument();
            document.Info.Title = "MatterHackers Parts Sheet";
            document.Info.Author = "MatterHackers Inc.";
            document.Info.Subject = "This is a list of the parts that are in a queue from MatterControl.";
            document.Info.Keywords = "MatterControl, STL, 3D Printing";

            int nextPartToPrintIndex = 0;
            int plateNumber = 1;
            bool done = false;
            while (!done && nextPartToPrintIndex < partImagesToPrint.Count)
            {
                PdfPage pdfPage = document.AddPage();
                CreateOnePage(plateNumber++, ref nextPartToPrintIndex, pdfPage);
            }
			try
			{
                // save the final document
            	document.Save(pathAndFileToSaveTo);
                // Now try and open the document. This will lanch whatever PDF viewer is on the system and ask it 
                // to show the file (at least on Windows).
            	Process.Start(pathAndFileToSaveTo);
			}
			catch (Exception)
            {
			}

            OnDoneSaving();
            currentlySaving = false;
        }
Exemple #12
0
        public void DrawString(string text, Font font, Brush brush, float x, float y)
        {
            // TODO: handle different brushes
            // TODO: emulate GDI "bordering" of text?
            SolidBrush colorBrush = brush as SolidBrush;
            var s1 = new TypeFacePrinter (text, font.SizeInPoints, new MatterHackers.VectorMath.Vector2 (0, 0), Justification.Left, Baseline.BoundsTop);
            var s2 = new VertexSourceApplyTransform (s1, Affine.NewScaling (1, -1));
            if (x != 0.0f || y != 0.0f) {
                s2 = new VertexSourceApplyTransform (s2, Affine.NewTranslation (x, y));
            }

            _InternalRender(s2, new RGBA_Bytes((uint)colorBrush.Color.ToArgb()) );
        }
Exemple #13
0
        public void ShowDebugInfo(Graphics2D graphics2D)
        {
            StyledTypeFace  typeFaceNameStyle = new StyledTypeFace(this, 30);
            TypeFacePrinter fontNamePrinter   = new TypeFacePrinter(this.fontFamily + " - 30 point", typeFaceNameStyle);

            RectangleDouble bounds           = typeFaceNameStyle.BoundingBoxInPixels;
            double          origX            = 10 - bounds.Left;
            double          x                = origX;
            double          y                = 10 - typeFaceNameStyle.DescentInPixels;
            int             width            = 50;
            Color           boundingBoxColor = new Color(0, 0, 0);
            Color           originColor      = new Color(0, 0, 0);
            Color           ascentColor      = new Color(255, 0, 0);
            Color           descentColor     = new Color(255, 0, 0);
            Color           xHeightColor     = new Color(12, 25, 200);
            Color           capHeightColor   = new Color(12, 25, 200);
            Color           underlineColor   = new Color(0, 150, 55);

            // the origin
            graphics2D.Line(x, y, x + width, y, originColor);

            graphics2D.Rectangle(x + bounds.Left, y + bounds.Bottom, x + bounds.Right, y + bounds.Top, boundingBoxColor);

            x += typeFaceNameStyle.BoundingBoxInPixels.Width * 1.5;

            width = width * 3;

            double temp = typeFaceNameStyle.AscentInPixels;

            graphics2D.Line(x, y + temp, x + width, y + temp, ascentColor);

            temp = typeFaceNameStyle.DescentInPixels;
            graphics2D.Line(x, y + temp, x + width, y + temp, descentColor);

            temp = typeFaceNameStyle.XHeightInPixels;
            graphics2D.Line(x, y + temp, x + width, y + temp, xHeightColor);

            temp = typeFaceNameStyle.CapHeightInPixels;
            graphics2D.Line(x, y + temp, x + width, y + temp, capHeightColor);

            temp = typeFaceNameStyle.UnderlinePositionInPixels;
            graphics2D.Line(x, y + temp, x + width, y + temp, underlineColor);

            Affine textTransform;

            textTransform  = Affine.NewIdentity();
            textTransform *= Affine.NewTranslation(10, origX);

            VertexSourceApplyTransform transformedText = new VertexSourceApplyTransform(textTransform);

            fontNamePrinter.Render(graphics2D, Color.Black, transformedText);

            graphics2D.Render(transformedText, Color.Black);

            // render the legend
            StyledTypeFace legendFont = new StyledTypeFace(this, 12);
            Vector2        textPos    = new Vector2(x + width / 2, y + typeFaceNameStyle.EmSizeInPixels * 1.5);

            graphics2D.Render(new TypeFacePrinter("Descent"), textPos, descentColor); textPos.Y     += legendFont.EmSizeInPixels;
            graphics2D.Render(new TypeFacePrinter("Underline"), textPos, underlineColor); textPos.Y += legendFont.EmSizeInPixels;
            graphics2D.Render(new TypeFacePrinter("X Height"), textPos, xHeightColor); textPos.Y    += legendFont.EmSizeInPixels;
            graphics2D.Render(new TypeFacePrinter("CapHeight"), textPos, capHeightColor); textPos.Y += legendFont.EmSizeInPixels;
            graphics2D.Render(new TypeFacePrinter("Ascent"), textPos, ascentColor); textPos.Y       += legendFont.EmSizeInPixels;
            graphics2D.Render(new TypeFacePrinter("Origin"), textPos, originColor); textPos.Y       += legendFont.EmSizeInPixels;
            graphics2D.Render(new TypeFacePrinter("Bounding Box"), textPos, boundingBoxColor);
        }
		private void AddCharacterMeshes(string currentText, TypeFacePrinter printer)
		{
			int newIndex = asynchMeshGroups.Count;
			StyledTypeFace typeFace = printer.TypeFaceStyle;

			for (int i = 0; i < currentText.Length; i++)
			{
				string letter = currentText[i].ToString();
				TypeFacePrinter letterPrinter = new TypeFacePrinter(letter, typeFace);

				if (CharacterHasMesh(letterPrinter, letter))
				{
					Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, unscaledLetterHeight / 2);

					asynchMeshGroups.Add(new MeshGroup(textMesh));

					PlatingMeshGroupData newMeshInfo = new PlatingMeshGroupData();

					newMeshInfo.spacing = printer.GetOffsetLeftOfCharacterIndex(i);
					asynchPlatingDatas.Add(newMeshInfo);
					asynchMeshGroupTransforms.Add(ScaleRotateTranslate.Identity());

					PlatingHelper.CreateITraceableForMeshGroup(asynchPlatingDatas, asynchMeshGroups, newIndex, null);
					ScaleRotateTranslate moved = asynchMeshGroupTransforms[newIndex];
					moved.translation *= Matrix4X4.CreateTranslation(new Vector3(0, 0, unscaledLetterHeight / 2));
					asynchMeshGroupTransforms[newIndex] = moved;

					newIndex++;
				}

				processingProgressControl.PercentComplete = ((i + 1) * 95 / currentText.Length);
			}
		}
		private void InsertTextDoWork(string brailleText, string wordText)
		{
			Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;

			asyncMeshGroups.Clear();
			asyncMeshGroupTransforms.Clear();
			asyncPlatingDatas.Clear();

			TypeFacePrinter brailPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(brailTypeFace, 12));

			int firstNewCharacter = 0;
			StyledTypeFace boldStyled = new StyledTypeFace(monoSpacedTypeFace, 12);

			if (includeText.Checked)
			{
				TypeFacePrinter normalPrinter = new TypeFacePrinter(wordText, boldStyled);
				Vector2 normalSize = normalPrinter.GetSize();
				AddCharacterMeshes(wordText, normalPrinter);
				
				firstNewCharacter = asyncPlatingDatas.Count;
			}

			AddCharacterMeshes(brailleText, brailPrinter);
			Vector2 brailSize = brailPrinter.GetSize();

			for (int i = 0; i < firstNewCharacter; i++)
			{
				asyncPlatingDatas[i].spacing = asyncPlatingDatas[i].spacing + new Vector2(0, boldStyled.CapHeightInPixels * 1.5);
			}

			CreateBase(asyncMeshGroups, asyncMeshGroupTransforms, asyncPlatingDatas);

			SetWordPositions(asyncMeshGroups, asyncMeshGroupTransforms, asyncPlatingDatas);
			SetWordSize(asyncMeshGroups, asyncMeshGroupTransforms);
			SetWordHeight(asyncMeshGroups, asyncMeshGroupTransforms);

			CenterTextOnScreen(asyncMeshGroups, asyncMeshGroupTransforms);

			processingProgressControl.PercentComplete = 95;
		}
        void insertTextBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture;
            BackgroundWorker backgroundWorker = (BackgroundWorker)sender;

            asynchMeshesList.Clear();
            asynchMeshTransforms.Clear();
            asynchPlatingDataList.Clear();

            string currentText = (string)e.Argument;
            TypeFacePrinter printer = new TypeFacePrinter(currentText, new StyledTypeFace(boldTypeFace, 12));
            Vector2 size = printer.GetSize(currentText);
            double centerOffset = -size.x / 2;

            for (int i = 0; i < currentText.Length; i++)
            {
                int newIndex = asynchMeshesList.Count;

                TypeFacePrinter letterPrinter = new TypeFacePrinter(currentText[i].ToString(), new StyledTypeFace(boldTypeFace, 12));
                Mesh textMesh = VertexSourceToMesh.Extrude(letterPrinter, 10 + (i%2));

                if (textMesh.Faces.Count > 0)
                {
                    asynchMeshesList.Add(textMesh);

                    PlatingMeshData newMeshInfo = new PlatingMeshData();

                    newMeshInfo.xSpacing = printer.GetOffsetLeftOfCharacterIndex(i).x + centerOffset;
                    asynchPlatingDataList.Add(newMeshInfo);
                    asynchMeshTransforms.Add(ScaleRotateTranslate.Identity());

                    PlatingHelper.CreateITraceableForMesh(asynchPlatingDataList, asynchMeshesList, newIndex);

                    PlatingHelper.PlaceMeshOnBed(asynchMeshesList, asynchMeshTransforms, newIndex, false);
                }

                backgroundWorker.ReportProgress((i + 1) * 95 / currentText.Length);
            }


            SetWordSpacing(asynchMeshesList, asynchMeshTransforms, asynchPlatingDataList);
            SetWordSize(asynchMeshesList, asynchMeshTransforms);
            SetWordHeight(asynchMeshesList, asynchMeshTransforms);

            if (createUnderline.Checked)
            {
                CreateUnderline(asynchMeshesList, asynchMeshTransforms, asynchPlatingDataList);
            }

            backgroundWorker.ReportProgress(95);
        }
        public override List <string> WrapSingleLineOnWidth(string originalTextToWrap, double maxPixelWidth)
        {
            List <string> lines = new List <string>();

            if (maxPixelWidth > 0 &&
                originalTextToWrap.Length > 0)
            {
                string          textToWrap = originalTextToWrap;
                TypeFacePrinter printer    = new TypeFacePrinter(textToWrap, styledTypeFace);
                while (textToWrap.Length > 0)
                {
                    printer.Text = textToWrap;
                    int countBeforeWrap;

                    double currentLength = 0;
                    for (countBeforeWrap = 0; countBeforeWrap < printer.Text.Length; countBeforeWrap++)
                    {
                        if (currentLength > maxPixelWidth)
                        {
                            break;
                        }
                        currentLength += printer.TypeFaceStyle.GetAdvanceForCharacter(textToWrap, countBeforeWrap);
                    }

                    while (printer.GetOffsetLeftOfCharacterIndex(countBeforeWrap).X > maxPixelWidth &&
                           countBeforeWrap > 1)
                    {
                        // now trim back to the last break
                        countBeforeWrap--;
                        while (countBeforeWrap > 1 &&
                               HasSpaceBeforeIndex(textToWrap, countBeforeWrap) &&
                               textToWrap[countBeforeWrap] != ' ')
                        {
                            countBeforeWrap--;
                        }
                    }

                    if (countBeforeWrap >= 0)
                    {
                        lines.Add(textToWrap.Substring(0, countBeforeWrap));
                    }

                    // check if we wrapped because of to long or a '\n'. If '\n' we only trim a leading space if to long.
                    if (countBeforeWrap > 1 &&                  // we have more than 2 characters left
                        textToWrap.Length > countBeforeWrap &&                         // we are longer than the remaining text
                        textToWrap[countBeforeWrap] == ' ' &&                         // the first new character is a space
                        textToWrap[countBeforeWrap - 1] != '\n')                            // the character before the space was not a cr (wrapped because of length)
                    {
                        textToWrap = textToWrap.Substring(countBeforeWrap + 1);
                    }
                    else
                    {
                        textToWrap = textToWrap.Substring(countBeforeWrap);
                    }
                }
            }
            else
            {
                lines.Add(originalTextToWrap);
            }

            return(lines);
        }
		public void TextWidgetVisibleTest()
		{
			{
				GuiWidget rectangleWidget = new GuiWidget(100, 50);
				TextWidget itemToAdd = new TextWidget("test Item", 10, 10);
				rectangleWidget.AddChild(itemToAdd);
				rectangleWidget.DoubleBuffer = true;
				rectangleWidget.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
				rectangleWidget.OnDraw(rectangleWidget.BackBuffer.NewGraphics2D());

				ImageBuffer textOnly = new ImageBuffer(75, 20, 32, new BlenderBGRA());
				textOnly.NewGraphics2D().Clear(RGBA_Bytes.White);

				textOnly.NewGraphics2D().DrawString("test Item", 1, 1);

				if (saveImagesForDebug)
				{
					ImageTgaIO.Save(rectangleWidget.BackBuffer, "-rectangleWidget.tga");
					//ImageTgaIO.Save(itemToAdd.Children[0].BackBuffer, "-internalTextWidget.tga");
					ImageTgaIO.Save(textOnly, "-textOnly.tga");
				}

				Assert.IsTrue(rectangleWidget.BackBuffer.FindLeastSquaresMatch(textOnly, 1), "TextWidgets need to be drawing.");
				rectangleWidget.Close();
			}

			{
				GuiWidget rectangleWidget = new GuiWidget(100, 50);
				TextEditWidget itemToAdd = new TextEditWidget("test Item", 10, 10);
				rectangleWidget.AddChild(itemToAdd);
				rectangleWidget.DoubleBuffer = true;
				rectangleWidget.BackBuffer.NewGraphics2D().Clear(RGBA_Bytes.White);
				rectangleWidget.OnDraw(rectangleWidget.BackBuffer.NewGraphics2D());

				ImageBuffer textOnly = new ImageBuffer(75, 20, 32, new BlenderBGRA());
				textOnly.NewGraphics2D().Clear(RGBA_Bytes.White);

				TypeFacePrinter stringPrinter = new TypeFacePrinter("test Item", 12);
				IVertexSource offsetText = new VertexSourceApplyTransform(stringPrinter, Affine.NewTranslation(1, -stringPrinter.LocalBounds.Bottom));
				textOnly.NewGraphics2D().Render(offsetText, RGBA_Bytes.Black);

				if (saveImagesForDebug)
				{
					ImageTgaIO.Save(rectangleWidget.BackBuffer, "-rectangleWidget.tga");
					//ImageTgaIO.Save(itemToAdd.Children[0].BackBuffer, "-internalTextWidget.tga");
					ImageTgaIO.Save(textOnly, "-textOnly.tga");
				}

				Assert.IsTrue(rectangleWidget.BackBuffer.FindLeastSquaresMatch(textOnly, 1), "TextWidgets need to be drawing.");
				rectangleWidget.Close();
			}
		}
Exemple #19
0
		public void ShowDebugInfo(Graphics2D graphics2D)
		{
			StyledTypeFace typeFaceNameStyle = new StyledTypeFace(this, 30);
			TypeFacePrinter fontNamePrinter = new TypeFacePrinter(this.fontFamily + " - 30 point", typeFaceNameStyle);

			RectangleDouble bounds = typeFaceNameStyle.BoundingBoxInPixels;
			double origX = 10 - bounds.Left;
			double x = origX;
			double y = 10 - typeFaceNameStyle.DescentInPixels;
			int width = 50;
			RGBA_Bytes boundingBoxColor = new RGBA_Bytes(0, 0, 0);
			RGBA_Bytes originColor = new RGBA_Bytes(0, 0, 0);
			RGBA_Bytes ascentColor = new RGBA_Bytes(255, 0, 0);
			RGBA_Bytes descentColor = new RGBA_Bytes(255, 0, 0);
			RGBA_Bytes xHeightColor = new RGBA_Bytes(12, 25, 200);
			RGBA_Bytes capHeightColor = new RGBA_Bytes(12, 25, 200);
			RGBA_Bytes underlineColor = new RGBA_Bytes(0, 150, 55);

			// the origin
			graphics2D.Line(x, y, x + width, y, originColor);

			graphics2D.Rectangle(x + bounds.Left, y + bounds.Bottom, x + bounds.Right, y + bounds.Top, boundingBoxColor);

			x += typeFaceNameStyle.BoundingBoxInPixels.Width * 1.5;

			width = width * 3;

			double temp = typeFaceNameStyle.AscentInPixels;
			graphics2D.Line(x, y + temp, x + width, y + temp, ascentColor);

			temp = typeFaceNameStyle.DescentInPixels;
			graphics2D.Line(x, y + temp, x + width, y + temp, descentColor);

			temp = typeFaceNameStyle.XHeightInPixels;
			graphics2D.Line(x, y + temp, x + width, y + temp, xHeightColor);

			temp = typeFaceNameStyle.CapHeightInPixels;
			graphics2D.Line(x, y + temp, x + width, y + temp, capHeightColor);

			temp = typeFaceNameStyle.UnderlinePositionInPixels;
			graphics2D.Line(x, y + temp, x + width, y + temp, underlineColor);

			Affine textTransform;
			textTransform = Affine.NewIdentity();
			textTransform *= Affine.NewTranslation(10, origX);

			VertexSourceApplyTransform transformedText = new VertexSourceApplyTransform(textTransform);
			fontNamePrinter.Render(graphics2D, RGBA_Bytes.Black, transformedText);

			graphics2D.Render(transformedText, RGBA_Bytes.Black);

			// render the legend
			StyledTypeFace legendFont = new StyledTypeFace(this, 12);
			Vector2 textPos = new Vector2(x + width / 2, y + typeFaceNameStyle.EmSizeInPixels * 1.5);
			graphics2D.Render(new TypeFacePrinter("Descent"), textPos, descentColor); textPos.y += legendFont.EmSizeInPixels;
			graphics2D.Render(new TypeFacePrinter("Underline"), textPos, underlineColor); textPos.y += legendFont.EmSizeInPixels;
			graphics2D.Render(new TypeFacePrinter("X Height"), textPos, xHeightColor); textPos.y += legendFont.EmSizeInPixels;
			graphics2D.Render(new TypeFacePrinter("CapHeight"), textPos, capHeightColor); textPos.y += legendFont.EmSizeInPixels;
			graphics2D.Render(new TypeFacePrinter("Ascent"), textPos, ascentColor); textPos.y += legendFont.EmSizeInPixels;
			graphics2D.Render(new TypeFacePrinter("Origin"), textPos, originColor); textPos.y += legendFont.EmSizeInPixels;
			graphics2D.Render(new TypeFacePrinter("Bounding Box"), textPos, boundingBoxColor);
		}
		private bool CharacterHasMesh(TypeFacePrinter letterPrinter, string letter)
		{
			return letterPrinter.LocalBounds.Width > 0
				&& letter != " "
				&& letter != "\n";
		}
		public TextScrollWidget(List<string> sourceLines)
		{
			string pathToFont = StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationMono.svg"));
			printer = new TypeFacePrinter("", new StyledTypeFace(TypeFace.LoadFrom(pathToFont), 12));
			printer.DrawFromHintedCache = true;
			this.allSourceLines = sourceLines;
			this.visibleLines = sourceLines;
			PrinterOutputCache.Instance.HasChanged.RegisterEvent(RecievedNewLine, ref unregisterEvents);
		}
		public void DrawString()
		{
			ImageBuffer testImage = new ImageBuffer(100, 100, 32, new BlenderBGRA());
			testImage.NewGraphics2D().DrawString("Test", 30, 50, color: RGBA_Bytes.Magenta, justification: Justification.Center);
			testImage.NewGraphics2D().DrawString("Test", 70, 50, color: RGBA_Bytes.Cyan, justification: Justification.Center);
			testImage.NewGraphics2D().DrawString("Test", 50, 30.3, color: RGBA_Bytes.Indigo, justification: Justification.Center);
			testImage.NewGraphics2D().DrawString("Test", 50, 70.3, color: RGBA_Bytes.Orange, justification: Justification.Center);
			testImage.NewGraphics2D().DrawString("Test", 50, 50, color: RGBA_Bytes.Yellow, justification: Justification.Center);

			CheckTestAgainstControl(testImage, "DrawString");

			TypeFacePrinter stringPrinterA = new TypeFacePrinter("A");
			stringPrinterA.TypeFaceStyle.FlatenCurves = false;
			CheckTestAgainstControl(stringPrinterA, "ShapeStringANotFlattened");
			stringPrinterA.TypeFaceStyle.FlatenCurves = true;
			CheckTestAgainstControl(stringPrinterA, "ShapeStringAFlattened");

			TypeFacePrinter stringPrintere = new TypeFacePrinter("e");
			stringPrintere.TypeFaceStyle.FlatenCurves = false;
			CheckTestAgainstControl(stringPrintere, "ShapeStringeNotFlattened");
			stringPrintere.TypeFaceStyle.FlatenCurves = true;
			CheckTestAgainstControl(stringPrintere, "ShapeStringeFlattened");

			TypeFacePrinter stringPrinterAe = new TypeFacePrinter("Ae");
			stringPrinterAe.TypeFaceStyle.FlatenCurves = false;
			CheckTestAgainstControl(stringPrinterAe, "ShapeStringAeNotFlattened");
			stringPrinterAe.TypeFaceStyle.FlatenCurves = true;
			CheckTestAgainstControl(stringPrinterAe, "ShapeStringAeFlattened");

			TypeFacePrinter stringPrinterTest = new TypeFacePrinter("Test");
			stringPrinterTest.TypeFaceStyle.FlatenCurves = false;
			CheckTestAgainstControl(stringPrinterTest, "ShapeStringTestNotFlattened");
			stringPrinterTest.TypeFaceStyle.FlatenCurves = true;
			CheckTestAgainstControl(stringPrinterTest, "ShapeStringTestFlattened");
		}
Exemple #23
0
 public TypeFacePrinter(String text, TypeFacePrinter copyPropertiesFrom)
     : this(text, copyPropertiesFrom.TypeFaceStyle, copyPropertiesFrom.Origin, copyPropertiesFrom.Justification, copyPropertiesFrom.Baseline)
 {
 }
		public TypeFacePrinter(String text, TypeFacePrinter copyPropertiesFrom)
			: this(text, copyPropertiesFrom.TypeFaceStyle, copyPropertiesFrom.Origin, copyPropertiesFrom.Justification, copyPropertiesFrom.Baseline)
		{
		}
		public TextScrollWidget(List<string> sourceLines)
		{
			printer = new TypeFacePrinter("", new StyledTypeFace(ApplicationController.MonoSpacedTypeFace, 12));
			printer.DrawFromHintedCache = true;
			this.allSourceLines = sourceLines;
			this.visibleLines = sourceLines;
			PrinterOutputCache.Instance.HasChanged.RegisterEvent(RecievedNewLine, ref unregisterEvents);
		}
Exemple #26
0
        public static CCSprite CreateText(string text, CCColor4B fill, CCColor4B stroke, TypeFace font, double emSizeInPoints, bool underline = false, bool flatenCurves = true, double strokeThickness = 1)
        {
            TypeFacePrinter printer = new TypeFacePrinter(text, new StyledTypeFace(font, emSizeInPoints, underline, flatenCurves));
            double width = printer.LocalBounds.Width;
            double height = printer.LocalBounds.Height;

            RectangleDouble rect = new RectangleDouble();
            bounding_rect.bounding_rect_single(printer, 0, ref rect);
            VertexSourceApplyTransform path = new VertexSourceApplyTransform(printer, Affine.NewTranslation(-rect.Left, -rect.Bottom));

            ImageBuffer buffer = new ImageBuffer((int)width, (int)height, 32, new BlenderRGBA());
            Graphics2D g = buffer.NewGraphics2D();

            if (fill.A > 0) g.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A));
            if (stroke.A > 0) g.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));

            Texture2D xnaTexture = XnaTexture((int)width, (int)height);
            xnaTexture.SetData<byte>(buffer.GetBuffer());
            CCTexture2D ccTexture = new CCTexture2D();
            ccTexture.InitWithTexture(xnaTexture);
            return new CCSprite(ccTexture);
        }
        void CreateOnePage(int plateNumber, ref int nextPartToPrintIndex, PdfPage pdfPage)
        {
            ImageBuffer plateInventoryImage = new ImageBuffer((int)(300 * 8.5), 300 * 11, 32, new BlenderBGRA());
            Graphics2D plateGraphics = plateInventoryImage.NewGraphics2D();
            double currentlyPrintingHeightPixels = PrintTopOfPage(plateInventoryImage, plateGraphics);

            Vector2 offset = new Vector2(PageMarginPixels.Left, currentlyPrintingHeightPixels);
            double tallestHeight = 0;
            List<PartImage> partsOnLine = new List<PartImage>();
            while (nextPartToPrintIndex < partImagesToPrint.Count)
            {
                ImageBuffer image = partImagesToPrint[nextPartToPrintIndex].image;
                tallestHeight = Math.Max(tallestHeight, image.Height);

                if (partsOnLine.Count > 0 && offset.x + image.Width > plateInventoryImage.Width - PageMarginPixels.Right)
                {
                    if (partsOnLine.Count == 1)
                    {
                        plateGraphics.Render(partsOnLine[0].image, plateInventoryImage.Width / 2 - partsOnLine[0].image.Width / 2, offset.y - tallestHeight);
                    }
                    else
                    {
                        foreach (PartImage partToDraw in partsOnLine)
                        {
                            plateGraphics.Render(partToDraw.image, partToDraw.xOffset, offset.y - tallestHeight);
                        }
                    }

                    offset.x = PageMarginPixels.Left;
                    offset.y -= (tallestHeight + PartPaddingPixels * 2);
                    tallestHeight = 0;
                    partsOnLine.Clear();
                    if (offset.y - image.Height < PageMarginPixels.Bottom)
                    {
                        break;
                    }
                }
                else
                {
                    partImagesToPrint[nextPartToPrintIndex].xOffset = offset.x;
                    partsOnLine.Add(partImagesToPrint[nextPartToPrintIndex]);
                    //plateGraphics.Render(image, offset.x, offset.y - image.Height);
                    offset.x += image.Width + PartPaddingPixels * 2;
                    nextPartToPrintIndex++;
                }
            }

            // print the last line of parts
            foreach (PartImage partToDraw in partsOnLine)
            {
                plateGraphics.Render(partToDraw.image, partToDraw.xOffset, offset.y - tallestHeight);
            }

            TypeFacePrinter printer = new TypeFacePrinter(string.Format("{0}", Path.GetFileNameWithoutExtension(pathAndFileToSaveTo)), 32, justification: Justification.Center);
            printer.Origin = new Vector2(plateGraphics.DestImage.Width/2, 110);
            plateGraphics.Render(printer, RGBA_Bytes.Black);

            printer = new TypeFacePrinter(string.Format("Page {0}", plateNumber), 28, justification: Justification.Center);
            printer.Origin = new Vector2(plateGraphics.DestImage.Width / 2, 60);
            plateGraphics.Render(printer, RGBA_Bytes.Black);

            string applicationUserDataPath = ApplicationDataStorage.Instance.ApplicationUserDataPath;
            string folderToSavePrintsTo = Path.Combine(applicationUserDataPath, "data", "temp", "plateImages");
            string jpegFileName = Path.Combine(folderToSavePrintsTo, plateNumber.ToString() + ".jpeg");

            if (!Directory.Exists(folderToSavePrintsTo))
            {
                Directory.CreateDirectory(folderToSavePrintsTo);
            }
            ImageIO.SaveImageData(jpegFileName, plateInventoryImage);

            XGraphics gfx = XGraphics.FromPdfPage(pdfPage);
            XImage jpegImage = XImage.FromFile(jpegFileName);
            //double width = jpegImage.PixelWidth * 72 / jpegImage.HorizontalResolution;
            //double height = jpegImage.PixelHeight * 72 / jpegImage. .HorizontalResolution;

            gfx.DrawImage(jpegImage, 0, 0, pdfPage.Width, pdfPage.Height);
        }
Exemple #28
0
        public UIGraphic AddText(double x, double y, string text, CCColor4B fill, CCColor4B stroke, TypeFace font, double emSizeInPoints, bool underline = false, bool flatenCurves = true, double strokeThickness = 1)
        {
            TypeFacePrinter printer;
            if (font != null)
                printer = new TypeFacePrinter(text, new StyledTypeFace(font, emSizeInPoints, underline, flatenCurves));
            else
                printer = new TypeFacePrinter(text, emSizeInPoints);

            RectangleDouble rect = new RectangleDouble();
            bounding_rect.bounding_rect_single(printer, 0, ref rect);
            VertexSourceApplyTransform path = path = new VertexSourceApplyTransform(printer, Affine.NewTranslation(x - rect.Left, y - rect.Bottom));

            if (fill.A > 0) this.graphics2D.Render(path, new RGBA_Bytes(fill.R, fill.G, fill.B, fill.A));
            if (stroke.A > 0) this.graphics2D.Render(new Stroke(path, strokeThickness), new RGBA_Bytes(stroke.R, stroke.G, stroke.B, stroke.A));
            return this;
        }
		public static void Main(string[] args)
		{
			// first we will show how to use the simple drawing functions in graphics 2D
			{
				ImageBuffer simpleImage = new ImageBuffer(640, 480, 32, new BlenderBGRA());
				Graphics2D simpleImageGraphics2D = simpleImage.NewGraphics2D();
				// clear the image to white
				simpleImageGraphics2D.Clear(RGBA_Bytes.White);
				// draw a circle
				simpleImageGraphics2D.Circle(50, 50, 30, RGBA_Bytes.Blue);
				// draw a line
				simpleImageGraphics2D.Line(10, 100, 520, 50, new RGBA_Bytes(20, 200, 200));
				// draw a filled box
				simpleImageGraphics2D.FillRectangle(60, 260, 200, 280, RGBA_Bytes.Yellow);
				// and an outline around it
				simpleImageGraphics2D.Rectangle(60, 260, 200, 280, RGBA_Bytes.Magenta);
				// draw some text
				simpleImageGraphics2D.DrawString("A Simple Example", 300, 400, 20);

				// and save this image out
				ImageTgaIO.Save(simpleImage, "SimpleDrawAndSave.tga");
			}

			// now we will we will show how to use the render function to draw more complex things
			{
				ImageBuffer lessSimpleImage = new ImageBuffer(640, 480, 32, new BlenderBGRA());
				Graphics2D lessSimpleImageGraphics2D = lessSimpleImage.NewGraphics2D();
				// clear the image to white
				lessSimpleImageGraphics2D.Clear(RGBA_Bytes.White);
				// draw a circle
				Ellipse ellipseTest = new Ellipse(0, 0, 100, 50);
				for (double angleDegrees = 0; angleDegrees < 180; angleDegrees += 22.5)
				{
					VertexSourceApplyTransform rotatedTransform = new VertexSourceApplyTransform(ellipseTest, Affine.NewRotation(MathHelper.DegreesToRadians(angleDegrees)));
					VertexSourceApplyTransform rotatedAndTranslatedTransform = new VertexSourceApplyTransform(rotatedTransform, Affine.NewTranslation(lessSimpleImage.Width / 2, 150));
					lessSimpleImageGraphics2D.Render(rotatedAndTranslatedTransform, RGBA_Bytes.Yellow);
					Stroke ellipseOutline = new Stroke(rotatedAndTranslatedTransform, 3);
					lessSimpleImageGraphics2D.Render(ellipseOutline, RGBA_Bytes.Blue);
				}

				// and a little polygon
				PathStorage littlePoly = new PathStorage();
				littlePoly.MoveTo(50, 50);
				littlePoly.LineTo(150, 50);
				littlePoly.LineTo(200, 200);
				littlePoly.LineTo(50, 150);
				littlePoly.LineTo(50, 50);
				lessSimpleImageGraphics2D.Render(littlePoly, RGBA_Bytes.Cyan);

				// draw some text
				TypeFacePrinter textPrinter = new TypeFacePrinter("Printing from a printer", 30, justification: Justification.Center);
				IVertexSource translatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewTranslation(new Vector2(lessSimpleImage.Width / 2, lessSimpleImage.Height / 4 * 3)));
				lessSimpleImageGraphics2D.Render(translatedText, RGBA_Bytes.Red);
				Stroke strokedText = new Stroke(translatedText);
				lessSimpleImageGraphics2D.Render(strokedText, RGBA_Bytes.Black);

				IVertexSource rotatedText = new VertexSourceApplyTransform(textPrinter, Affine.NewRotation(MathHelper.DegreesToRadians(90)));
				IVertexSource rotatedTranslatedText = new VertexSourceApplyTransform(rotatedText, Affine.NewTranslation(new Vector2(40, lessSimpleImage.Height / 2)));
				lessSimpleImageGraphics2D.Render(rotatedTranslatedText, RGBA_Bytes.Black);

				// and save this image out
				ImageTgaIO.Save(lessSimpleImage, "LessSimpleDrawAndSave.tga");
			}
		}
Exemple #30
0
 // TODO: These are not GDI+ compatible.. decide where to put them.
 // TODO: adjust measure string to handle "StringFormat.GenericTypographic" differently than normal padding
 public static SizeF MeasureStringStatic(string text, Font font)
 {
     // TODO: teach agg-sharp to render windows fonts
     var tfp = new TypeFacePrinter(text, font.SizeInPoints);
     var bounds = tfp.LocalBounds;
     return new SizeF((float)bounds.Width,(float)bounds.Height);
 }