CSS3の縦書きを試していたところ、ルビの位置がずれることに気づいた。正常な位置より1文字分ほど上からルビがふられてしまう。
現象を確認したのは「Chrome 14.0.835.163 m」
おそらくChromeのバグと思われる。
参考にしていたページでは正常に表示できているので、色々実験して調べてみたところ
scriptタグの有無で表示位置が変わってしまうことがわかった。
scriptタグは完全な空でなければなんでもよく、空白なり改行があればルビは正常に表示された。
もしルビの位置がずれて困っている人がいたら、headタグ内に下記のコードを入れたら治るかも知れない。

<script language="Javascript">
</script>

正常に表示されるサンプル

対象:Processing1.5.1
環境:Windows7 64bit, Eclipse3.7

1. ワークスペースの切り替えを行いProcessingのソースのルートを指定する。
2.「android」以外のプロジェクトをインポート
3.「core」プロジェクトを「processing-core」に名称変更。(プロジェクトを選択してShift+Alt+R)
4.ApacheAntを参照しているプロジェクトはEclipse3.7のplugins/antのディレクトリ/lib/ant.jarを指定する。参照エラーになっているライブラリは削除。
5.ソースはUTF-8なのでプロジェクトの設定からテキストのエンコーディングをUTF-8に変更
6.「com.sun.jdi」の解決ができていない場合はJDKのlibにあるtools.jarをライブラリに追加
7.coreとappのbuild.xmlを実行
8.バイナリ版のパッケージに入っている lib/preference.txt lib/version.txt と models を core のフォルダに追加
9.ワークスペースにあるjavascriptをmodelsに追加
10. processing.app.Baseを実行

以上

scalaでxmlのタグを置換したりする時に使うBasicTransformerにバグがあるようで、何度も同じタグに
対する置換処理が走ってしまうようです。既にバグの報告がされていて、パッチも投稿されていました。

http://lampsvn.epfl.ch/trac/scala/ticket/3689

投稿されているパッチを使ってみたところ、特定のパターンでやはり同じタグの置換処理が走る場合が
あって、さらに修正を施す必要がありました。
結果、できたものが下記のコードです。うまくオーバーライドとかでできればよかったのですが、だめだったので
BasicTransformerをコピってtransformメソッドを書き換えました。

class BugFixedBasicTransformer {
    /**
   *  @param n  ...
   *  @param ns ...
   *  @return   ...
   */
  protected def unchanged(n: Node, ns: Seq[Node]) =
    ns.length == 1 && (ns.head == n)

  /** Call transform(Node) for each node in ns, append results
   *  to NodeBuffer.
   */
  def transform(it: Iterator[Node], nb: NodeBuffer): Seq[Node] =
    it.foldLeft(nb)(_ ++= transform(_)).toSeq

  /** Call transform(Node) to each node in ns, yield ns if nothing changes,
   *  otherwise a new sequence of concatenated results.
   */
//  def transform(ns: Seq[Node]): Seq[Node] = {
//    val (xs1, xs2) = ns span (n => unchanged(n, transform(n)))
//
//    if (xs2.isEmpty) ns
//    else xs1 ++ transform(xs2.head) ++ transform(xs2.tail)
//  }

  def transform(n: Node): Seq[Node] = {
    if (n.doTransform) n match {
      case Group(xs)  => Group(transform(xs)) // un-group the hack Group tag
      case _          =>
        val ch = n.child
        val nch = transform(ch)

        if (ch eq nch) n
        else           Elem(n.prefix, n.label, n.attributes, n.scope, nch: _*)
    }
    else n
  }

  def apply(n: Node): Node = {
    val seq = transform(n)
    if (seq.length > 1)
      throw new UnsupportedOperationException("transform must return single node for root");
    else seq.head
  }

  def transform(ns: Seq[Node]): Seq[Node] = {
    val xs = ns.toStream map transform
    val (xs1, xs2) = xs zip ns span { case (x, n) => unchanged(n, x) }

    if (xs2.isEmpty) ns
    else {
      (xs1 map (_._2)) ++ transform(xs2.head._1) ++ transform(ns drop (xs1.length + 1))
    }
  }
}

class BugFixedRuleTransformer(val rules: BugFixedRewriteRule*) extends BugFixedBasicTransformer {
  override def transform(n: Node): Seq[Node] =
    rules.foldLeft(super.transform(n)) { (res, rule) => rule transform res }
}

abstract class BugFixedRewriteRule extends BugFixedBasicTransformer {
  /** a name for this rewrite rule */
  val name = this.toString()
  override def transform(ns: Seq[Node]): Seq[Node] = super.transform(ns)
  override def transform(n: Node): Seq[Node] = n
}

Scalaにはクロージャがあるので当然ローンパターンを使用できるが、戻り値の型をパラメータ化しておくと、より便利になる。
例えば下記のように書くと、access()に渡したクロージャの結果をaccess()の結果として取得できるようになる。


def access[T](f:(java.sql.Connection)=>T):T = {
	val conn = openConnection()
	try {
		f(conn)
	} finally {
		conn.close()
	}
}

scalaで特定のXMLタグの置換を行うには、標準ライブラリのRewriteRuleとRuleTransformerを利用できる。
RewriteRuleに置換ルールを記述し、RuleTransformerでRewriteRuleに基づいて置換処理を行う。

下記のXMLのreplacementタグを属性nameの値に応じて置換をしたいとする。

val node = <template><replacement name="key"/></template>

まず、RewriteRuleを継承して、置換ルールを作成する。

import scala.xml._
import scala.xml.transform._

class ReplacementTagRewriteRule(params:Map[String,String]) extends RewriteRule {
	override def transform(node:Node): Seq[Node] = node match {
		case e @ Elem(_,"replacement",_,_,_*) =>
			new Text(params.get(e.attribute("name").get.toString).get)
		case other => other
	}
}

RuleTransformerを使って置換処理を実行する。RuleTransformerは関数オブジェクトなので括弧で適用できる。

new RuleTransformer(new ReplacementTagRewriteRule(Map("key"-> "abc")))(node)

結果は

<template>abc</template>

となる。