EzDevInfo.com

kerning.js

Take control of your web typography. Kerning.js

How to adjust text kerning in Android TextView?

Is there a way to adjust the spacing between characters in an Android TextView? I believe this is typically called "kerning".

I'm aware of the android:textScaleX attribute, but that compresses the characters along with the spacing.


Source: (StackOverflow)

.NET library for typesetting documents (PDF or similar)?

EDIT: Better explanation: Before setting a bounty for this question I want to state clearer what I need:

I need .NET library for generating printable documents. Users should be able to print exactly the same document that they see either using my application or using external tool (like Adobe Acrobat reader). It does not have to be library for generating PDF documents, any document format that satisfies above condition will do.

I need the library to support following scenarios:

Scenario 1:

  1. I create text in some font and color.
  2. I ask the library for the width if this text if printed.
  3. I compute position([X,Y] coordinates on page) of this text based on information from 2. and have the library to print in at this position on a page.

Scenario 2:

  1. I create a text with some parts of it in superscript. All parts of text (normal and superscript) are in same (but variable) font.
  2. I ask the library what is the width if this text when printed. I get correct answer that also takes kerning between normal text and superscript into account.
  3. I compute position([X,Y] coordinates) on a page where this text should be printed (using its width from step 2.). I let the library to print it at this position. Printed on the page it has exactly the width that was returned by library in previous step.

Note for second scenario: I have text with some parts in superscript - example AAA{v-superscript text}BBB (where text in {} braces is superscript). The library needs to be able to print this text using correct kerning. Without right kerning there will be the same gap between last A and first superscript v as between last superscript t and first B. For the user it will look like there is a space between A and superscript v but no space after the last superscript letter. So the text will look ugly. If the library is to handle this correctly it would have method to print the whole text AAA{v-superscript text}BBB at once with specification that a part of it is in superscript. Then it would use correct kerning between normal text and superscript.

Scenario 3:

  1. I want to print picture that consists of lines, circles, filled circles, letters and bezier curves on exact point in a page. I need to specify width of lines and circles. All shapes needs to be printed in pixel precision.

The library should be free of charge and not GPL (LGPL is ok). Is there something that allows me to do what I need ? Can it be done with iTextSharp (version 4.1.6 that is LGPL not AGPL)? Or perhaps with Fixed document ? Thank you for any suggestions.


Original question:

