Rectangle2D rect = font.getStringBounds(text, context);
int TEXT_TRACK_WIDTH = (int)rect.getWidth();
int TEXT_TRACK_HEIGHT = (int)rect.getHeight();
temp = null;
tempF = null;
QDRect textBox = new QDRect(0, 0, TEXT_TRACK_WIDTH, TEXT_TRACK_HEIGHT);
// add text track
Track textTrack;
try
{
textTrack = movie.addTrack(TEXT_TRACK_WIDTH, TEXT_TRACK_HEIGHT, 0);
Media textMedia = new TextMedia(textTrack, movie.getTimeScale());
TextMediaHandler handler = (TextMediaHandler)textMedia.getHandler();
textMedia.beginEdits();
byte[] msgBytes = text.getBytes();
QTPointer msgPoint = new QTPointer(msgBytes);
handler.addTextSample(msgPoint, QDFont.getFNum(fontName), fontSize, style,
new QDColor(fgColor[0] / 255f, fgColor[1] / 255f, fgColor[2] / 255f),
new QDColor(bgColor[0] / 255f, bgColor[1] / 255f, bgColor[2] / 255f),
QDConstants.teJustLeft, textBox, dfFlag, QDFont.getFNum(fontName), 0, 0,
QDColor.white, Math.round(duration * movie.getTimeScale()));
textMedia.endEdits();
textTrack.insertMedia(Math.round(start * movie.getTimeScale()), 0,
textMedia.getDuration(), 1);
// position the text track to (x, y)
Matrix mat = new Matrix();
mat.rect(new QDRect(0, 0, TEXT_TRACK_WIDTH, TEXT_TRACK_HEIGHT),
new QDRect(x, y, TEXT_TRACK_WIDTH, TEXT_TRACK_HEIGHT));
textTrack.setMatrix(mat);
} // try
catch (Exception e)
{
e.printStackTrace();