How to use fonts with embedded colors? - wpf

I want using fonts in WPF which have integral colors / decorative patterns in the symbols. But when I have tried this my text is always shown in black :
in this link ( Color Fonts ) you u can see several fonts of the type that I am attempting to use:
How I can solve this problem?
Here is the code from the above example which uses the "ResotEDream" font from the above link:
<RichTextBox>
<FlowDocument>
<Paragraph>
<Run Text="ABCD" FontFamily="ResotEDream" FontSize="72"/>
</Paragraph>
</FlowDocument>
</RichTextBox>
It is intended to look like the "ABCD" rendering shown above, which is a sample of that font.

Related

Trying to wrap and scale text in a textblock WPF

I'm trying to auto scale the font and wrap text in a TextBlock in WPF and I can't figure it out.
I've Googled it and looked at stackoverflow loads of times and the main suggestion is to place a TextBlock inside a ViewBox. I've tried that, and all it does is scale the whole text down to one line instead of wrapping it.
If I just use a TextBlock without a ViewBox it wraps, but doesn't scale to fit. It's driving me mad, as I am literally trying to move from WinForms to WPF to make better looking UIs.
I've tried StackPanel and DockPanel and they still don't have the desired effect.
All I want is a TextBlock to take a string of text of unknown size and display it scaled and wrapped. I don't understand why it's so difficult
It is helpful to include code of what you have tried.
When I do this:
<Grid>
<TextBox VerticalAlignment="Center" TextWrapping="Wrap" Width="100"/>
</Grid>
I get this:
Is that what you are looking for?
You could also check out the RichTextBox if you need more features.

WPF: how to write text in a different direction?

I need to write text in the orientation specified for the image below. The fact is that I saw some examples around here by using a textblock and rotating the angle of the control using "RenderTransform", but this is not what I really need. I tried to do it using an image but it doesn't fit very well... so I really don't know how to solve it. If you look at the image beside you can see that the text is written from bottom to top and the line below the text is in the right of the screen.
This is the screen that I need to develop:
I tried by rotating the textblock, but the only way that it works for me was wrapping the text, but this is just the "closest" solution that I found. Also, as you can see, I need to set a border for the textblock.
Anyway, I hope you can help me because any example around fits with my problem.
In order to rotate your text at 90 degrees, I believe that you will need to use the LayoutTransform instead of the RenderTransform:
<TextBlock Text="FootRoller" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock.LayoutTransform>
<RotateTransform Angle="-90"/>
</TextBlock.LayoutTransform>
</TextBlock>
The difference is when the transform will be applied. Using the LayoutTransform, the text will be rotated before the layout pass and this will be important in your case. I imagine that using the RenderTransform will rotate your TextBlock, but as it does that after the layout pass, it would not show it all... this is because it was measured for size before it was rotated.
You can find out full details from the Transforms Overview page on MSDN. From the linked page:
LayoutTransform – A transform that is applied before the layout pass. After the transform is applied, the layout system processes the transformed size and position of the element.
RenderTransform – A transform that modifies the appearance of the element but is applied after the layout pass is complete. By using the RenderTransform property instead of the LayoutTransform property, you can obtain performance benefits.
They're all right. RenderTransform should be all you need. Like;
<TextBlock Text="FootRoller" RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock.RenderTransform>
<CompositeTransform Rotation="-90"/>
</TextBlock.RenderTransform>
</TextBlock>
P.S. - You can literally just change RenderTransform to LayoutTransform which Sheridan has provided an explanation for in his answer.
If RenderTransform didn't work, take a look at LayoutTransform. You didn't tell us why RenderTransform didn't work but it's usually a safe bet that LayoutTransform will solve whatever problem it gave you.

Font not rendering properly on WPF desktop application

I have a custom font in my project. But WPF is not rendering it properly.
<TextBlock Text="This is a test sentence"
Foreground="Black" FontSize="50"
FontFamily="Assets/Fonts/#Custom Font"/>
Now I have two font files named:
Custom Font Medium Italic.ttf
Custom Font Bold Extended Italic.ttf
When I open these two files, the font name shown is only Custom Font. In the above textblock, if I use full file name,i.e., Custom Font Medium Italic.ttf, it doesn't work. So how to use these fonts in the textblock differently.
You need to reference the name of the font and not the name of the font file. I think that you also need to add a '#' character as well... try something like this:
<FontFamily x:Key="testfont">Assets/Fonts#Custom Font Bold Italic</FontFamily>
From the FontFamily Class page on MSDN:
XAML Values
fontFamilyFolderReference
A string specifying a folder containing the font, along with a font family name. The folder and font family name are delimited by a # character. The folder reference may be absolute, or relative. For example, "Custom Fonts#My Custom Font".
you can put the font files into different folders. e.g.
/Resources/Font/Medium/Custom Font Medium Italic.ttf
/Resources/Font/Bold_Extended/Custom Font Bold Extended Italic.ttf
then they can be referenced separately.

Rotate the text inside a small grid/panel

