| Class | Line # | Actions | |||||
|---|---|---|---|---|---|---|---|
| FormulaRenderer | 33 | 0 | - | 0 | 0 | ||
| FormulaRenderer.Type | 40 | 4 | 0% | 3 | 4 | ||
| FormulaRenderer.FontSize | 101 | 4 | 0% | 3 | 2 |
| 1 | /* | |
| 2 | * See the NOTICE file distributed with this work for additional | |
| 3 | * information regarding copyright ownership. | |
| 4 | * | |
| 5 | * This is free software; you can redistribute it and/or modify it | |
| 6 | * under the terms of the GNU Lesser General Public License as | |
| 7 | * published by the Free Software Foundation; either version 2.1 of | |
| 8 | * the License, or (at your option) any later version. | |
| 9 | * | |
| 10 | * This software is distributed in the hope that it will be useful, | |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 13 | * Lesser General Public License for more details. | |
| 14 | * | |
| 15 | * You should have received a copy of the GNU Lesser General Public | |
| 16 | * License along with this software; if not, write to the Free | |
| 17 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
| 18 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
| 19 | */ | |
| 20 | package org.xwiki.formula; | |
| 21 | ||
| 22 | import java.io.IOException; | |
| 23 | ||
| 24 | import org.xwiki.component.annotation.Role; | |
| 25 | ||
| 26 | /** | |
| 27 | * Convert a LaTeX formula into an image. | |
| 28 | * | |
| 29 | * @version $Id: 3a01bdca2ae766e12573a71285dc7f98b6990328 $ | |
| 30 | * @since 2.0M3 | |
| 31 | */ | |
| 32 | @Role | |
| 33 | public interface FormulaRenderer | |
| 34 | { | |
| 35 | /** | |
| 36 | * Encloses the supported formats for rendered mathematical formulae. | |
| 37 | * | |
| 38 | * @version $Id: 3a01bdca2ae766e12573a71285dc7f98b6990328 $ | |
| 39 | */ | |
| 40 | enum Type | |
| 41 | { | |
| 42 | /** | |
| 43 | * Portable Network Graphics, a lossless, free image format. See RFC 2083 for details. Best-looking results, but | |
| 44 | * might not be supported by very old browsers. | |
| 45 | */ | |
| 46 | PNG(".png", "image/png"), | |
| 47 | ||
| 48 | /** Graphics Interchange Format, a patent encumbered image format. */ | |
| 49 | GIF(".gif", "image/gif"), | |
| 50 | ||
| 51 | /** Lossy image format created by Joint Photographic Experts Group. */ | |
| 52 | JPEG(".jpg", "image/jpeg"); | |
| 53 | ||
| 54 | /** The default rendered image format. */ | |
| 55 | public static final Type DEFAULT = PNG; | |
| 56 | ||
| 57 | /** The file extension for this type. */ | |
| 58 | private final String extension; | |
| 59 | ||
| 60 | /** The mimetype for this format. */ | |
| 61 | private final String mimetype; | |
| 62 | ||
| 63 | /** | |
| 64 | * Creation of a type, specifying the corresponding file extension and mimetype. | |
| 65 | * | |
| 66 | * @param extension the file extension for this format, starting with "." | |
| 67 | * @param mimetype the mimetype for this format | |
| 68 | */ | |
| 69 | 3 | Type(String extension, String mimetype) |
| 70 | { | |
| 71 | 3 | this.extension = extension; |
| 72 | 3 | this.mimetype = mimetype; |
| 73 | } | |
| 74 | ||
| 75 | /** | |
| 76 | * Access to the file extension corresponding to this format. | |
| 77 | * | |
| 78 | * @return a string containing the extension, starting with ".". | |
| 79 | */ | |
| 80 | 0 | public String getExtension() |
| 81 | { | |
| 82 | 0 | return this.extension; |
| 83 | } | |
| 84 | ||
| 85 | /** | |
| 86 | * Access to the mimetype corresponding to this format. | |
| 87 | * | |
| 88 | * @return a string containing the mimetype, in the format defined in RFC 2045 | |
| 89 | */ | |
| 90 | 0 | public String getMimetype() |
| 91 | { | |
| 92 | 0 | return this.mimetype; |
| 93 | } | |
| 94 | } | |
| 95 | ||
| 96 | /** | |
| 97 | * Encloses the supported LaTeX font sizes used for displaying a mathematical formula. | |
| 98 | * | |
| 99 | * @version $Id: 3a01bdca2ae766e12573a71285dc7f98b6990328 $ | |
| 100 | */ | |
| 101 | enum FontSize | |
| 102 | { | |
| 103 | // TODO: Check the correct pt sizes | |
| 104 | /** Script size. */ | |
| 105 | TINY(10, "\\tiny"), | |
| 106 | ||
| 107 | /** Footnote size. */ | |
| 108 | VERY_SMALL(12, "\\scriptsize"), | |
| 109 | ||
| 110 | /** Footnote size. */ | |
| 111 | SMALLER(14, "\\footnotesize"), | |
| 112 | ||
| 113 | /** Small text. */ | |
| 114 | SMALL(17, "\\small"), | |
| 115 | ||
| 116 | /** Normal font size. */ | |
| 117 | NORMAL(20, "\\normalsize"), | |
| 118 | ||
| 119 | /** Slightly larger font size. */ | |
| 120 | LARGE(24, "\\large"), | |
| 121 | ||
| 122 | /** Large font size. */ | |
| 123 | LARGER(29, "\\Large"), | |
| 124 | ||
| 125 | /** Very large. */ | |
| 126 | VERY_LARGE(35, "\\LARGE"), | |
| 127 | ||
| 128 | /** The largest defined font size. */ | |
| 129 | HUGE(41, "\\huge"), | |
| 130 | ||
| 131 | /** The largest defined font size. */ | |
| 132 | EXTREMELY_HUGE(50, "\\Huge"); | |
| 133 | ||
| 134 | /** The default font size. */ | |
| 135 | public static final FontSize DEFAULT = NORMAL; | |
| 136 | ||
| 137 | /** The font pt size. */ | |
| 138 | private final int size; | |
| 139 | ||
| 140 | /** The corresponding LaTeX command. */ | |
| 141 | private final String command; | |
| 142 | ||
| 143 | /** | |
| 144 | * Creation of a font size, specifying the corresponding size measured in "pt" and the LaTeX command. | |
| 145 | * | |
| 146 | * @param size the font size in "pt" | |
| 147 | * @param command the LateX command that sets this font size | |
| 148 | */ | |
| 149 | 10 | FontSize(int size, String command) |
| 150 | { | |
| 151 | 10 | this.size = size; |
| 152 | 10 | this.command = command; |
| 153 | } | |
| 154 | ||
| 155 | /** | |
| 156 | * Access to the actual font size. | |
| 157 | * | |
| 158 | * @return the value of the corresponding font size, in "pt" | |
| 159 | */ | |
| 160 | 2 | public int getSize() |
| 161 | { | |
| 162 | 2 | return this.size; |
| 163 | } | |
| 164 | ||
| 165 | /** | |
| 166 | * Access to the LateX command that sets this font size. | |
| 167 | * | |
| 168 | * @return a string representing the LateX command | |
| 169 | */ | |
| 170 | 0 | public String getCommand() |
| 171 | { | |
| 172 | 0 | return this.command; |
| 173 | } | |
| 174 | } | |
| 175 | ||
| 176 | /** | |
| 177 | * Generates the image (if not already generated), stores it, and returns a key which can be used for retrieving it | |
| 178 | * in a subsequent request. | |
| 179 | * | |
| 180 | * @param formula the mathematical formula to render, in LaTeX format, <em>without</em> the surrounding math-mode | |
| 181 | * commands ($, begin{math}, etc.) | |
| 182 | * @param inline whether the formula appears inline inside the text, or as a standalone block | |
| 183 | * @param size the font size to use for the text | |
| 184 | * @param type The type of image to generate. See the {@link Type} enum for supported types. <em>Not all renderers | |
| 185 | * support all types</em>. | |
| 186 | * @return an identifier which can be used for retrieving the image from the {@link ImageStorage storage} | |
| 187 | * @throws IllegalArgumentException if the LaTeX syntax of the formula is incorrect and the error is unrecoverable | |
| 188 | * @throws IOException in case of a renderer execution error | |
| 189 | */ | |
| 190 | String process(String formula, boolean inline, FontSize size, Type type) throws IllegalArgumentException, | |
| 191 | IOException; | |
| 192 | ||
| 193 | /** | |
| 194 | * Retrieve the image data from the storage. | |
| 195 | * | |
| 196 | * @param imageID the identifier for the image, returned by {@link #process(String, boolean, FontSize, Type)} | |
| 197 | * @return the generated {@link ImageData}, or {@code null} if no image exists with this identifier | |
| 198 | */ | |
| 199 | ImageData getImage(String imageID); | |
| 200 | } |