さて、以下の作品。なぜそれを実装しなければならなかったのかまだわかりませんが、これは機能します...
package com.lomda.ong2;
import java.util.HashMap;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.FontMetricsInt;
import android.graphics.Typeface;
import android.graphics.Paint.Align;
import android.graphics.Paint.FontMetrics;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.Log;
// render Hebrew strings with diacritic marks
//
public class HebRender {
Paint paint;
HashMap<String, Integer> spaces;
String charString;
String prevChar = "";
final String TAG = "HebRender";
public HebRender(Context svContext){
paint = new Paint();
Typeface t = Typeface.createFromAsset(svContext.getAssets(),"fonts/SimpleCLM-Bold.ttf");
//Typeface t = Typeface.createFromAsset(svContext.getAssets(),"fonts/gisha.ttf");
paint.setTypeface(t);
paint.setStyle(Paint.Style.FILL);
paint.setTextSize(48);
paint.setAntiAlias(true);
paint.setTypeface(Typeface.DEFAULT_BOLD);
paint.setTextAlign(Align.CENTER);
}
public void drawText( Canvas canvas, String word, Point locate, int color) {
Rect bounds = new Rect();
Rect prevBounds = new Rect(0,0,0,0);
paint.getTextBounds(word, 0, word.length(), bounds);
paint.setColor(color);
int wordWidth = bounds.width();
// move to right edge (parameter is center)
locate.x += wordWidth/2;
// initialize bounds of individual characters
bounds = new Rect(0,0,0,0);
// for each character
for (int i = 0; i < word.length(); i++) {
// locate and write letter
char c = word.charAt(i);
charString = String.valueOf(c);
if (c >= 1488 && c <=1514) {// is in consonant range
paint.getTextBounds(charString, 0, charString.length(), bounds); // get current char dimensions
if (!prevChar.equals("")) {
int moveOver = bounds.width()/2 + prevBounds.width()/2 + (int) paint.getTextSize()/10;
locate.x -= moveOver;
}
Log.d(TAG, String.format("Char: %s, Prev char width: %d, char width: %d", charString, prevBounds.width(), bounds.width()));
canvas.drawText(charString, locate.x, locate.y, paint);
prevChar = charString;
prevBounds.set(bounds); // save previous dimensions
} else {// for each diacritic locate and write
canvas.drawText(charString, locate.x + getOffset(c, bounds.width()), locate.y, paint);
}
}
}
// some diacritic marks need to be moved
private int getOffset(char c, int charWidth) {
int offset = 0;
switch (c){
case 0x05C1: // shin dot
offset = charWidth/2;
break;
case 0x05C2: // sin dot
offset = -charWidth/2;
break;
case 0x05BC: // dagesh
offset = findDagesh(c, charWidth);
break;
case 0x05B9: // holam
offset = -(3*charWidth/5);
break;
}
return offset;
}
// move dagesh around for certain characters
private int findDagesh(char c, int charWidth) {
int offset = 0;
if (prevChar.equals("ג")) {
offset = Math.min(2, -charWidth/3);
} else if (prevChar.equals("ו") ||prevChar.equals("ז") || prevChar.equals("י")){
offset = Math.min(7, -7*charWidth/10);
} else if (prevChar.equals("ע") || prevChar.equals("ש") ) {
offset = Math.max(1, charWidth/3);
} else if (prevChar.equals("פ")){
offset = Math.max(2, charWidth/3);
}
return offset;
}
}