This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] text layout implementation


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 ();
+            ci.next ();
+          }

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)
    {
      buf.append(c);
      ci.next();
    }

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, brawer@dandelis.ch, http://www.dandelis.ch/people/brawer/ 



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]