Exemplo n.º 1
0
        public static Dictionary <char, ImageBuffer> GetCorrectCache(TypeFace typeFace, RGBA_Bytes color, double emSizeInPoints)
        {
            lock (typeFace)
            {
                // TODO: check if the cache is getting too big and if so prune it (or just delete it and start over).

                Dictionary <RGBA_Bytes, Dictionary <double, Dictionary <char, ImageBuffer> > > foundTypeFaceColor;
                if (!Instance.typeFaceImageCache.TryGetValue(typeFace, out foundTypeFaceColor))
                {
                    // add in the type face
                    foundTypeFaceColor = new Dictionary <RGBA_Bytes, Dictionary <double, Dictionary <char, ImageBuffer> > >();
                    Instance.typeFaceImageCache.Add(typeFace, foundTypeFaceColor);
                }

                Dictionary <double, Dictionary <char, ImageBuffer> > foundTypeFaceSizes;
                if (!foundTypeFaceColor.TryGetValue(color, out foundTypeFaceSizes))
                {
                    // add in the type face
                    foundTypeFaceSizes = new Dictionary <double, Dictionary <char, ImageBuffer> >();
                    foundTypeFaceColor.Add(color, foundTypeFaceSizes);
                }

                Dictionary <char, ImageBuffer> foundTypeFaceSize;
                if (!foundTypeFaceSizes.TryGetValue(emSizeInPoints, out foundTypeFaceSize))
                {
                    // add in the point size
                    foundTypeFaceSize = new Dictionary <char, ImageBuffer>();
                    foundTypeFaceSizes.Add(emSizeInPoints, foundTypeFaceSize);
                }

                return(foundTypeFaceSize);
            }
        }
Exemplo n.º 2
0
        public IVertexSource GetGlyphForCharacter(char character)
        {
            // scale it to the correct size.
            IVertexSource sourceGlyph = TypeFace.GetGlyphForCharacter(character);

            if (sourceGlyph != null)
            {
                if (DoUnderline)
                {
                    sourceGlyph = new GlyphWithUnderline(sourceGlyph, TypeFace.GetAdvanceForCharacter(character), TypeFace.Underline_position, TypeFace.Underline_thickness);
                }
                Affine glyphTransform = Affine.NewIdentity();
                glyphTransform *= Affine.NewScaling(currentEmScaling);
                IVertexSource characterGlyph = new VertexSourceApplyTransform(sourceGlyph, glyphTransform);

                if (FlatenCurves)
                {
                    characterGlyph = new FlattenCurves(characterGlyph);
                }

                return(characterGlyph);
            }

            return(null);
        }
Exemplo n.º 3
0
 public StyledTypeFace(TypeFace typeFace, double emSizeInPoints, bool underline = false, bool flatenCurves = true)
 {
     this.TypeFace    = typeFace;
     emSizeInPixels   = emSizeInPoints / PointsPerInch * PixelsPerInch;
     currentEmScaling = emSizeInPixels / typeFace.UnitsPerEm;
     DoUnderline      = underline;
     FlatenCurves     = flatenCurves;
 }
Exemplo n.º 4
0
        public static TypeFace LoadFrom(string content)
        {
            TypeFace fontUnderConstruction = new TypeFace();

            fontUnderConstruction.ReadSVG(content);

            return(fontUnderConstruction);
        }
Exemplo n.º 5
0
        public static TypeFace LoadSVG(String filename)
        {
            TypeFace fontUnderConstruction = new TypeFace();

            string svgContent = "";

            using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (StreamReader reader = new StreamReader(fileStream))
                {
                    svgContent = reader.ReadToEnd();
                }
            }
            fontUnderConstruction.ReadSVG(svgContent);

            return(fontUnderConstruction);
        }
		public MHTextEditWidget(string text = "", double x = 0, double y = 0, double pointSize = 12, double pixelWidth = 0, double pixelHeight = 0, bool multiLine = false, int tabIndex = 0, string messageWhenEmptyAndNotSelected = "", TypeFace typeFace = null)
		{
			Padding = new BorderDouble(3);
			actuallTextEditWidget = new TextEditWidget(text, x, y, pointSize, pixelWidth, pixelHeight, multiLine, tabIndex: tabIndex, typeFace: typeFace);
			actuallTextEditWidget.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
			actuallTextEditWidget.MinimumSize = new Vector2(Math.Max(actuallTextEditWidget.MinimumSize.x, pixelWidth), Math.Max(actuallTextEditWidget.MinimumSize.y, pixelHeight));
			actuallTextEditWidget.VAnchor = Agg.UI.VAnchor.ParentBottom;
			AddChild(actuallTextEditWidget);
			BackgroundColor = RGBA_Bytes.White;
			HAnchor = HAnchor.FitToChildren;
			VAnchor = VAnchor.FitToChildren;

			noContentFieldDescription = new TextWidget(messageWhenEmptyAndNotSelected, textColor: RGBA_Bytes.Gray);
			noContentFieldDescription.VAnchor = VAnchor.ParentBottom;
			noContentFieldDescription.AutoExpandBoundsToText = true;
			AddChild(noContentFieldDescription);
			SetNoContentFieldDescriptionVisibility();
		}
