?? markup.java
字號:
/** the CSS value for a horizontal alignment of an object */ public static final String CSS_VALUE_TEXTALIGNRIGHT = "right"; /** the CSS value for a horizontal alignment of an object */ public static final String CSS_VALUE_TEXTALIGNCENTER = "center"; /** the CSS value for a horizontal alignment of an object */ public static final String CSS_VALUE_TEXTALIGNJUSTIFY = "justify"; /** a CSS value for text decoration */ public static final String CSS_VALUE_UNDERLINE = "underline"; /** a default value for font-size * @since 2.1.3 */ public static final float DEFAULT_FONT_SIZE = 12f; /** * Parses a length. * * @param string * a length in the form of an optional + or -, followed by a * number and a unit. * @return a float */ public static float parseLength(String string) { // TODO: Evaluate the effect of this. // It may change the default behavour of the methd if this is changed. // return parseLength(string, Markup.DEFAULT_FONT_SIZE); int pos = 0; int length = string.length(); boolean ok = true; while (ok && pos < length) { switch (string.charAt(pos)) { case '+': case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '.': pos++; break; default: ok = false; } } if (pos == 0) return 0f; if (pos == length) return Float.parseFloat(string + "f"); float f = Float.parseFloat(string.substring(0, pos) + "f"); string = string.substring(pos); // inches if (string.startsWith("in")) { return f * 72f; } // centimeters if (string.startsWith("cm")) { return (f / 2.54f) * 72f; } // millimeters if (string.startsWith("mm")) { return (f / 25.4f) * 72f; } // picas if (string.startsWith("pc")) { return f * 12f; } // default: we assume the length was measured in points return f; } /** * New method contributed by: Lubos Strapko * * @since 2.1.3 */ public static float parseLength(String string, float actualFontSize) { if (string == null) return 0f; int pos = 0; int length = string.length(); boolean ok = true; while (ok && pos < length) { switch (string.charAt(pos)) { case '+': case '-': case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': case '.': pos++; break; default: ok = false; } } if (pos == 0) return 0f; if (pos == length) return Float.parseFloat(string + "f"); float f = Float.parseFloat(string.substring(0, pos) + "f"); string = string.substring(pos); // inches if (string.startsWith("in")) { return f * 72f; } // centimeters if (string.startsWith("cm")) { return (f / 2.54f) * 72f; } // millimeters if (string.startsWith("mm")) { return (f / 25.4f) * 72f; } // picas if (string.startsWith("pc")) { return f * 12f; } // 1em is equal to the current font size if (string.startsWith("em")) { return f * actualFontSize; } // one ex is the x-height of a font (x-height is usually about half the // font-size) if (string.startsWith("ex")) { return f * actualFontSize / 2; } // default: we assume the length was measured in points return f; } /** * Converts a <CODE>Color</CODE> into a HTML representation of this <CODE> * Color</CODE>. * * @param s * the <CODE>Color</CODE> that has to be converted. * @return the HTML representation of this <COLOR>Color </COLOR> */ public static Color decodeColor(String s) { if (s == null) return null; s = s.toLowerCase().trim(); Color c = WebColors.getRGBColor(s); if (c != null) return c; try { if (s.startsWith("#")) { if (s.length() == 4) s = "#" + s.substring(1, 2) + s.substring(1, 2) + s.substring(2, 3) + s.substring(2, 3) + s.substring(3, 4) + s.substring(3, 4); if (s.length() == 7) return new Color(Integer.parseInt(s.substring(1), 16)); } else if (s.startsWith("rgb")) { StringTokenizer tk = new StringTokenizer(s.substring(3), " \t\r\n\f(),"); int[] cc = new int[3]; for (int k = 0; k < 3; ++k) { if (!tk.hasMoreTokens()) return null; String t = tk.nextToken(); float n; if (t.endsWith("%")) { n = Float.parseFloat(t.substring(0, t.length() - 1)); n = n * 255f / 100f; } else n = Float.parseFloat(t); int ni = (int) n; if (ni > 255) ni = 255; else if (ni < 0) ni = 0; cc[k] = ni; } return new Color(cc[0], cc[1], cc[2]); } } catch (Exception e) { } return null; } /** * This method parses a String with attributes and returns a Properties * object. * * @param string * a String of this form: 'key1="value1"; key2="value2";... * keyN="valueN" ' * @return a Properties object */ public static Properties parseAttributes(String string) { Properties result = new Properties(); if (string == null) return result; StringTokenizer keyValuePairs = new StringTokenizer(string, ";"); StringTokenizer keyValuePair; String key; String value; while (keyValuePairs.hasMoreTokens()) { keyValuePair = new StringTokenizer(keyValuePairs.nextToken(), ":"); if (keyValuePair.hasMoreTokens()) key = keyValuePair.nextToken().trim(); else continue; if (keyValuePair.hasMoreTokens()) value = keyValuePair.nextToken().trim(); else continue; if (value.startsWith("\"")) value = value.substring(1); if (value.endsWith("\"")) value = value.substring(0, value.length() - 1); result.setProperty(key.toLowerCase(), value); } return result; } /** * Removes the comments sections of a String. * * @param string * the original String * @param startComment * the String that marks the start of a Comment section * @param endComment * the String that marks the end of a Comment section. * @return the String stripped of its comment section */ public static String removeComment(String string, String startComment, String endComment) { StringBuffer result = new StringBuffer(); int pos = 0; int end = endComment.length(); int start = string.indexOf(startComment, pos); while (start > -1) { result.append(string.substring(pos, start)); pos = string.indexOf(endComment, start) + end; start = string.indexOf(startComment, pos); } result.append(string.substring(pos)); return result.toString(); }}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -