LineBreakMeasurer with anti-aliased text

Hello,
I am developing an application, which needs to render anti-aliased text. The application uses LineBreakMeasurer for text layout. Without anti-aliasing, LineBreakMeasurer works perfectly. However, when I turn anti-aliasing on, the text lines returned by LineBreakMeasurer.nextLayout() are too long (that is, longer than the specified wrapping width).
For example, if I call
TextLayout layout = measurer.nextLayout(92.0);
then
layout.getAdvance()
might return 101.0.
Has anybody been able to make LineBreakMeasurer to work with anti-aliased text?
Thanks,
-Tero

My english is not so good, I hope this help to you.
import javax.swing.*;
import java.awt.*;
import java.awt.font.*;
import java.awt.event.*;
import java.text.*;
public class ParagraphLayout extends JFrame{
  public static void main(String[] args) {
    JFrame f = new ParagraphLayout("ParagraphLayout");
    f.getContentPane().add(new Test());
    f.setVisible(true);
  public ParagraphLayout(String title) {
    super(title);
    createUI();
  protected void createUI() {
    setSize(500, 400);
    center();
    addWindowListener(new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        dispose();
        System.exit(0);
  public void center() {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Dimension frameSize = getSize();
    int x = (screenSize.width - frameSize.width) / 2;
    int y = (screenSize.height - frameSize.height) / 2;
    setLocation(x, y);
class Test extends JPanel{
       public Test(){
            super();
      public void update(Graphics g){
           paintComponent(g);
      public void paintComponent(Graphics g) {
        Graphics2D g2 = (Graphics2D)g;
        g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON);
        // From _One Hundred Years of Solitude_ by Gabriel Garcia Marquez.
        String s = "Jos\u00e9 Arcadio Buend\u00eda spent the long months " +
           "of the rainy season shut up in a small room that he " +
           "had built in the rear of the house so that no one " +
           "would disturb his experiments. Having completely abandoned " +
           "his domestic obligations, he spent entire nights in the " +
           "courtyard watching the course of the stars and he almost " +
           "contracted sunstroke from trying to establish an exact method " +
           "to ascertain noon. When he became an expert in the use and " +
           "manipulation of his instruments, he conceived a notion of " +
           "space that allowed him to navigate across unknown seas, " +
           "to visit uninhabited territories, and to establish " +
           "relations with splendid beings without having to leave " +
           "his study. That was the period in which he acquired the habit " +
           "of talking to himself, of walking through the house without " +
           "paying attention to anyone...";
        Font font = new Font("Serif", Font.PLAIN, 24);
        AttributedString as = new AttributedString(s);
        as.addAttribute(TextAttribute.FONT, font);
        AttributedCharacterIterator aci = as.getIterator();
        FontRenderContext frc = g2.getFontRenderContext();
        LineBreakMeasurer lbm = new LineBreakMeasurer(aci, frc);
        Insets insets = getInsets();
        float wrappingWidth = getSize().width - insets.left - insets.right;
        float x = insets.left;
        float y = insets.top;
        while (lbm.getPosition() < aci.getEndIndex()) {
          TextLayout textLayout = lbm.nextLayout(wrappingWidth);
          y += textLayout.getAscent();
          textLayout.draw(g2, x, y);
          y += textLayout.getDescent() + textLayout.getLeading();
          x = insets.left;
}

Similar Messages

  • Anti-aliased text when exporting PDF to image

    I need to be able to batch-convert multi-page PDFs to individual bitmap images (one image for each page) with anti-aliased text.
    Photoshop works this way if you open a single PDF, allowing you to select one or more pages to rasterize as separate images, but not when batch processing (specifically, if you use the Image Processor script on a folder of images and PDFs, it will rasterize the PDFs automatically, but it will only do so with the first page of each PDF.)
    Acrobat, on the other hand, automatically creates an image for each page when exporting, and can do this in a batch sequence, but the text is not anti-aliased, making the image look like a screenshot from 1997. No matter how high an image resolution you select, the text is still jagged when you zoom in.
    So, is there a setting I'm missing that will allow the text to be anti-aliased when using Acrobat to export PDF to an image? I am using Acrobat 8, not 9, so something might have changed in the newest version.

    Not sure about Acrobat Pro 8, but in Acrobat Pro 9 (not Extended) you can Export>Image>Multiple Choice: JPEG, JPEG2000, PNG, TIFF.  I used JPEG and under the options in the export dialog box, leave the filename as is to coincide with the PDF filename and then choose Maximum Resolution under File Settings: Grayscale (JPEG, Quality:Maximum); Color (JPEG, Quality:Maximum) . . . skip down to Conversion Colorspace: Determine Automatically and Resolution choose 600pixels/inch for a letter size document.  This will result in a file size of 1.3MB per JPEG image if there is not a lot of information on the page.  I chose a simple header, footer with page numbering, and 5 lines of Lorem Ipsum text.  600dpi is overkill, you can go for 300dpi and still result in a decent image that will be able to be printed on a laser photocopier that is connected to a production computer.  Obviously if you are printing to a laser printer or a high quality inkjet 300dpi will suffice as well for a letter sized document.  But I have been told that 300dpi is not a standard rule of thumb and you must obtain specs from your printer since he/she can calculate by very strict rules the dpi you need for your content.  It depends on whether you have background images such as watermarks and also if your text body contains line-art.

  • Is there a tiling window manager with anti-aliased fonts?

    Hi,
    Is there a tiling window manger with anti-aliased fonts?
    Thanks.
    Last edited by 9mqks5hn (2009-07-14 18:50:45)

    pauldonnelly wrote:
    cinan wrote:your font configuration has nothing to do with window manager. Hope this helps you http://wiki.archlinux.org/index.php/Xor … figuration
    Any text the window manager displays is rather affected.
    None come to mind here, but that doesn't mean much.
    You can use any panel/pager with XMonad if you use the ewmh hooks (these panels usually support anti-aliased fonts). There is a dzen2-xft version floating around the net somewhere if I'm not mistaken...

  • I am using the pen tool to clipp an image. Sometimes when I apply the mask WITH NO FEATHER it still appears to be feathered? Does this have to do with Anti-aliasing

    I am using the pen tool to clipp an image. Sometimes when I apply the mask WITH NO FEATHER it still appears to be feathered? Does this have to do with Anti-aliasing?

  • CS5 bug rendering anti-aliased text in 'Save for web'

    Seems like there's a bit of a bug when using 'Save for web and devices' with thin weights of type in CS5 for Mac. Although thin type looks fine while working in Illustrator, as soon as you enter the 'Save for web' dialogue, it gets badly mangled. Looks like this issue has been present at least since CS4. It does not happen in Photoshop. It looks particularly bad for light text on a dark background.
    Some people may say "sure, Illustrator is not really meant for intensive bitmap work". However, with features like 'pixel preview' and 'snap to pixel', Illustrator has (generally) become a very viable tool for web design, and personally I much prefer it to Photoshop. It is also clear that Adobe intends it to be usable in this manner. So the anti-aliasing render bug is definitely a problem. Just surprised they didn't address it when CS5 was born.
    I put up some example images on http://www.thesheep.co.uk/2011/06/24/illustrator-save-for-web-anti-aliasing-problems/ to illustrate the problem.
    Does anyone have any clever work-arounds for this? It's a bit annoying to have to move stuff over to PS before exporting, but maybe that's what I have to do. Hopefully Adobe will address this soon.

    Hi,
    I am experiencing this same problem of pixelated gifs when I use the "save for web" dialog from Illustrator, but this solution has not worked for me. I have tried the trick of using type-optimized anti-aliasing, but it doesn't change the output at all. I've done this from within the "Image size" tab as well as through Effect>Rasterize>Options)Anti-aliasing: Type Optimized. My image is a logo made entirely from text, although for some of it I used "outline path", so I'm not sure if it still qualifies as text...I'm a newbie at this stuff, so the technical details are still quite opaque to me.
    Does anyone know of a solution to this that does not require me to add Photoshop to my workflow?
    I'm using Illustrator in CS5, version 15.0.2.
    Thanks in advance
    Jonathan

  • How can I get anti-aliased text?

    I create my bitmap and Graphics2D object as follows:
    BufferedImage img = new BufferedImage(devExtX, devExtY, BufferedImage.TYPE_INT_ARGB);
    graphic = (Graphics2D) img.getGraphics();
    graphic.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    graphic.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    graphic.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    graphic.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    But text is drawn with no anti-aliasing (does that mean it is aliased <g>?).
    Any ideas what I am missing?
    thanks - dave

    Hi George,
    STXL: Long Text (Header - English)
    Extract all records where XTDOBJECT='AUFK' and XTDID='KOPF' and XTDSPRAS in ('E')
    XTDNAME is MANDT+AUFNR
    STXL: Long Text (Operations- English)
    Extract all records where XTDOBJECT='AUFK' and XTDID='AVOT' and XTDSPRAS in ('E')
    XTDNAME is MANDTAUFPLAPLZL
    STXL: Long Text (Components- English)
    Extract all records where XTDOBJECT='AUFK' and XTDID='MATK' and XTDSPRAS in ('E')
    XTDNAME is MANDTRSNUMRSPOS
    This may help you
    Babu

  • (Arial) Fonts turn into cyrillic with anti-aliasing 'none' (bug?)

    Hi, I've got this really strange problem here.
    When I'm typing 'ç' in a Photoshop I get a cyrillic 'H'. When I turn the anti-aliasing of the font into 'sharp' instead of 'none' for instance, it's back the ç again. This occurs with every key in the numeric row.
    I'm using an azerty keyboard and the ç is located on the 9-key,  This only happens with the default font 'Arial' (regular). I'm working with Photoshop CS3 (Master Collection) on a Mac OSX 1.5.6 (Leopard).

    You're welcome.   
    Undisclosed recipient wrote:
    Thrashing the preferences did the trick. I should make a habbit of this when things fall apart.
    Absolutely! It's the first thing I try when anything starts acting weird "suddenly".
    Undisclosed recipient wrote:
    I figured it was a russian H because the other letters on the numeric row were russian too (inverted R's and so on).
    Interesting.
    Incidentally, the я is not an inverted or flipped R but a uniquely Cyrillic letter which represents the diphthong YA, and its name in Russian is indeed "Ya".

  • Anti aliased text

    I'm thinking of reformatting all the text using anti alias
    option.
    This seems a sensible option, as I assume it makes the text
    look smoother.
    I like the appearence, but a reasonable number of people,
    didn't like it. Some said it made things look marginally blurry.
    What are your views. Do many of you use the anti alias
    feature. Currently I use Verdana font in my applications.

    I agree it's a mix between 'smoother' vs. 'blurry'. With some
    fonts, the
    'I' can look pretty thin and blurry especially. You may have
    better
    results with different fonts; so the first thing maybe to try
    is a
    variety of fonts showing A through Z set to antialias and see
    which
    looks best.
    Colors can matter too.
    I think I've found good results with something like black,
    bold,
    antialiased text on top of backgrounds that aren't too
    heavily
    contrasted (like maybe yellow instead of white?).
    Ensure the font you pick is a common one or you'll have to
    install it on
    the user's computer.
    I generally don't use antialiased fonts though...all depends
    how they
    look for a given project's design. They also take a bit more
    power to
    display so might want to avoid them for lower-end machine
    specs.
    Erik
    webacity wrote:
    > I'm thinking of reformatting all the text using anti
    alias option.
    Erik Lord
    http://www.capemedia.net
    Adobe Community Expert - eLearning
    http://www.adobe.com/communities/experts/
    http://www.awaretips.net -
    Authorware Tips!

  • Preview - anti aliasing and text in scanned pdf

    hello all,
    i have an issue with preview not anti aliasing text in pdf files.  to elaborate, take a pdf with text which is selectable and it appears jagged, not anti aliased as in pdfs with text which is treated as an image, i.e. not selectable.
    also, sometimes, when scrolling through pages in full screen, the following page has the text anti-aliased as the scroll animation is taking place, i.e. while the previous page is being moved away through the gesture, but once the previous page has disappeared and the new page 'settled in' the smoothing is gone.
    smooth text and line art is checked, as is lcd smoothing in general preferences.
    any suggestion are much appreciated.
    s.

    Hi 1ndivisible,
    Hmm, that's odd. My type is looking pretty decent out of Illustrator. Can you try a different font or the same font in a new sequence?
    Thanks,
    Kevin

  • Flash 9 Text Not Properly Anti-Aliased In Flash 10

    I use Flash CS3 to author .swfs for Flash Player 9. recently
    i noticed that Flash 10 is not displaying the anti-aliased text
    from Flash 9 content correctly.
    See image (link:
    http://i717.photobucket.com/albums/ww175/chunk1978/Picture3.png
    ). The above image is Flash 9 text playing in Flash 10. The bottom
    image is Flash 9 text playing in Flash 9. The removal of the fine
    coloring makes the text much sharper looking. It's not ideal,
    especially for smaller text of size 10 and below.
    Is there anyway i can create a Flash 10 file using Flash CS3?
    I've tried using the trial version of Flash CS4 to do this,
    but it really doesn't play nicely with my current CS3 project. LOTS
    of "missing fonts" as well as the working stage not rendering
    correctly in the program. I'd rather avoid CS4 all together as it
    seems littered with issues, and i'm in no position to start from
    scratch.
    any help would be very appreciated.

    Have you checked the font?
    Are they the same fonts in Word and Pages?
    Some applications maintain their own font folders.
    There is also a possibility of font clashes, a problem with OSX having dfonts, ttf and sometimes otf fonts all with the same name. OSX is a bit of a mess with font management (as well as color management).
    Peter

  • No anti-aliasing?

    I have read that the Text Engine introduced with Flash Player 10 is supposed to provide anti-aliasing for devide fonts (i.e. non-embedded fonts).  This is essential for Web applications: without anti-aliasing text looks awful and Flex applications cannot compete with HTML applications.  But fonts that include East-Asian characters cannot be embedded because they take up too much space.  And I don't see how a Web application in 2009 can fail to support East-Asian characters.
    Today I tried Flash Builder 4, and created 3 Spark components, of types RichEditableText, RichText, and SimpleText, without embedding any fonts.  All three could be rotated, which I believe means they use the new Text Engine.  But none of them had anti-aliasing (which I checked by looking at how they rendered capital letter W).  Why is this?  Do I have to do something special to get anti-aliasing?  Or is anti-aliaing a feature that will be coming later?
    Thanks in advance,
    Francisco

    Hi Corey,
    Thanks for your message.  I've looked more carefully at the device font I'm using on the Mac (with an LCD display).  You are right, it's anti-aliased.  (I can't see any subpixel colorations with my magnifying glass as I can see them on Windows, but maybe they are just less obvious.) 
    So the reason the device font looks ugly on the Mac must just be the letter spacing.  Since you said it looks good to you, I checked the code and did some experimentation.  It turns out that I'm saying fontFamily="_sans" and, surprisingly, in Flex 3, this it not the same as not assigning a value to fontFamily.  (Out of curiosity I checked Flex 4, and it is the same there.)  Saying fontFamily="_sans" causes the letter spacing to be way off.  If I don't say anything the spacing it still a bit off, but not too much, and the font does not look bad, although it still does not look as good as an embedded font.
    I tried taking screen shots, but they come out a little blurry and it's hard to judge fonts on them.  But I'm attaching a simple mxml file that compares the embedded font, the device font with no assignment to fontFamily, and the device font with fontFamily="_sans".
    If you want to see the huge difference that fonts make on the application, the best thing is to look at the application itself, so I should say what it is.  It's Noflail Search, a search engine that you can find at noflail.com.  It starts out using an embedded font, but if it encounters an East-Asian character, or you specifiy an East-Asian language restriction, or you turn on an IME for an East-Asian language, it switches to fontFamily="_sans" (and lets you know that it does).  To go back to the embedded font you can remove what caused the switch and reload the page.  So it's easy to compare the effect of the two fonts.
    The switching to the device font was my clumsy attempt at coping with the East-Asian character problem.  Unfortunately the switching happens fairly often, because East-Asian characters pop-up in results when you least expect it, even if the query has nothing to do with East-Asia.  So I will remove the "feature" soon, and just use device fonts and hope that most Windows users have ClearType enabled.  But I'll leave it on all day Monday in case you want to check out the effect of the fonts on the application.
    When I said that Adobe should not rely on embedded fonts I was referring to the fact that the nice anti-aliasing and text rendering that you have in Flex 3, and the presumably nicer one in Flex 4, is only available for embedded fonts.
    Btw I've been comparing the subpixel anti-aliasing that I get with ClearType and a device font on Windows to the embedded font, and the embedded font looks definitely better.  The device font with ClearType looks purplish, and the anti-aliasing does not seem as good.  So let me emphasize that I'm not arguing that Adobe should use subpixel anti-aliasing.  I'm arguing that the grey-scale anti-aliasing and text rendering that you use for embedded fonts should be used for device fonts as well.  Is there any technical reason that makes this difficult?  Impossible?
    Thanks for listening
    Francisco

  • Having an issue with font aliasing.

    I seem to be having a weird issue that I've never experienced before. My fonts appear to be aliased, both in Photoshop and Illustrator, even after applying anti-aliasing.
    Below is a screenshot of Helvetica Neue Ultralight at 9pt and 72pt, and Arial at 60 pt, all with anti-aliasing set to smooth. When I set anti-aliasing to other settings, it doesn't get any better. Turning it off makes it worse. The project is 300dpi (or ppi as photoshop says, wouldn't that technically make it 150dpi?)
    http://www.nikostoscani.com/images/textaliasing.png
    I am doing a business card design and read that it's actually to keep text aliased for print. Is this true? Should I not worry about it? It seems odd to me, because I've never experienced this before. It's the same way on both my Mac and PC, in both Illustrator and Photoshop.
    Any and all help would be much appreciated!
    EDIT: Even custom shapes appear to be aliased along some edges. I'm not sure what's going on.

    It could be your monitor's resolution setting.  Have you tried printing the fonts and shapes?  If so, are they pixelated in the print?  FYI, 300ppi does not mean 150dpi.  PPi is an image resolution, DPi is a print resolution.  Both are different but are often confused where consumers typically say dpi when they mean ppi ( not knowing the true differences between the two ).

  • Anti-Aliased Fonts : FF2 vs IE7

    I could have sworn Firefox was the first to come out with
    font
    anti-aliasing, for smoother text detail... then IE7 came out
    and followed
    suit, opening the door to fonts smaller than 10px looking
    smooth (for
    copyright notices and the like).
    However, as I compare both browsers today, I see IE7 has the
    anti-aliasing
    but FF2 doesn't. Yet my FF2 install is defaults-only, so I
    can't imagine I'd
    have turned anti-aliased fonts off.
    What happened? Did I imagine the whole thing, where FF came
    out with
    anti-aliased fonts first? Or did they try it and change their
    minds in a
    future update? Am I losing my mind?
    Thanks.

    "darrel" <[email protected]> wrote in message
    news:fcmoav$b5u$[email protected]..
    >> Darrel, anti-aliasing is not hacking. It's not a
    short-cut, a cheat, or a
    >> crutch. Those magazines you read that make millions
    of dollars and can
    >> afford the best printing equipment out there ALSO
    use anti-aliasing on
    >> their fonts. Time magazine, Entertainment Weekly,
    Rolling Stone... none
    >> of those fonts are anti-alias-free.
    >
    > Anti-aliasing is a screen concept. Nothing to do with
    printed type.
    I've printed both anti-aliased and non-anti-aliased fonts at
    300dpi, and I
    see a difference. In fact, there are several levels of
    anti-aliasing, from
    crisp to smooth.
    Why are we even having this discussion? It's quickly turning
    ugly.
    > And it's a hack to get around the inherit low resolution
    that is a
    > computer screen (compared to print).
    It's being used as such on screens, yes. But it's not its
    sole and only
    purpose.
    >> It is simply inconcievable to imaging a resolution
    SO HIGH that the human
    >> eye won't be able to distinguish between 2-tone and
    anti-aliased fonts.
    >
    > That's exactly what a basic laserprinter gives you.
    >
    >> I mean it would have to be a million dots per
    inches.
    >
    > Nah...anything above 300 dpi is fine.
    See above answer about being able to visually see the
    difference between
    anti-aliased and non-anti-aliased fonts at 300dpi.
    What you can say is that YOU don't see it, but please don't
    project that
    limitation on all of us. ;-)
    >>>> Not for a mere copyright notice or other
    fine print! (They call it that
    >>>> for a reason :-)
    >>>
    >>> If you are purposely making it illegible, than
    what's it matter if it's
    >>> smooth or not?
    >>
    >> Same reason it's small but smooth on print mediums.
    >
    > So it looks good under a magnifying glass? ;o)
    Please stop trolling me. :-P
    And on that note, I'll let you have the last reply. No
    offense intended
    whatsoever, but I've learned to spot a coming flamefest from
    a mile out, and
    I'm just too old for them now. ;-)

  • Paths being anti-aliased

    Hello,
    I've got a project with a lot of artwork in paths.  It was created in illustrator run through catalyst.  The artwork was all fine until I added some RichText on the screen next to the art in Flash Builder.  Now the art is all anti-aliasing making the fine lines look very fuzzy.  Can anyone tell me how to turn anti-aliasing off for the entire project?  I've confirmed that its the RichText that is doing it because if I comment it out it goes back to aliased lines in all the paths.
    Thanks for any help,
    Paul

    Check out the section "Anti-Aliased Text' toward the bottom of this article:
    Intermediate Images
    http://java.sun.com/developer/technicalArticles/Media/intimages/

  • The images in Photoshop or InDesign improperly anti-aliased, looking fuzzy

    I've bought Late 2013 Retina Macbook Pro with Mac OS Mavericks, and am having trouble with anti-aliasing.
    In short, the images/documents open in Photoshop or InDesign are improperly anti-aliased and look fuzzy.
    I can understand why the menu bars and stuff should appear fuzzy and blurry as a result of auto anti-aliasing; otherwise they might appear too small for eyes to see since the resolution is super high.
    But why should the machine want to blow up the images or documents inside the application and apply anti-aliasing to make them look so fuzzy?
    It would be grateful if there's a way to stop my computer doing the anti-aliasing all the stuff on screen.

    No, not that I know of - you do need to make certain that you're using the very latest versions of both apps, though.
    Clinton

Maybe you are looking for

  • I cannot click on a subject in the google drop down box to search without typing it in. Never happened before with the Google bar.

    clicking on a subject in the Google drop down box does not begin a search unless I type subject matter in the box first.

  • ID3 Tags wiped out....help !!

    Having imported my music library and converted ID3 tags to version 2.4, when I view the files in Windows Explorer all the tag information has been deleted. This problem stays even when files are converted to AAC format (also, rather than AAC the file

  • TS3899 Problem with icloud

    Hi all, Last year i have purchased an iphone 5s and my icloud has been created linked with my company mail. However i have forgotten my password and try to reset it. I have put the new password and it works when i try to login on the apple website wi

  • Can't sync music to my iphone 5

    after making changes to my playlist, I synched my iphone 5, but it wiped off all the music.  Now it wont sync my playlists to my phone.  I have tried resetting phone to factory settings, and have deleted and reinstalled itunes on my laptop, but still

  • Sun Studio creator & Liferay

    Hai All I need a help badly as i'm working with Sun Studio Creator,Liferay,Tomcat 5.5,SQL Server When i deploy my portlet to Liferay It Works fine but if i'm trying to gothrough the tabs its getting error can anyone help me Thanks