Exemplo n.º 7
0
 public double GetAdvanceForCharacter(char character)
 {
     return(TypeFace.GetAdvanceForCharacter(character) * currentEmScaling);
 }
Exemplo n.º 8
0
 public double GetAdvanceForCharacter(char character, char nextCharacterToKernWith)
 {
     return(TypeFace.GetAdvanceForCharacter(character, nextCharacterToKernWith) * currentEmScaling);
 }
Exemplo n.º 9
0
		public static TypeFace LoadSVG(String filename)
		{
			TypeFace fontUnderConstruction = new TypeFace();

			string svgContent = "";
			using (FileStream fileStream = new FileStream(filename, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
			{
				using (StreamReader reader = new StreamReader(fileStream))
				{
					svgContent = reader.ReadToEnd();
				}
			}
			fontUnderConstruction.ReadSVG(svgContent);

			return fontUnderConstruction;
		}
Exemplo n.º 10
0
		public static TypeFace LoadFrom(string content)
		{
			TypeFace fontUnderConstruction = new TypeFace();
			fontUnderConstruction.ReadSVG(content);

			return fontUnderConstruction;
		}
Exemplo n.º 11
0
		public View3DTextCreator(Vector3 viewerVolume, Vector2 bedCenter, MeshViewerWidget.BedShape bedShape)
		{
			boldTypeFace = TypeFace.LoadFrom(StaticData.Instance.ReadAllText(Path.Combine("Fonts", "LiberationSans-Bold.svg")));

			MeshGroupExtraData = new List<PlatingMeshGroupData>();

			FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
			mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
			mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;

			FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight);
			centerPartPreviewAndControls.AnchorAll();

			GuiWidget viewArea = new GuiWidget();
			viewArea.AnchorAll();
			{
				meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape);
				meshViewerWidget.AllowBedRenderingWhenEmpty = true;
				meshViewerWidget.AnchorAll();
			}
			viewArea.AddChild(meshViewerWidget);

			centerPartPreviewAndControls.AddChild(viewArea);
			mainContainerTopToBottom.AddChild(centerPartPreviewAndControls);

			FlowLayoutWidget buttonBottomPanel = new FlowLayoutWidget(FlowDirection.LeftToRight);
			buttonBottomPanel.HAnchor = HAnchor.ParentLeftRight;
			buttonBottomPanel.Padding = new BorderDouble(3, 3);
			buttonBottomPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

			buttonRightPanel = CreateRightButtonPanel(viewerVolume.y);

			// add in the plater tools
			{
				FlowLayoutWidget editToolBar = new FlowLayoutWidget();

				processingProgressControl = new ProgressControl("Finding Parts:".Localize(), ActiveTheme.Instance.PrimaryTextColor, ActiveTheme.Instance.PrimaryAccentColor);
				processingProgressControl.VAnchor = Agg.UI.VAnchor.ParentCenter;
				editToolBar.AddChild(processingProgressControl);
				editToolBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;

				editPlateButtonsContainer = new FlowLayoutWidget();

				MHTextEditWidget textToAddWidget = new MHTextEditWidget("", pixelWidth: 300, messageWhenEmptyAndNotSelected: "Enter Text Here".Localize());
				textToAddWidget.VAnchor = VAnchor.ParentCenter;
				textToAddWidget.Margin = new BorderDouble(5);
				editPlateButtonsContainer.AddChild(textToAddWidget);
				textToAddWidget.ActualTextEditWidget.EnterPressed += (object sender, KeyEventArgs keyEvent) =>
				{
					InsertTextNow(textToAddWidget.Text);
				};

				Button insertTextButton = textImageButtonFactory.Generate("Insert".Localize());
				editPlateButtonsContainer.AddChild(insertTextButton);
				insertTextButton.Click += (sender, e) =>
				{
					InsertTextNow(textToAddWidget.Text);
				};

				KeyDown += (sender, e) =>
				{
					KeyEventArgs keyEvent = e as KeyEventArgs;
					if (keyEvent != null && !keyEvent.Handled)
					{
						if (keyEvent.KeyCode == Keys.Escape)
						{
							if (meshSelectInfo.downOnPart)
							{
								meshSelectInfo.downOnPart = false;

								ScaleRotateTranslate translated = SelectedMeshTransform;
								translated.translation *= transformOnMouseDown;
								SelectedMeshTransform = translated;

								Invalidate();
							}
						}
					}
				};

				editToolBar.AddChild(editPlateButtonsContainer);
				buttonBottomPanel.AddChild(editToolBar);
			}

			GuiWidget buttonRightPanelHolder = new GuiWidget(HAnchor.FitToChildren, VAnchor.ParentBottomTop);
			centerPartPreviewAndControls.AddChild(buttonRightPanelHolder);
			buttonRightPanelHolder.AddChild(buttonRightPanel);

			viewControls3D = new ViewControls3D(meshViewerWidget);

			buttonRightPanelDisabledCover = new Cover(HAnchor.ParentLeftRight, VAnchor.ParentBottomTop);
			buttonRightPanelDisabledCover.BackgroundColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryBackgroundColor, 150);
			buttonRightPanelHolder.AddChild(buttonRightPanelDisabledCover);
			LockEditControls();

			GuiWidget leftRightSpacer = new GuiWidget();
			leftRightSpacer.HAnchor = HAnchor.ParentLeftRight;
			buttonBottomPanel.AddChild(leftRightSpacer);

			closeButton = textImageButtonFactory.Generate("Close".Localize());
			buttonBottomPanel.AddChild(closeButton);

			mainContainerTopToBottom.AddChild(buttonBottomPanel);

			this.AddChild(mainContainerTopToBottom);
			this.AnchorAll();

			meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;

			AddChild(viewControls3D);

			// set the view to be a good angle and distance
			meshViewerWidget.TrackballTumbleWidget.TrackBallController.Scale = .06;
			meshViewerWidget.TrackballTumbleWidget.TrackBallController.Rotate(Quaternion.FromEulerAngles(new Vector3(-MathHelper.Tau * .02, 0, 0)));

			AddHandlers();
			UnlockEditControls();
			// but make sure we can't use the right panel yet
			buttonRightPanelDisabledCover.Visible = true;
		}
