# File TexRenderer.java

### Coverage histogram

38% of files have more coverage

0
23
4
1
100
62
10
0.43
5.75
4
2.5

## Classes

Class Line # Actions
TexRenderer 46 23 0% 10 4
0.851851985.2%

## Contributing tests

This file is covered by 12 tests. .

## Source view

 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.rendering.internal.renderer.tex; 21 22 import java.util.Map; 23 24 import javax.inject.Named; 25 26 import org.xwiki.component.annotation.Component; 27 import org.xwiki.component.annotation.InstantiationStrategy; 28 import org.xwiki.component.descriptor.ComponentInstantiationStrategy; 29 import org.xwiki.rendering.internal.renderer.wikimodel.WikiModelGeneratorListener; 30 import org.xwiki.rendering.internal.renderer.wikimodel.WikiModelPrinterAdapter; 31 import org.xwiki.rendering.listener.Format; 32 import org.xwiki.rendering.listener.WrappingListener; 33 import org.xwiki.rendering.renderer.PrintRenderer; 34 import org.xwiki.rendering.renderer.printer.WikiPrinter; 35 import org.xwiki.rendering.wikimodel.tex.TexSerializer; 36 37 /** 38 * Generates LaTeX syntax from a {@link org.xwiki.rendering.block.XDOM} object being traversed. 39 * 40 * @version $Id: cf884975a8952fbe48dff17e0e08387fe1ffe532$ 41 * @since 2.1RC1 42 */ 43 44 @Named("tex/1.0") 45 @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) 46 public class TexRenderer extends WrappingListener implements PrintRenderer 47 { 48 /** 49 * The printer. 50 */ 51 private WikiPrinter printer; 52 53 24 @Override 54 public WikiPrinter getPrinter() 55 { 56 24 return this.printer; 57 } 58 59 12 @Override 60 public void setPrinter(WikiPrinter printer) 61 { 62 12 this.printer = printer; 63 12 setWrappedListener(new WikiModelGeneratorListener(new TexSerializer(new WikiModelPrinterAdapter(getPrinter()), 64 null, null, null))); 65 } 66 67 6 @Override 68 public void beginFormat(Format format, Map parameters) 69 { 70 6 switch (format) { 71 3 case BOLD: 72 3 this.printer.print("\\textbf{"); 73 3 break; 74 2 case ITALIC: 75 2 this.printer.print("\\textit{"); 76 2 break; 77 1 case MONOSPACE: 78 1 this.printer.print("\\texttt{"); 79 1 break; 80 0 default: 81 // Not supported by default, additional packages are needed 82 0 break; 83 } 84 } 85 86 6 @Override 87 public void endFormat(Format format, Map parameters) 88 { 89 6 switch (format) { 90 3 case BOLD: 91 2 case ITALIC: 92 1 case MONOSPACE: 93 6 this.printer.print("}"); 94 6 break; 95 0 default: 96 // Not supported by default, additional packages are needed 97 0 break; 98 } 99 } 100 }