Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Styled text in a TextComponent? (Read 4731 times)
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 65
Joined: Jan 23rd, 2015
Styled text in a TextComponent?
Apr 7th, 2015 at 4:04pm
Print Post  
I would like to style the text within a TextComponent within a custom CompositeNode.

I tried calling diagram.drawStyledText() within a 'drawLocal() on my custom CompositeNode but this gives a slightly displaced shadow text - so I can see both the styled and plain text at the same time (See attached image for example of what I'm getting and what I need)

Is there a better way of doing this?
  

Drawing1.png ( 16 KB | 156 Downloads )
Drawing1.png
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Styled text in a TextComponent?
Reply #1 - Apr 7th, 2015 at 7:33pm
Print Post  
If you call super.drawLocal it will also render standard TextComponent's graphics along with text, and drawStyledText will draw over the already rendered unformatted text. You could avoid that by setting component's TextColor to transparent, but then you wouldn't have much use for the hosted components.

In order to change font attributes for all text of a TextComponent, you could assign them through its Font property. E.g. you could specify it in XML definition in format that can be parsed by Java's Font.decode method:

Code
Select All
<Text Name="Text" Font="Arial-italic-4" TextAlignment="Near" />"... 



If you prefer more-varied formatting via HTML tags, better override TextComponent.draw method in custom class:

Code
Select All
package com.myorg;

import java.awt.Graphics2D;

import com.mindfusion.diagramming.*;
import com.mindfusion.diagramming.components.*;

public class StyledTextComponent
	extends TextComponent
{
	@Override
	public void draw(Graphics2D g2d, RenderOptions options)
	{
		Brush textBrush = new SolidBrush(getTextColor());
		textBrush.applyTo(g2d, getBounds());
		if (options.getTargetView() instanceof DiagramView)
		{
			DiagramView view = (DiagramView) options.getTargetView();
			view.getDiagram().drawStyledText(
				g2d, getText(), getFont(), getBounds(), getTextFormat(), textBrush);
		}
	}
} 



and then load the custom component from XML template by specifying its full name:

Code
Select All
<com.myorg.StyledTextComponent ... /> 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 65
Joined: Jan 23rd, 2015
Re: Styled text in a TextComponent?
Reply #2 - Apr 8th, 2015 at 12:49pm
Print Post  
Thanks - the over-ride to get HTML styled text is working very well - just what I needed. Smiley
  
Back to top
 
IP Logged
 
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 65
Joined: Jan 23rd, 2015
Re: Styled text in a TextComponent?
Reply #3 - Apr 8th, 2015 at 3:27pm
Print Post  
Do I need to override something else in the 'StyledTextComponent' so that when I call diagram.createImage() I get the text output?

The diagram on screen looks fine, but when I create an image I loose the entire contents of the 'StyledTextComponent'
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Styled text in a TextComponent?
Reply #4 - Apr 8th, 2015 at 6:06pm
Print Post  
Apparently there isn't DiagramView associated with RenderOptions when exporting images. Try this version of draw method instead:

Code
Select All
@Override
public void draw(Graphics2D g2d, RenderOptions options)
{
	Brush textBrush = new SolidBrush(getTextColor());
	textBrush.applyTo(g2d, getBounds());

	CompositeNode node = (CompositeNode)getParentHost();
	node.getParent().drawStyledText(
		g2d, getText(), getFont(), getBounds(), getTextFormat(), textBrush);
} 



I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
AR
Junior Member
**
Offline


I Love MindFusion!

Posts: 65
Joined: Jan 23rd, 2015
Re: Styled text in a TextComponent?
Reply #5 - Apr 9th, 2015 at 8:59am
Print Post  
Smiley That works.

We add the image to a Word report and it looks fine now.

Thank you for your help.
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint