I want to display text with directwrite in a specified rectangle and with a specified font size, the text outside the rect should be cutted off.
By searching I found something about CreateTextLayout but it looked like it isn't possible to define the font size with it.
Thanks for answers.
It's not something DirectWrite is responsible for, unless you're using IDWriteBitmapRenderTarget. If you're using DrawText/DrawTextLayout from Direct2D you simply need to use D2D1_DRAW_TEXT_OPTIONS_CLIP option. If you are using DirectWrite bitmap target, it's enough to set target size to layout size, or to blit layout size portion to your destination context.
There is IDWriteTextFormat::SetTrimming(). When applied (with SetTrimming(&DWRITE_TRIMMING{DWRITE_TRIMMING_GRANULARITY_CHARACTER,0,0}, nullptr);), overflowing characters [glyph clusters?] and lines are omitted.
Related
I have this IText object within a parent Group object.
When I select the Group and resize it horizontally (and vertically as well) the IText resizes as well which makes the text Strech and look awfull.
Now what I would like to do is have the IText center itself (keeping its aspect ratio) within the Group.
How can I do that. I tried modifying the Width and Left of the IText when the object is scaling, but that did not work.
try use latest fabricjs version ( 1.6.0.rc1 ) and instead of using fabric.IText use fabric.Textbox.
This new class has the properties you are looking for, the controls normally used for scaling are instead used for resizing the element and the text flows inside it.
I was not able to make the latest fabric.Textbox work exactly like I wanted.
Luckily, I found a way of making the fabric.ITextcenter horizontally when the parent fabric.Group is resized horizontally and also make the same fabric.IText Text grow in size based on the vertical resize. No ugly text stretch.
Here is the solution:
https://jsfiddle.net/t44wyday/46/
How to change the font size of text displayed at run time in the styles.xml in my application depending on the screen size of the device used.
I had the same problem. I wanted to get the same aspect text ratio on every screen. No dp nor sp worked for me. The only solution that works for me is to create a dummy textbox (not visible) at startup then get the textsize and multiply for some ratio (depending on what you actually want). This value should be used to set text size dynamically to your controls.
At least it works for me because the same aspect remains on every different screen.
you need to add in the text size via dimens.xml files depending on screen size.....take a look at this following Question on SO - Text size and different android screen sizes
You can go through this, I used the below method to scale texts on different screen resolutions and sizes.
To define a range of text sizes and a dimension programmatically through the support library, call the TextViewCompat.setAutoSizeTextTypeUniformWithConfiguration(TextView textview, int autoSizeMinTextSize, int autoSizeMaxTextSize, int autoSizeStepGranularity, int unit) method. Provide the text view on which it needs to be applied,the maximum value, the minimum value, the granularity value, and any TypedValue dimension unit (like TypedValue.COMPLEX_UNIT_SP).
I use that code
Font bmpfont=Font.createBitmapFont(icon, new int[0], new int[12], "S");
First param is image, second is offset, third is length and fourth is charset. And I get Font object from that code. But I set that font to TextArea...
TextArea ta=new TextArea();
ta.getStlye().setFont(bmpfont);
ta.setText("S");
Text Area display only "S". Then I want to know how to create my own bitmap font and how to add that font to use. I want to make many bitmap fonts.
Generally we expect you to use the bitmap font creation tools within LWUIT and not invoke this method which is intended for internal use.
Regardless its plainly obvious you used the method incorrectly since the cut offsets don't contain the locations within the font.
Just use the resource editor or Ant task to create a font and then set that font either via the theme or by manually extracting it from the resource file.
I draw some text on screen using ID3DXFont::DrawText. This text should be displayed the same regardless of screen resolution.
For example, if screen resolution is low, text wrapped and when it is higher text is not wrapped. How can I avoid such situation? I want text size to be connected to screen resolution so if resolution is lower I want the text to be relatively smaller so that no wrapping happens. Is there any way?
Thanks in advance
Below is a logical solution. It doesn't have any of the code or procedures needed to make work in direct X but having done something similar outside of DirectX I wanted to share the logic
Working on whatever default screen resolution you want set the font to be the size needed.
Find the percentage of the screen height the font size you chose takes up.
Then having stored that value when you go to render again, in the final version of the program, calculate the font size based on the screen size and the percentage
What I was working in had functions like GetTextHeight and properties on the font size to allow you to set the height (which in turn set the font size appropriately). So if can find anything similar to this in DirectX than this could be a route for you to take.
I am trying to send data to a specific MergeField. The data are sent correctly. Each line of the data has for specific characters. For example the data to the field may be:
12345 FIRST\nABCDE.F SECOND
(it cannot get the newline so i just so it through character \n)
Now in the printed document each character has its one width, '1' is smaller than 'E' for example. So the data are not alligned within the field. I tried the following fonts: Arial, Tahoma, Courier New. Nothing helped.
Any ideas? Thanks in advance.
Ps the data are sent through an executable built by Visual C++ 5.0!!
You should probably use a tab-stop based layout. Set your tab-stops every, say, centimetre or so (i.e. just big than the widest character in your font) and add a tab before each element that needs to be aligned.
With this you shouldn't need to find a fixed width font and can use something more attractive.
Edit: Out of interest, I wonder why you have no luck with Courier New which is fixed width.
Maybe you could post a screenshot somewhere so we can have a look at your problem in more detail.
Try Courier - it does not have kerning (kerning = variable character width)
Also in the Font window there is a check box that allows you to apply kerning to fonts of a certain size or above - setting this value to a large font size may remove kerning.