Re: embedding fonts in webpages with groovy - No Fluff Just Stuff

Re: embedding fonts in webpages with groovy

Posted by: Andres Almiray on January 9, 2008

René Ghosh recently wrote about Embedding fonts in webpages with Groovy, and though he did a great job I couldn't help to think that perhaps a little builder magic may be in order.

The first thing would be to let GraphicsBuilder render the text, or any GraphicsOperation for that matter, to an offscreen image, an option that it didn't have before today but is very easy to accomplish, as shown in the following example

GraphicsRenderer will create a BufferedImage of the appropriate dimensions if you do not define one, it will also clip it if you do not do so :-) and there are other options that can be configured.

The second part of the builder equation is MarkupBuilder, but as René kindly answered back, his code embeds the produced images using a quick set of methods that do not belong to MarkupBuilder, that is why he went with the option of using a GString. Here we may have 3 alternatives:
  1. Extend MarkupBuilder and plug in the custom methods. This requires getting a hold of MarkupBuilder internals.
  2. Extend MArkupBuilder via ExpandoMetaClass. It also requires knowing about MarkupBuilder internals and ExpandoMetaClass, but you save on making a subclass.
  3. Plug in a factory into MarkupBuilder. Sadly this is a no go, as MarkupBuilder does not extend FactoryBuilderSupport, but it would be nice if it did.
Because of that I've been toying with the idea of a XMarkupBuilder, its almost finished now but there are still some rough edges that need to be smoothed. Before ending this I must say that is great to be able to share these and other ideas with James and receive quick feedback.

Keep on Groovying!
Andres Almiray

About Andres Almiray

Andres is a Java/Groovy developer and a Java Champion with more than 20 years of experience in software design and development. He has been involved in web and desktop application development since the early days of Java. Andres is a true believer in open source and has participated on popular projects like Groovy, Griffon, and DbUnit, as well as starting his own projects (Json-lib, EZMorph, GraphicsBuilder, JideBuilder). Founding member of the Griffon framework and Hackergarten community event. https://ch.linkedin.com/in/aalmiray

Why Attend the NFJS Tour?

  • » Cutting-Edge Technologies
  • » Agile Practices
  • » Peer Exchange

Current Topics:

  • Languages on the JVM: Scala, Groovy, Clojure
  • Enterprise Java
  • Core Java, Java 8
  • Agility
  • Testing: Geb, Spock, Easyb
  • REST
  • NoSQL: MongoDB, Cassandra
  • Hadoop
  • Spring 4
  • Cloud
  • Automation Tools: Gradle, Git, Jenkins, Sonar
  • HTML5, CSS3, AngularJS, jQuery, Usability
  • Mobile Apps - iPhone and Android
  • More...
Learn More »