<Label Grid.Row="1"
Height="70"
Margin="2"
Width="300"
Content="{l:Translate Key={x:Static l:MultistringTags.SHOW_MENU}}"
DockPanel.Dock="Bottom"
FontSize="20"
FontWeight="Bold"
Foreground="White">
<Label.RenderTransform>
<RotateTransform Angle="270" />
</Label.RenderTransform>
</Label>
Here I want to rotate the text, which is inside a grid and a grid column width equals with text height. In this case I see only part of text like if text was drawn without rotating cutted of by grid width, and rotated to required angle. I have tried panels, they give me same result.
Does anybody know some workaround to make it show all the text and I don't want to use image because text should be translatable.
I believe if you change it to set the LayoutTransform instead of RenderTransform, it will prevent the text from being cut off.
<Label.LayoutTransform>
<RotateTransform Angle="270" />
</Label.LayoutTransform>
Further to #nekizalb's answer stating that you should use a LayoutTransform, the reason that you would need to do that instead of using a RenderTransform is because of the timing at which each occurs... a LayoutTransform will affect results of layout.
From the UIElement.RenderTransform Property page on MSDN:
A render transform does not regenerate layout size or render size information. Render transforms are typically intended for animating or applying a temporary effect to an element. For example, the element might zoom when focused or moused over, or might jitter on load to draw the eye to that part of the user interface (UI).
From the FrameworkElement.LayoutTransform Property page on MSDN:
In contrast to RenderTransform, LayoutTransform will affect results of layout.
Example scenarios where LayoutTransform would be useful include: rotating elements such as menu components from horizontal to vertical or vice versa, scaling elements (zooming in) on focus, providing editing behavior, etc.

Why is Typography.Capitals parameter ignored?

I have applied SmallCaps as shown below, but it doesn't seem to have any effect on in the browser or in a design window.
<TextBlock Text="Text Here !" Typography.Capitals="SmallCaps"/>
Why is Typography.Capitals parameter ignored? Are there any settings that need to be enabled for this ?
UPDATE
It seems that for these properties to work, the font used must support them. Silverlight can not perform magic with the font, it can only work with the features built into the font itself. And it seems that there are some differences between different versions of Windows, which made this even more confusing. I have tried this on Windows 7 and 8 using the following fonts:
Gabriola, Georgia, Verdana, Arial, Comic Sans MS, Calibri, Segoe UI, Portable User Interface
On both Win7 and 8 the only properties that ever worked were SmallCaps and AllSmallCaps. None of the other settings made any difference whatsoever, neither on Win7 or Win8. On Windows 8 these two properties worked for all the fonts listed above. On Windows 7 the only fonts where they did work were Calibri and Gabriola. I then started looking into the versions of the fonts installed on the two different machines. It turns out they are different. For example, on my Win7 machine both Verdana and Segoe UI is of version 5.05. On the Win8 machine Verdana is version 5.31 and Segoe UI is version 5.28.
So I think this is why we get different results on different machines. It has nothing to do with Silverlight, but with the versions of the fonts installed on the client machine. The version of Verdana installed on Win7 has no support for SmallCaps and AllSmallCaps, but the version that comes with Win8 does have that support.
END UPDATE
I am definitely seeing a difference with SmallCaps and AllSmallCaps. The rest of the values don't seem to do anything. It could depend on the FontFamily used I suppose. Any way, the following code renders like the screen shot below.
<ContentControl FontSize="18"
FontFamily="Segoe UI">
<StackPanel>
<TextBlock Text="Writing Some Text Here in the Text Block. AllPetiteCaps"
Typography.Capitals="AllPetiteCaps"></TextBlock>
<TextBlock Text="Writing Some Text Here in the Text Block. AllSmallCaps"
Typography.Capitals="AllSmallCaps"></TextBlock>
<TextBlock Text="Writing Some Text Here in the Text Block. Normal"
Typography.Capitals="Normal"></TextBlock>
<TextBlock Text="Writing Some Text Here in the Text Block. PetiteCaps"
Typography.Capitals="PetiteCaps"></TextBlock>
<TextBlock Text="Writing Some Text Here in the Text Block. SmallCaps"
Typography.Capitals="SmallCaps"></TextBlock>
<TextBlock Text="Writing Some Text Here in the Text Block. Titling"
Typography.Capitals="Titling"></TextBlock>
<TextBlock Text="Writing Some Text Here in the Text Block. Unicase"
Typography.Capitals="Unicase"></TextBlock>
</StackPanel>
</ContentControl>
I'm not sure how much difference there is between WPF and Silverlight on this, but apparently for WPF the font has to be an OpenType font. According to wpf.2000things.com:
WPF includes a Typography class, which allows setting various attached properties for textual elements. These properties only affect text that is rendered using an OpenType font.
And in Programming WPF, 2nd Edition:
WPF supports both TrueType and OpenType fonts. OpenType fonts often contain
many alternates to the basic set of character shapes in order to support advanced
typographical functionality. If you are using a low-level text-handling feature such as
GlyphRun, you can use these alternates directly, referring to them by glyph index. But
if you are using the higher-level elements, such as TextBlock or the FlowDocument
viewers, these can locate and use the appropriate glyphs for you. You can control
which character shapes are used with the attached properties defined by the
Typography class.

Resources