<commit_before>package mkl.testarea.pdfbox1.content;

import java.io.File;
import java.io.IOException;

import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * This test focuses on drawing special characters, something the PDFBox method
 * {@link PDPageContentStream#drawString(String)} is not really good at-
 * 
 * @author mkl
 */
public class DrawSpecialCharacters
{
    final static File RESULT_FOLDER = new File("target/test-outputs", "content");

    @BeforeClass
    public static void setUpBeforeClass() throws Exception
    {
        RESULT_FOLDER.mkdirs();
    }

    /**
     * <a href="http://stackoverflow.com/questions/30619974/pdfbox-unable-to-write-superscripted-characters">
     * PDFBox unable to write superscripted characters
     * </a>
     * <p>
     * {@link #testDrawTmSignBroken()} represents the observation the OP made,
     * {@link #testDrawTmSignCustomDraw()} is a solution using custom drawing operations, and
     * {@link #testDrawTmSignLetters()} is a solution drawing the trademark symbol using smaller letters with text rise.
     */
	@Test
	public void testDrawTmSignBroken() throws IOException, COSVisitorException
	{
		PDDocument document = new PDDocument();
        PDPage page = new PDPage();
        document.addPage(page);
        PDPageContentStream contents = new PDPageContentStream(document, page);
        PDFont font = PDType1Font.HELVETICA_BOLD;<commit_msg>New test DrawSpecialCharacters.testDrawEuro focusing on the stackoverflow question<commit_after>package mkl.testarea.pdfbox1.content;

import java.io.File;
import java.io.IOException;

import org.apache.pdfbox.cos.COSName;
import org.apache.pdfbox.encoding.EncodingManager;
import org.apache.pdfbox.exceptions.COSVisitorException;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.pdmodel.PDPage;
import org.apache.pdfbox.pdmodel.edit.PDPageContentStream;
import org.apache.pdfbox.pdmodel.font.PDFont;
import org.apache.pdfbox.pdmodel.font.PDType1Font;
import org.junit.BeforeClass;
import org.junit.Test;

/**
 * This test focuses on drawing special characters, something the PDFBox method
 * {@link PDPageContentStream#drawString(String)} is not really good at-
 * 
 * @author mkl
 */
public class DrawSpecialCharacters
{
    final static File RESULT_FOLDER = new File("target/test-outputs", "content");

    @BeforeClass
    public static void setUpBeforeClass() throws Exception
    {
        RESULT_FOLDER.mkdirs();
    }

    /**
     * <a href="http://stackoverflow.com/questions/22260344/pdfbox-encode-symbol-currency-euro">
     * PdfBox encode symbol currency euro
     * </a>
     * <p>
     * Three ways of trying to draw a '' symbol, the first one fails.
     * </p>
     */
    @Test
    public void testDrawEuro() throws IOException, COSVisitorException
    {
        PDDocument document = new PDDocument();
        PDPage page = new PDPage();
        document.addPage(page);
        PDPageContentStream contents = new PDPageContentStream(document, page);
        PDFont font = PDType1Font.HELVETICA_BOLD;
        contents.beginText();
        contents.setFont(font, 18);
        contents.moveTextPositionByAmount(30, 600);
        contents.drawString("");
        contents.moveTextPositionByAmount(0, -30);
        contents.drawString(String.valueOf(Character.toChars(EncodingManager.INSTANCE.getEncoding(COSName.WIN_ANSI_ENCODING).getCode("Euro"))));
        contents.moveTextPositionByAmount(0, -30);
        byte[] commands = "(x) Tj ".getBytes();
        commands[1] = (byte) 128;
        contents.appendRawCommands(commands);
        contents.endText();
        contents.close();
        document.save(new File(RESULT_FOLDER, "Euro.pdf"));
        document.close();
    }

    /**
     * <a href="http://stackoverflow.com/questions/30619974/pdfbox-unable-to-write-superscripted-characters">
     * PDFBox unable to write superscripted characters
     * </a>
     * <p>
     * {@link #testDrawTmSignBroken()} represents the observation the OP made,
     * {@link #testDrawTmSignCustomDraw()} is a solution using custom drawing operations, and
     * {@link #testDrawTmSignLetters()} is a solution drawing the trademark symbol using smaller letters with text rise.
     * </p>
     */
	@Test
	public void testDrawTmSignBroken() throws IOException, COSVisitorException
	{
		PDDocument document = new PDDocument();
        PDPage page = new PDPage();
        document.addPage(page);
        PDPageContentStream contents = new PDPageContentStream(document, page);
        PDFont font = PDType1Font.HELVETICA_BOLD;
{'fraction_non_alphanumeric': 0.10633484162895927, 'fraction_numerical': 0.009872480460715755, 'mean_word_length': 3.735150925024343, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4045665', 'n_tokens_mistral': 1481, 'n_tokens_neox': 1427, 'n_words': 337}