After asking my previous question about Uniscribe glyph kerning, and not yet receiving an answer, plus further reading on google etc, it seems Uniscribe may not support extracting glyph kerning information from a font.
I therefore have a simple followup question - are there any good examples (preferably with some C++ code) of extracting glyph kerning information for a specified string from a font?
It's mentioned in various places that either Pango, QT or ICU are capable of doing this, but documentation is a bit thin on the ground and I'm struggling to know where to get started.
Any help pointing me in the right direction gratefully received. I already have code in place to render the glyphs in the desired way, I am simply after the extended kerning information, so I can position the glyphs a little nicer.
Thanks,
OpenType fonts have two different ways to specify kerning information, both of which are optional:
The kern table, inherited from TrueType. This table supplies kerning pair information (i.e. how much you should horizontally offset a particular pair of characters). Microsoft provides specs for this table and also supplies some Windows API functions such as GetKerningPair() and GetFontData() that could help you extract values.
The GPOS table, an OpenType table which apparently handles every conceivable form of glyph positioning. Microsoft also has some specs for this table, but honestly I don't even know where you'd begin... You'd probably want to look at how ICU handles this sort of stuff.
I haven't found much in the way of code samples for any of this, though I'd imagine getting kerning values from the kern table is far simpler than the GPOS table.
Related
I want to make a color looks consistent across different environment. I wonder if there is a way to know the color profile the system or the display is currently using, so that I can convert the color into the right color space for the system to render.
Thank Brendan for explaining solutions on Windows. But does anyone have any ideas what it is like on Mac?
I wonder if there is a way to know the color profile the system or the display is currently using, so that I can convert the color into the right color space for the system to render.
There's a way (e.g. the IDXGIOutput6::GetDesc1 method - see https://learn.microsoft.com/en-us/windows/win32/api/dxgi1_6/nf-dxgi1_6-idxgioutput6-getdesc1 ).
Unfortunately this isn't very convenient. The raw information doesn't seem to include any information for gamma; and the maths needed to convert the raw information (RedPrimary, GreenPrimary, BluePrimary, WhitePoint) into a color conversion matrix is difficult to find.
To make it worse; it can't work when the same graphics/window is stretched across multiple monitors with different color profiles; can break when the end user reconfigures monitor settings (as this isn't reflected in the values Windows gets from the monitor), and monitors can change over time. These things put the burden on the end user (making sure all monitors match, doing monitor calibration regularly to achieve accurate colors, etc) and most users (excluding professional graphics designers) don't do this.
Note: Ideally; an OS would provide a standard wide gamut linear color space (e.g. maybe CIE XYZ) and do the color space conversion for all software (e.g. using GPU in the background, for each monitor separately); but Window's APIs are old (and it would've been expensive in the 1990s) and backward compatibility makes it hard to retrofit something like that, so they mostly just adopted "assumed sRGB even if it's wrong" and tacked on an awful mess for software developers who need accurate colors.
Since you are asking about Windows color properties, the Monitor Configuration Functions part of the Win API is available and can be used to get(and set) color attributes. Here are just a few examples:
GetMonitorColorTemperature
GetMonitorRedGreenOrBlueDrive
GetMonitorRedGreenOrBlueGain
GetMonitorBrightness
The components specific to each function needed to build and run your application are listed in each link. eg.
highlevelmonitorconfigurationapi.h
Dxva2.lib
Dxva2.dll
I have some experience rendering text in opengl, where the approach is to use font glyphs (which can eb created through things like freetype) and then used by pulling individual lettings useing texture coordinates, however I wanted to try using a more create font and was thinking about how to render cursive fonts.
I noticed a lot of the fonts on here are cursive fonts and have been unable to find any information on rendering cursive fonts. I realize that a texture lookup approach will probably not work in the same way. I am looking for some advice to point in a direction since I have ben unable to find one.
https://www.fontsquirrel.com/fonts/list/popular
The only thing I can think about is to come up with a set of bezier curves to represent the entire sentence and then render it. This would make it hard to render text dynamically since the curves will need to be connected in real time to maintain smoothness.
Has anyone had any success with rendering cursive fonts?
Cursive fonts work in the same way as non-cursive fonts do. The only thing is that the axis-aligned bounding boxes of neighboring glyphs might overlap. In theory, this can happen to any font - not only to cursive ones.
A glyph is not only characterized by its width and height. It also has additional information that are used for laying out text. In FreeType, these are bearings and advance distances (see the documentation). The advance distance tells you how much the text cursor will advance, i.e., where the next glyph will start. The bearing will tell you how much space you have to leave blank between the current text cursor and the actual glyph. For very skewed glyphs, this bearing might be negative, i.e., the glyph starts left of the cursor position. Similarly, the advance distance may be smaller than the glyph width. This allows neighboring glyphs to intertwine.
Btw, different APIs call these font metrics differently. E.g., DirectWrite calls them overhangs.
Effectively what you have to do is define a relationship between characters, and use visual variations of the same characters so that they appear linked.
For example, a cursive lowercase 'L' next to a cursive lowercase 'O' will link from the bottom of the L to the top of the O; whereas if the letter after the L was, let's say 'i', then it would have to link the characters at the bottom.
If you're intending on some predetermined text, then you can of course also just manually arrange things. If you're looking for a real-time solution, you would need the above method.
Take a loot at this page and perhaps some of the libraries found in the "implementations" section, which should point you in the direction of ready-to-use assets.
I'm using Pango for text layouting without the cairo backend (currently testing with the win32 backend). And I like to know if pango is capable of a flow layout around an image, or any given container. Or maybe inside a custom container.
Something like this: Flow around image
I have checked many examples and the Pango API and didn't found such a feature. Maybe I'm missing something or Pango does not have this feature.
As I said in this answer, you can't. I went through the source code Pango graphics handling is primitive to the point of uselessness. Unless there's been some major reworking in the past year, which the release notes don't indicate, it's probably the same now.
The image you provide as an example is only available as PDF at the moment which requires every line, word and glyph be hard-positioned on the page. While theoretically possible to check the alpha channel of the image to wrap the text around the actual image instead of the block it contains, this has not (to the best of my knowledge) ever been implemented in a dynamic output system.
Pango, specifically, cannot even open "holes" in the text for graphics to be added later and, at the code level, doesn't even have the concept of a multi-line cell - hence a line being the size of its largest component.
Your best bet is to look at WebKit for more complex displays. I, for one, have pretty much given up on Pango and it seems to be getting less popular.
I want to render Unicode characters in an application and I have a rough idea of how I can do that for standard latin characters with freetype. However for other languages that have different layouts and shaping I'm not sure how to go from a set of characters I get in a UTF-8 encoded string to:
Picking a suitable font to display the characters
Picking the right layout for the characters (LTR, RTL, TTB)
Is this data contained in the unicode characters themselves (I'm not sure how else applications like web browsers would figure out how to render text)?
For a given Unicode character, how can I determine points 1 and 2? Freetype has some great documentation and talks quite a bit about using different layouts, but I didn't see how you would go about extracting said information from the characters themselves.
I also took a quick look at Harfbuzz but couldn't really find any documentation. There's an example floating around that shows how to set up and use Harfbuzz to layout some languages with Freetype rendering the glyphs, but the example explicitly passes layout, font and language information to Harfbuzz.
What do you do when you don't know those things in advance?
This is for a mobile application, and ideally the libs/solutions used would have a permissive license.
The Unicode character code point only encodes the character
itself; it gives no information with regards to the font to use,
nor layout, nor in fact anything else. To get information
concerning layout, etc., Unicode provides a number of files,
such as UnicodeData.txt, which you can download and use. As
for the fonts, each font should provide descriptor files of some
sort, with things like the width, height and depth of each
character; these files can also be used to determine whch
characters the font supports.
I've read Rendering Vector Art on the GPU on rendering shapes that are defined by quadratic/cubic Bezier curve boundaries. I was hoping to build off of this to create text that fills in as if it were stroked by a pen or brush somehow. (Any advice on how to do this is welcome.)
However, I'm a little unsure of where to get my hands on fonts / shapes that have the format specified in this paper (arrays of points representing quadratic/cubic Beziers).
Does anyone know of a way of getting font/vector drawings that are in this format? The authors of the paper mention truetype fonts, but according to
TrueType Font Parsing in C
it looks like parsing truetype fonts might involve a lot more than this? I know there are also formats like .svg, but I am not sure where to start with that, since it holds so much more than what I am looking to get out of it.
As an example, is there some type of file format that I could convert a .svg file or truetype file to, perhaps by using something inkscape's export function, such that the resulting format would be possible to parse for an array of points and control points?
I accepted an answer below, but for anyone interested in this, you should check out
https://github.com/quarnster/TTF
It's pretty much exactly what I was looking for. The code works great, but it's a bit hard to understand how to use it. It makes more sense if you read about the TTF format, like here An Introduction to TrueType Fonts: A look inside the TTF format.
I suggest using the cross platform library FreeType (http://www.freetype.org/). FreeType loads font files and, among other things, provides the bounding curves of glyphs in the typeface. Specifically, you should look into the function FT_Outline_Decompose, which gives exactly what you want.