Exemplo n.º 12
0
		public static Dictionary<char, ImageBuffer> GetCorrectCache(TypeFace typeFace, RGBA_Bytes color, double emSizeInPoints)
		{
			lock(typeFace)
			{
				// TODO: check if the cache is getting too big and if so prune it (or just delete it and start over).

				Dictionary<RGBA_Bytes, Dictionary<double, Dictionary<char, ImageBuffer>>> foundTypeFaceColor;
				if (!Instance.typeFaceImageCache.TryGetValue(typeFace, out foundTypeFaceColor))
				{
					// add in the type face
					foundTypeFaceColor = new Dictionary<RGBA_Bytes, Dictionary<double, Dictionary<char, ImageBuffer>>>();
					Instance.typeFaceImageCache.Add(typeFace, foundTypeFaceColor);
				}

				Dictionary<double, Dictionary<char, ImageBuffer>> foundTypeFaceSizes;
				if (!foundTypeFaceColor.TryGetValue(color, out foundTypeFaceSizes))
				{
					// add in the type face
					foundTypeFaceSizes = new Dictionary<double, Dictionary<char, ImageBuffer>>();
					foundTypeFaceColor.Add(color, foundTypeFaceSizes);
				}

				Dictionary<char, ImageBuffer> foundTypeFaceSize;
				if (!foundTypeFaceSizes.TryGetValue(emSizeInPoints, out foundTypeFaceSize))
				{
					// add in the point size
					foundTypeFaceSize = new Dictionary<char, ImageBuffer>();
					foundTypeFaceSizes.Add(emSizeInPoints, foundTypeFaceSize);
				}

				return foundTypeFaceSize;
			}
		}
Exemplo n.º 13
0
		public StyledTypeFace(TypeFace typeFace, double emSizeInPoints, bool underline = false, bool flatenCurves = true)
		{
			this.TypeFace = typeFace;
			emSizeInPixels = emSizeInPoints / PointsPerInch * PixelsPerInch;
			currentEmScaling = emSizeInPixels / typeFace.UnitsPerEm;
			DoUnderline = underline;
			FlatenCurves = flatenCurves;
		}
Exemplo n.º 14
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;
        }