I need to typeset complex documents in .NET (C#) application for the user. Primary use of those documents will be for printing.

Documents will contain text and simple generated graphics. Layout of text and graphic will be complex and needs to be computed (in another words text position in document needs to be controlled by my code, it will not be done automatically by chosen library).

Here are my API requirements:

  1. function that returns exact width for given string and given font in which text should appear
  2. ability to position text to exact position on the page
  3. have text with some part of it in super script
  4. function to get exact width of some text that has some part of it in superscript
  5. ability to add pictures or even better option to draw simple graphics (line of given thickness, filled circle of given radius/diameter)

It does not have to be library for creating PDF documents - any other "what you see is what will be printed" document format will also do. If there is WPF component that can displays such documents it is an advantage. I know there is iTextSharp but is not easy to achieve 4. requirement with iTextSharp. Of course some PDF generation library that satisfies requirements above will be great solution too.

Thank you for ANY suggestions, I'm also happy to provide details or clearer explanation.


Source: (StackOverflow)

Advertisements

Letter Spacing in EditText for Android

I am trying to have a custom EditText based on the background that i am using for. The Background image has some spaces between the entry areas so i need to have some space between the characters(kerning) to fit them right in. So for example after every character the user enters, i need to put 4 whitespace after that.

I couldn't find any solution for this on the net so far, some people suggested TextWatcher, but i couldn't manage to make it work as i want it too.

Can someone help me about it?

Thanks


Source: (StackOverflow)

Kerning problems when drawing text character by character

I'm trying to draw strings character by character to add lighting effects to shapes composed of text.

while (i != line.length()) {
c = line.substring(i, i + 1);

cWidth = g.getFontMetrics().stringWidth(c);

g.drawString(c, xx += cWidth, yy);
i++;
}

The problem is, the width of a character isn't the actual distance it's drawn from another character when those two characters are printed as a string. Is there any way to get the correct distance in graphics2d?


Source: (StackOverflow)

.ttf kerning in iOS: how read kerning info?

I use custom font in iOS application (cocos2d, OpenGL) and there is no kerning. Font already have kerning info (on my Mac in TextEdit and Pages kerning pairs looks fine), but when I use this font in application — kerning don't apply. Is there some way to use kerning pairs with custom .ttf font in iOS application?


Source: (StackOverflow)

Most performant way to draw text on a curve, and animate it?

I'm guessing that it's to make a string out of individual CATextLayers and then position them as required along the curve, then animate. Because that's what's I've got working now, but it loses Kerning. Here's how:

Why isn't my curved text centering itself?

But is Core Text more performant and able to avoid the whole "drawing into a context" nonsense that slows everything down compared to the lean, mean Core Animation way of doing things, and respect kerning? i.e. avoiding drawRect: and all other aspects that greatly slow things down, as in this manner of drawing to the screen:

https://github.com/darcyliu/CocoaSampleCode/tree/master/CoreTextArcCocoa

Imagine a string of 200 characters, bent around a circle, with the ability to animate the spacing between characters, hopefully at a stable 60fps. This is possible with Core Animation, but that's by breaking the string up into individual characters and placing them around the circle with equal spacing, which causes a complete loss of kerning information.

I'm hoping for a way to do this without losing the kerning information and still being able to dynamically adjust spacing at 60fps.


Source: (StackOverflow)

Uniscribe Kerning

At work, I have been tasked with improving the text rendering of our application to better support text character kerning. Our application generates images that appear on Television, so image quality is paramount. Therefore, even small improvements to the appearance of any output we generate is very useful.

Our current text engine is implemented using Uniscribe, which seems to be an ideal solution. As mentioned here, it supports ligature substitution in a context aware fashion with complex scripts. It also handles right-to-left languages, and BiDi. This is all important as we need to be able to render arabic/cursive languages perfectly.

It therefore seems rather peculiar that Uniscribe doesn't appear to output glyph kerning information. I have attached a screenshot to demonstrate the issue.

alt text

My app performs the same as notepad in that every glyph appears 'monospaced'. Notice how in Photoshop CS2, the bridge at the top of the 'T' nicely overhangs the 'e'. I want to recreate this.

I am aware of other APIs such as Pango/Freetype - but it seems a rather heavyweight solution to include all of that just to do the final 1% of this task, if Uniscribe is so great at everything else.

Am I missing a step using Uniscribe? What is the best solution to this? Can Freetype export kerning information in a lightweight fashion, so that I can integrate it with the existing Uniscribe solution?

N.b. We only need to run on Windows - platform portability is thankfully not an issue I need to worry about right now.

Cheers in advance !


Source: (StackOverflow)

Apache FOP, custom fonts, kerning?

I've just used Apache FOP to produce a PDF/X photobook to be submitted to a photo print service. Everything seems fine, but kerning. With a custom serif font, e.g. the word "portfolio" isn't properly rendered (the problem lies with f-o, as o should be rendered under f's "head"). Installing the same font under Mac OS X, for instance, and trying TextEdit, the word is correctly rendered.

This is how I configured fonts:

            <font metrics-url="Muli/Muli-Light.xml"  
                  kerning="yes" 
                  embed-url="Muli/Muli-Light.ttf">
                <font-triplet name="Muli" style="normal" weight="300"/>
            </font>

where the XML file has been achieved by processing the TTF font as per FOP documentation. The file contains kerning pairs, that it's what should be needed AFAIK.

What am I missing? I'm using FOP 1.0.


Source: (StackOverflow)

Android Font Kerning: Nexus 7 vs. Galaxy Tab 2

I'm currently developing an application that was originally meant to be run solely on Nexus 7 and Android 4.2. However, there was a change of plans and now it is meant to run on the Galaxy Tab 2, Android 4.1.1 instead.

I am using a custom font that rendered great on the Nexus 7. However, when downgrading the version of Android and switching to the Galaxy Tab 2, the font kerning got completely messed up and looks terrible. Spacing is way off from what it should be.

Any tips to point me in the right direction for fixing this issue? I don't have the slightest idea how to fix this, except for switching to a different font, which is less than ideal.


Source: (StackOverflow)

iOS 7 Applying kerning and line spacing to text

I have the following code which works flawlessly in iOS 6, problem is it has no effect whatsoever in iOS 7. How do I apply kerning and line spacing in iOS 7?

+ (NSAttributedString *)attributedText:(NSString *)text inFont:(UIFont *)font {
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text];

    NSMutableParagraphStyle *style = [NSMutableParagraphStyle new];
    style.lineSpacing = 5;
    CGFloat kernSize = -0.6;
    [attributedString addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
    [attributedString addAttribute:NSKernAttributeName value:@(kernSize) range:NSMakeRange(0, text.length)];

    return attributedString;
}

Source: (StackOverflow)

Obtaining kerning information

How can I obtain kerning information for GDI to then use in GetKerningPairs? The documentation states that

The number of pairs in the lpkrnpair array. If the font has more than nNumPairs kerning pairs, the function returns an error.

However, I do not know how many pairs to pass in, and I don't see a way to query for it.

EDIT #2

Here is my fill application that I have also tried, this is always producing 0 for any font for the number of pairs. GetLastError will always return 0 also.

#include <windows.h>
#include <Gdiplus.h>
#include <iostream>

using namespace std;
using namespace Gdiplus;

int main(void)
{
    GdiplusStartupInput gdiplusStartupInput;
    ULONG_PTR           gdiplusToken;
    GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

    Font* myFont = new Font(L"Times New Roman", 12);
    Bitmap* bitmap = new Bitmap(256, 256, PixelFormat32bppARGB);
    Graphics* g = new Graphics(bitmap);

    //HDC hdc = g->GetHDC();
    HDC hdc = GetDC(NULL);
    SelectObject(hdc, myFont->Clone());
    DWORD numberOfKerningPairs = GetKerningPairs(hdc, INT_MAX, NULL );

    cout << GetLastError() << endl;
    cout << numberOfKerningPairs << endl;

    GdiplusShutdown(gdiplusToken);

    return 0;
}

EDIT I tried to do the following, however, it still gave me 0.

Font* myFont = new Font(L"Times New Roman", 10);
Bitmap* bitmap = new Bitmap(256, 256, PixelFormat32bppARGB);
Graphics* g = new Graphics(bitmap);

SelectObject(g->GetHDC(), myFont);
//DWORD numberOfKerningPairs = GetKerningPairs( g->GetHDC(), -1, NULL );
DWORD numberOfKerningPairs = GetKerningPairs( g->GetHDC(), INT_MAX, NULL );

Source: (StackOverflow)

Modifying the kerning in System.Drawing.Graphics.DrawString()

I'm rendering text onto an image using the System.Drawing.Graphics class, and the DrawString() method.

I need to generate the text for this image in a very specific way so that it exactly - pixel for pixel - matches an existing image.

The problem is that the text generated by DrawString() has a different kerning to the text in the existing image (my best guess is approximately 0.5 - 1 pixel per letter).

Can anyone tell me if it's possible to modify the kerning while using this namespace and method?

Also, it's a custom font that we're using and we had to convert this from open-type (which the source image used) to true-type. Might the kerning have been modified at this stage?


Source: (StackOverflow)

Qt kerning issue

In my application I'm using a QTextEdit to display some text, using HTML for formatting. The displayed document can be printed. And here's the issue: while on screen the kerning is correct, when printed the document has a very bad looking (mainly: too much space after some letters).

Trying to understand the problem I output the HTML in an external file, and tested it in real browsers. In Chrome there's exactly the same issue, while in Firefox the kerning is correct for printing too. The problem comes definitely from the HTML rendering engine, but I'm not using the QtWebkit module (I haven't even compiled it) which would have explained that the same problem occurs in Chrome.

How can I fix this ?

EDIT

Here's what it looks like:

First the text as it should be rendered (Firefox): kerning with Firefox

Then what is rendered with Qt/Chrome (particulary noticeable after the M and the p): kerning with Qt/Chrome


Source: (StackOverflow)

Accessing font kerning information in Java2D

Little background..

I'm in the process of making an OpenGL game using Java and LWJGL. I've written a TextRenderer-class that renders text using cached pages of glyphs. The glyphs itself are rendered in Java2D to BufferedImages and packed into texture pages along with the glyph measurements. TextRenderer draws the characters as textured quads, using the cached information.

All this works well, except for one thing: missing kerning. Granted, it's not necessary to have as the text looks fine as it is, but it would improve the quality if I had access to the font kerning information.

And the question is..

Is it possible to obtain the kerning information using plain Java, in a way that would be portable across Windows, Linux and MacOS X? Back when I wrote the TextRenderer I briefly looked around but could not find such a way..

One possible solution

If there is no way of doing this in pure Java, I was thinking of writing a separate tool using Freetype. As listed in their features page:

FreeType 2 provides information that is often not available from other similar font engines, like kerning distances, glyph names, vertical metrics, etc.

The tool would store the kerning pairs for common characters into a file that my text renderer would load in and make use of. So this is probably what I will do if you guys don't come up with a better alternative. :)


Source: (StackOverflow)

How can I specify letter spacing or kerning, in a WPF TextBox?

I'd like to modify the spacing between characters in a WPF TextBox.
Something like the letter-spacing: 5px thing that is available in CSS.
I think it is possible in XAML; what's the simplest way?

I found the "Introduction to the GlyphRun Object and Glyphs Element" document, and found it to be exceedingly unhelpful.

This is a code example from that page:

<!-- "Hello World!" with explicit character widths for proportional font -->
<Glyphs 
   FontUri             = "C:\WINDOWS\Fonts\ARIAL.TTF"
   FontRenderingEmSize = "36"
   UnicodeString       = "Hello World!"
   Indices             = ",80;,80;,80;,80;,80;,80;,80;,80;,80;,80;,80"
   Fill                = "Maroon"
   OriginX             = "50"
   OriginY             = "225"
/>

The same documentation page gives this "explanation" for what the Indices property does:

enter image description here

I have no idea what any of that means. I'm also not sure that Indices is the right thing - the comment in the code speaks of "character widths" which I don't care about. I want to adjust the width between characters.

Also, there is no example for how to apply a Glyphs element to a TextBox. When I tried it, my WPF test app just crashed.


What I want to do is slightly increase the empty space that appears between drawn characters within a WPF TextBox. The text will vary in length and content. Do I have to modify the Indicies property every time there is a new character? Is there a way to say "make it 20% more space than usual, for every character".

Can anybody help me?


Source: (StackOverflow)