[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] text layout implementation

From: Sascha Brawer
Subject: Re: [PATCH] text layout implementation
Date: Wed, 19 Nov 2003 18:01:38 +0100

Hi Graydon,

>this patch implements simple awt text layouts using attributed strings
>and j2d glyph vectors. it will probably need further work, but it is
>enough to get the swing text system limping along.

+        String run = new String();
+        while (ci.current () != CharacterIterator.DONE && 
+               ci.getIndex() < limit)
+          {
+            run += ci.current ();
+   ();
+          }

Actually, this seems a bit inefficient. Won't the "+=" statement allocate
a new StringBuffer and a new String, plus copy everything around, for
each single character?

  char c;
  StringBuffer buf;

  buf = new StringBuffer(); // can you somehow determine the size?
  while ((c = ci.current ()) != CharacterIterator.DONE && 
         ci.getIndex() < limit)

But why do you need to create the string at all? Could't you set up a
CharacterIterator so it points to a single font run, and use the method
java.awt.Font.createGlyphVector(FontRenderContext, CharacterIterator)?
This should be much more efficient, because you'd save all those object
allocations. A local class could implement CharacterIterator, but also
have setter methods (or accessible fields), so only a single instance
needs to be allocated.

Also, does the proposed implementation work if there are changes in any
attributes other than font, such as TextAttribute.UNDERLINE? It seems
that all these attributes are lost by passing Strings.

Please don't feel offended if I'm a bit picky here; I'm just trying to
ensure that we have efficient and good code.

-- Sascha

Sascha Brawer, address@hidden, 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]