1 package com.tapina.robe.runtime;
2
3 /***
4 * This class contains utility methods for working with fonts.
5 */
6 public class FontUtils {
7 /***
8 * This method finds the Acorn name for a given native Font.
9 * Note that each name segment is restricted to 10 characters.
10 * @param font native Font object
11 * @param maxLength maximum length of Acorn name
12 * @return name of font for RISC OS programs, or null if no Acorn version could be created
13 * @todo change to use StringTokenizer
14 */
15 public static String nativeToAcornName(final java.awt.Font font, final int maxLength) {
16 final String fontName = font.getName();
17 String[] nameParts = fontName.split("-");
18 if (fontName.equals("Serif")) {
19 return "Trinity.Medium";
20 } else if (fontName.equals("Monospaced")) {
21 return "Corpus.Medium";
22 }
23 StringBuffer outputName = new StringBuffer(maxLength);
24 final int namePartCount = nameParts.length;
25 for (int i = 0; i < namePartCount; i++) {
26 final String s = nameParts[i];
27 if (s.length() > 10) {
28 return null;
29 }
30 outputName.append(s);
31 if (i < namePartCount - 1) {
32 outputName.append('.');
33 }
34 }
35 if (outputName.length() >= maxLength) {
36 return null;
37 }
38 final String acornName = outputName.toString();
39 return acornName;
40 }
41 }