Font rendering in XNA is getting low quality - text

I am currently working in XNA 4.0 trying to render a font that I got. The font is rendered with this:
spriteBatch.DrawString(this.font, this.text, new Vector2(10, 10), this.color);
But some of my letters gets blurry and low quality (See image)
I have tried to change the SamplerState of the GraphicDevice but that does not seem to improve anything.
-Update-
After testing one of the ideas were XNA would compress the text and in that case loosing quality i tried out to create my own font texture instead of generating one using a .spritefont. And then sending that into the contentloader, the results I managed to get was just slightly larger text but with the same artifacts.
See Image
And I was now wondering if the problem still can have to do with compressing problems or if there could be another issue making the font get a lower quality in the program compared to using it ouside the program.
The way I am currently loading my font is using
font= ContentManager.Load<SpriteFont>(FontPath);

It's because XNA uses compression for spritefonts. The possible workarounds are:
Use Nuclex framework, which includes an alternative font importer;
Make your own font texture, following the instructions from Shawn Hargreaves's blog;
In your SpriteFont definition, double the size of generated font, then draw it at half its size.

Related

How Can I Fix Inconsistent Text Downscaling with a Rich Text Label In Godot?

I have a rich text label that works fine under a resolution of 1920x1080. However, when scaled down to the resolution on my laptop, which has a 1366x768 resolution, the text on said label becomes janky and malformed.
Some lines are cut off at the top or the bottom, and others are squished (as you can see in the image at lines 3, 6, and 13).
I'm using Godot v3.5.1 and the text font is Noto Sans Regular from here
I tried enabling mipmaps, using the filter, disabling anti aliasing, disabling font oversampling and enabling GPU pixel snap under Project Settings > Rendering > 2D > Snapping. And out of all of those, only the pixel snap setting worked. Completely fixes the issue and the text is rendered properly.
However, this completely breaks an animation of a spinning circle that plays at basically all times during the actual gameplay. It becomes stuttered and shakes instead of the normally smooth animation it has otherwise. I realize this may possibly be fixed by using SVG instead of PNG sprites, but I feel like that's not an ideal solution in case other sprites get added. Especially since my game will also allow community members to add their own sprites for their own game play.
So is there any way to fix the text without breaking the animations, or make it so that the animations don't break with pixel snap enabled?

Text distorting during PNG rendering in Apache Batik

There are some very strange distortion in the images that are rendered via Apache Batik.This issue is not temporary as the distortion is happening every time the call is made, at the very same co-ordinates for the same svg. This happens in Linux environments and I am not able to reproduce this issue in mac OS environments.I am using Oswald custom font (from google fonts) and there is usage of transformation attributes like letter-spacing, rotate functionality.
Tried many of the suggestions like:
1) Verified if the Oswald font is registered to the Graphics environment.
2) Removed text transformation attributes like letter-spacing,rotate, but still the distortion is occuring. We have also replaced letter-spacing attributes with kerning.Tried with shape-rendering="geometricPrecision" also to no success.
3) Tried with other fonts and din't face the distortion with Arial custom font, but with Oswald, Roboto the distortion still exists.Our usecase needs Oswald Font, hence we cannot use Arial font.
4) Tried SVG fonts by embedding the svg fonts in the svg file - No success.
5) Tried trim functionality but no success.
6) Replaced the characters where the distortion is happening and the issue is solved, but I am not able to deduce anything from this.
7) Increased And decreased the font size by 1px where the distortion is happening and the issue is solved, but I am not able to deduce anything from this.
I found few threads where the reason was mentioned that Batik rendering varies per OS environment but was not able to find any solution. Was anyone able to solve this?
Upgrading JDK from 8 to 11 has solved the problem.

FabricJS Text vs NodeJs Node Canvas Text - The Fonts Look Different

I am really stressed out with this, i have built an entire designer with Fabricjs, gone through some right hoops with the text to make it work how it's needed. The problem is now when the data from the canvas is sent to the server for a full resolution render with NodeJs (fabricjs in node) the fonts are coming out looking different to they do in the browser.
All the fonts are installed on the server, and the correct font does render, it just seems to have different spacing between the characters even though the fabric version is the same and all the extension code is the same on browser and server side, all the TTF fonts are the same etc etc
Here is the browser version:
And here is the node js version:
As you can see the font is correct on the node one compared to the browser one, but it's being rendered slightly differently.
Is there a solution anyone knows of to fix this?
I don't believe that there is any way to solve this problem when using fabric.js
Text in fabric.js can be scaled arbitrarily, but then it is rasterized and displayed as a canvas object like any other image.
You can see in the fabric.js demos that the text will stretch like an image until your input is complete, then it re-renders to a new image at that scale.
Knowing that this is how fabric.js handles text, it is possible to select two scales that produce quite different results:
In the image above you can see that the two fonts are pretty much the same size, but the one on the right (slightly larger) has been rasterized such that it appears to have a bolder appearance. It's the best example I could reproduce with limited time.
This is why rendering the fabric.js objects in your browser at a smaller resolution than the server will lead to the font appearing slightly different.
If you try rendering the browser version at the same size as the server you are likely going to get the same results.

UWP - Black color instead of transparency

This is an issue for xamarin.uwp and FFImageLoading, but it reproduces only in UWP.
The issue with optimized files by Photoshop.
I optimized my images on a server with Photoshop. I exported them with option Smaller File (8-bit) after it I got black color in UWP (ios and android are ok).
When I deleted downsample parameters for CachedImage(FFImageLoading control) then transparency was back.
Example:
And files before optimization and after it
https://github.com/luberda-molinet/FFImageLoading/wiki/Xamarin.Forms-API
Says that the CachedImage class does not support transparency on iOS or Windows Phone. Perhaps since the article was written iOS support has been added but not yet UWP.
It's a bug, please make a separate issue on project site. It's related to this:
8 bit PNG can have no more than 256 colors. A part of the PNG file structure holds pointers to 256 colors and then each pixel in the image gets its color from one of those pointers. Thus each pixel only consumes one bytem its 0-255 value pointing to its color on the palette. On the other hand, a 32 bit PNG is 4 bytes per pixel and each pixel can represent a different ARGB color value.
Pixel Format
// Edit I created it: https://github.com/luberda-molinet/FFImageLoading/issues/986

Coloured textures for POIs

I was trying to use a coloured texture (PNG 24/RGB) for a POI (bicycle_parking) and it was not being rendered. It was added properly as a texture, it just won't be rendered on the POI.
After some testing I came to believe that POIs only accept grayscale textures that can later be filled up with a color. Is this right?
I also found out that the icon needs to be of a specific size (I got it working only at 32x32 pixels and 512x512, but the scaling did not make it look good). Is there any information regarding this?
Now I have a grayscale icon (mostly white) but the fill color does not change the white as expected. This is as far as I got..
Here's a set of icons similar to the ones I need to render into POIs
How could I achieve adding this type of icons as the texture of a POI? Workarounds/hacks are welcome as well :)
Thanks!
The texture of the Poi must have a size that is a power of 2 and goes from 32x32 up until 512x512. Also make sure that the colour code of that image is RGB anything else wont work. For the best visual result you have to create 3 sets of pngs for different screen densities, for example see heatmap_legend.png then look at heatmap_legend#2x.png and heatmap_legend#3x.png, you can find them in the "common" folder.
So turns out that the color wasn't a problem after all. It was quite tricky to get one image working, but once I had the image working, adding color to it and saving the PNG worked just fine.
The problem with the image size I experienced is still happening. You need to export it in 32x32, 64x64 or 96x96 in order to StyleEditor not to crash when opening the file.

Resources