How can I render matching text with Pango on two computers? - dpi

We have tests that check how code build on Gtk with Pango and Cairo renders shapes and text.
I can't get font rendering to match between different developers computers and CI.
The font seems to render 1 or 2 pixels higher or lower.
Hinting, and DPI may be setup different between these machines, can I set some environment variables to ensure fonts render at the same size and with the same hinting ?

Related

Why fonts in Qt are appearing blurry or pixelated?

All my fonts are appearing pixelated, so I used AntiAliasing but it isn't helping out. As you can see the pixelated font in the image itself:
This is the code I am currently using:
butt1 = QtWidgets.QLabel("""Scrappr""")
font = QtGui.QFont()
font.setStyleStrategy(QtGui.QFont.PreferAntialias)
font.setPixelSize(22)
font.setFamily('Segoe UI Bold')
butt1.setFont(QtGui.QFont(font))
I tried different solutions on SO, qtforums etc but nothing works for me :(
I tried:
Different combinations of ClearType text but It didn't work out as, by default all the text appears good on windows and chrome but with Qt only, it becomes pixelated.
Changing windows aero theme to classic one...
But none of them helped.
Here are My PC Specs:
windows: 7 ultimate
PySide2 version: 5.14.2.1
Resolution: 1360 X 768
I'm using BrownPro font and the texts were blurry at all resolutions, but much more evident at low resolutions.
I was able to solve the issue by setting the hinting preference for the font to: PreferNoHinting. Applying it at the application level, fixes the issue everywhere.
Here is the documentation: https://doc.qt.io/qt-5/qfont.html#HintingPreference-enum
And here is the code I used:
QFontDatabase::addApplicationFont(":/fonts/BrownPro-Bold.ttf");
QFontDatabase::addApplicationFont(":/fonts/BrownPro-Regular.ttf");
QFontDatabase::addApplicationFont(":/fonts/BrownPro-Light.ttf");
QFont brown_pro_font("BrownPro");
brown_pro_font.setHintingPreference(QFont::HintingPreference::PreferNoHinting); //This line did the trick
QApplication::setFont(brown_pro_font);
Try to see the fonts used by PyQt5:
import PyQt5
from pyQt5 import QtGui
dir(QtGui.QFont)
the result will show all you need for QFond and the fonts can be used:
[..., 'Helvetica',...,'SansSerif',..., 'Serif',..., 'Times', ...
You can try to add your custom fonts but you need to test each font.
For example, the documentation tells us:
In Windows a request for the “Courier” font is automatically changed to “Courier New”, an improved version of Courier that allows for smooth scaling. The older “Courier” bitmap font can be selected by setting the PreferBitmap style strategy (see setStyleStrategy() ).
Once a font is found, the remaining attributes are matched in order of priority:
fixedPitch()
pointSize() (see below)
weight()
style()
I happen to work with Qt last year and i used qml for building the UI part of my application.
Qt itself prefers us to use qml for building UI, since they have written a UI engine that renders everything better compared to the old engines.
In case of PyQt you are using the python only approach which is only not usually recommended, i am not saying that the qml version is pixel perfect. it still works bad at drawing curves (but that is not the stuff we usually require). As far as your problem is concerned qml will work fine for you (it has much better text rendering).
You might struggle a bit finding the learning resource for qml. But at least give it a shot and yes it is easier much easier than Python only approach.

Font size rendering is different depending upon login using Gimp?

I am using Gimp python-fu plugin. The plug-in written correctly renders a text block:
(GIMP_UNIT_POINT = 3)
titleBlockLayer = pdb.gimp_text_layer_new(img, title, <font_name>, 40, GIMP_UNIT_POINT)
but only if gimp is invoked from the X window manager (or a terminal window) when logged in on the computer's console (Fedora, various releases, same behavior; various releases of GIMP, same behavior).
However, when logged in via ssh, (using X11 forwarding to display locally), the fonts are rendered HUGE by comparison.
I am confused because (supposedly) the same login .profile and .rc files have been run regardless.
Does anyone have a clue as to what/where/how GIMP determines what a POINT means, because it is obviously not coded in but dependent upon some resource file.
For Gimp a point is 1/72 of an inch, according to the doc of gimp_text_get_extents_fontname() in the PDB browser:
If you need to display a font in points, divide the size in points by 72.0 and multiply it by the vertical resolution of the image you are taking into account.
Experimentally, when using points in gimp_text_layer_new() the size depends on the image print definition. This value can depend on user settings (72DPI by default) but you can control/set it using gimp_image_get_resolution(...) and gimp_image_set_resolution(...). What bothers me though it that it seems that at least on my Ubuntu 16.04 gimp_text_layer_new() works in inches and not in points (at 72DPI, points and pixels should be equivalent), so I would stick to using pixels and to the point<->pixels conversions using the image resolution.
Btw, what are the versions of Gimp and the Pango and Cairo libs on your various systems?
Edit: Possible explanation: it appears that in recent versions (since 2.8 at least), gimp_text_layer_new() accepts more than units than just pixels and points. It also takes millimeters, inches, and picas. So it's no longer 0 for pixels and 1 for points, and you can use the predefined UNIT_* values. The catch: 1 is no longer the value for points but is now the value for inches:
UNIT_PIXEL=0
UNIT_INCH=1
UNIT_MM=2
UNIT_POINT=3
UNIT_PICA=4

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

Chromium and Firefox display colors differently and I don't know which one is doing it right

I've been building a website under Ubuntu 17.10 and use Firefox and Chromium for testing. The two browsers show quite different colors (not only for images but all colors) and I always thought that it is Chromium which for some reason wrongly over-saturates them, so up until now I always chose colors that looked right in Firefox.
But I'm starting to get more and more complaints about the website's background being too purple - which it shouldn't be in my opinion as only the blue component of it's color (#eeeeff) is "elevated", but it has reached a point that more people are seeing it as purple than blue, what makes me confused.
This is the aforementioned color displayed in Firefox (left) and Chromium (right).
And this is how I see a website:
The difference is quite large (notice how even the favicon is different) and I'm asking you to tell me which one is the browser I should trust when choosing the colours of my websites and whether I could do something to avoid it being displayed so differently in different browsers.
(There are some users that see the overly saturated colors in Firefox too. So now which is the right one, really?)
Another option is to open chrome://flags/ and select the option sRGB on the Force color profile item.
By using this setting instead of disabling the Use hardware acceleration when available, you don't lose some nice features like the 3D view on Google Maps.
Solution found here: https://www.reddit.com/r/Fedora/comments/74h5yh/blue_shows_as_purple_in_chrome/
Using GPick as a Color Picker and calling a Website with Color Hexcode like
http://www.color-hex.com/color-palette/54430
I see, that Firefox renders the RGB Colors exactly, meaning GPick identifies the same Hex Code from CSS.
Whereas Chromium renders some kind of differnt color.
You can call
chrome://flags/#force-color-profile
and set the Color Profile in Chromium to sRGB, so the rendered Color from Chromium is identified the same as the HexCode with GPick.
If you disable 'Use hardware acceleration when available' in Chromium Settings and relaunch, Chromium displays colors correctly. When turned on, Chromium colors are off. I consider this as a workaround until Chromium color management issue with hardware acceleration is resolved.
With the other two colours being equal, your colour is right in the middle of "blue territory".
If you convert it to HSL and look on the hue line, you can see it is right in the middle of the "blue" frequency range.
Consequently, any hint of green or red is incorrect.

Creating a cross browser icon webfont

I have been making my own webfont taking as a starting point articles from web designer depot and intridea.
I know different engines render fonts differently and but the issue I'm having is that firefox renders the font higher than chrome - at the size I am displaying the font this is very noticeable (3 or 4 px - which on a button means they're totally misaligned).
I have also referenced Github's octicon documentation - when checking out how octicons compare browser they look great! No noticeable difference as far as I can see. How did they achieve this?
I am using inkscape and have tried a couple of different svg starter templates. Setup is Set width: 1024 and have tried the icons at various sizes with no different outcome. i.e. 512pt square and aligned just under the baseline.
My question is what rules do I need to impliment when creating a webfont to get the smallest difference between browser rendering of the font?
This is a complicated question that involves something called vertical metrics. A font has three sets of these. the first set, found in the 'hhea' table, are generally specific to Mac. The other two sets, found in the 'OS/2' table relate to Windows (and Linux). The idea is to get these values equalized. Our Generator has a feature called oddly enough 'Fix Vertical Metrics' which does a best guess at these. Note that Github used the Generator for finishing their icons.
I know this doesn't relate specifically to SVG fonts, but I'm pretty sure this is where your problems lie. Having different vertical metrics values screws up the baselines across platforms.
Some reading:
http://blog.typekit.com/2010/07/14/font-metrics-and-vertical-space-in-css/
http://webfonts.info//webfonts-know-how/part-1-we-need-talk-about-line-height
http://code.google.com/p/googlefontdirectory/wiki/VerticalMetricsRecommendations
There's a webapp, icomoon : http://icomoon.io/app/
It make the job pretty well but you have to test the rendering of the different icons.
They offert a lot of icons if you don't want do design everything.
I had the same problem, and solved it by manually setting the metrics for all three types.
You can see my working solution with screenshots of the settings here: https://stackoverflow.com/a/20609766/955413
I used the Icomoon App to create the Emoji icon font as well as for creating custom icon fonts on a per project basis.
The Icomoon App allows you to do each of the following :
Get one or more icons from several popular icon fonts
Upload other fonts, which may be icon fonts but also regular fonts
Upload SVG files to use as icons
Combine any number of icons from any number of available fonts
Set the UNICODE hex value for whichever characters you need
Export and/or save the font set you create
For more details, see Create webfont with Unicode Supplementary Multilingual Plane symbols.

Resources