Exemplo n.º 15
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);
        }
		public View3DBrailleBuilder(Vector3 viewerVolume, Vector2 bedCenter, BedShape bedShape)
		{
			monoSpacedTypeFace = ApplicationController.MonoSpacedTypeFace;

			brailTypeFace = TypeFace.LoadFrom(StaticData.Instance.ReadAllText(Path.Combine("Fonts", "Braille.svg")));

			MeshGroupExtraData = new List<PlatingMeshGroupData>();

			FlowLayoutWidget mainContainerTopToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom);
			mainContainerTopToBottom.HAnchor = Agg.UI.HAnchor.Max_FitToChildren_ParentWidth;
			mainContainerTopToBottom.VAnchor = Agg.UI.VAnchor.Max_FitToChildren_ParentHeight;

			FlowLayoutWidget centerPartPreviewAndControls = new FlowLayoutWidget(FlowDirection.LeftToRight);
			centerPartPreviewAndControls.AnchorAll();

			GuiWidget viewArea = new GuiWidget();
			viewArea.AnchorAll();
			{
				meshViewerWidget = new MeshViewerWidget(viewerVolume, bedCenter, bedShape);
				meshViewerWidget.AllowBedRenderingWhenEmpty = true;
				meshViewerWidget.AnchorAll();
			}
			viewArea.AddChild(meshViewerWidget);

			centerPartPreviewAndControls.AddChild(viewArea);
			mainContainerTopToBottom.AddChild(centerPartPreviewAndControls);

			FlowLayoutWidget buttonBottomPanel = new FlowLayoutWidget(FlowDirection.LeftToRight);
			buttonBottomPanel.HAnchor = HAnchor.ParentLeftRight;
			buttonBottomPanel.Padding = new BorderDouble(3, 3);
			buttonBottomPanel.BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor;

			buttonRightPanel = CreateRightButtonPanel(viewerVolume.y);

			// add in the plater tools
			{
				FlowLayoutWidget editToolBar = new FlowLayoutWidget();

				processingProgressControl = new ProgressControl("Finding Parts:".Localize(), ActiveTheme.Instance.PrimaryTextColor, ActiveTheme.Instance.PrimaryAccentColor);
				processingProgressControl.VAnchor = Agg.UI.VAnchor.ParentCenter;
				editToolBar.AddChild(processingProgressControl);
				editToolBar.VAnchor |= Agg.UI.VAnchor.ParentCenter;

				editPlateButtonsContainer = new FlowLayoutWidget();

				textToAddWidget = new MHTextEditWidget("", pixelWidth: 300, messageWhenEmptyAndNotSelected: "Enter Text Here".Localize());
				textToAddWidget.VAnchor = VAnchor.ParentCenter;
				textToAddWidget.Margin = new BorderDouble(5);
				editPlateButtonsContainer.AddChild(textToAddWidget);
				textToAddWidget.ActualTextEditWidget.EnterPressed += (object sender, KeyEventArgs keyEvent) =>
				{
					InsertTextNow(textToAddWidget.Text);
				};

				Button insertTextButton = textImageButtonFactory.Generate("Insert".Localize());
				editPlateButtonsContainer.AddChild(insertTextButton);
				insertTextButton.Click += (sender, e) =>
				{
					InsertTextNow(textToAddWidget.Text);
				};

				editToolBar.AddChild(editPlateButtonsContainer);
				buttonBottomPanel.AddChild(editToolBar);
			}

			GuiWidget buttonRightPanelHolder = new GuiWidget(HAnchor.FitToChildren, VAnchor.ParentBottomTop);
			centerPartPreviewAndControls.AddChild(buttonRightPanelHolder);
			buttonRightPanelHolder.AddChild(buttonRightPanel);

			viewControls3D = new ViewControls3D(meshViewerWidget);

			viewControls3D.ResetView += (sender, e) =>
			{
				meshViewerWidget.ResetView();
			};

			buttonRightPanelDisabledCover = new Cover(HAnchor.ParentLeftRight, VAnchor.ParentBottomTop);
			buttonRightPanelDisabledCover.BackgroundColor = new RGBA_Bytes(ActiveTheme.Instance.PrimaryBackgroundColor, 150);
			buttonRightPanelHolder.AddChild(buttonRightPanelDisabledCover);
			LockEditControls();

			GuiWidget leftRightSpacer = new GuiWidget();
			leftRightSpacer.HAnchor = HAnchor.ParentLeftRight;
			buttonBottomPanel.AddChild(leftRightSpacer);

			closeButton = textImageButtonFactory.Generate("Close".Localize());
			buttonBottomPanel.AddChild(closeButton);

			mainContainerTopToBottom.AddChild(buttonBottomPanel);

			this.AddChild(mainContainerTopToBottom);
			this.AnchorAll();

			meshViewerWidget.TrackballTumbleWidget.TransformState = TrackBallController.MouseDownType.Rotation;

			AddChild(viewControls3D);

			// set the view to be a good angle and distance
			meshViewerWidget.ResetView();

			AddHandlers();
			UnlockEditControls();
			// but make sure we can't use the right panel yet
			buttonRightPanelDisabledCover.Visible = true;

			//meshViewerWidget.RenderType = RenderTypes.Outlines;
			viewControls3D.PartSelectVisible = false;
			meshViewerWidget.ResetView();
		}