Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

PDFTextPainterTestCase.java 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.svg;
  19. import java.awt.Graphics2D;
  20. import java.io.StringWriter;
  21. import org.junit.Test;
  22. import org.apache.batik.bridge.TextPainter;
  23. import org.apache.xmlgraphics.java2d.GraphicContext;
  24. import org.apache.fop.fonts.FontInfo;
  25. import org.apache.fop.pdf.PDFDocument;
  26. public class PDFTextPainterTestCase extends NativeTextPainterTest {
  27. private static class OperatorCheckingPDFGraphics2D extends PDFGraphics2D {
  28. OperatorCheckingPDFGraphics2D(FontInfo fontInfo, final OperatorValidator validator) {
  29. super(false, fontInfo, new PDFDocument("test"), null, null, null, 0, null);
  30. this.currentStream = new StringWriter() {
  31. @Override
  32. public void write(String str) {
  33. validator.check(str);
  34. }
  35. };
  36. }
  37. }
  38. @Override
  39. protected TextPainter createTextPainter(FontInfo fontInfo) {
  40. return new PDFTextPainter(fontInfo);
  41. }
  42. @Override
  43. protected Graphics2D createGraphics2D(FontInfo fontInfo, OperatorValidator validator) {
  44. PDFGraphics2D g2d = new OperatorCheckingPDFGraphics2D(fontInfo, validator);
  45. g2d.setGraphicContext(new GraphicContext());
  46. return g2d;
  47. }
  48. @Test
  49. public void testRotatedGlyph() throws Exception {
  50. runTest("rotated-glyph.svg", new OperatorValidator()
  51. .addOperatorMatch("Tm", "1 0 0 -1 40 110 Tm ")
  52. .addOperatorMatch("TJ", "[(A)] TJ\n")
  53. .addOperatorMatch("Tm", "0.70710677 0.7071068 0.7071068 -0.70710677 106.69999695 110 Tm ")
  54. .addOperatorMatch("TJ", "[(B)] TJ\n")
  55. .addOperatorMatch("Tm", "1 0 0 -1 173.3999939 110 Tm ")
  56. .addOperatorMatch("TJ", "[(C)] TJ\n"));
  57. }
  58. @Test
  59. public void testDxDy() throws Exception {
  60. runTest("dx-dy.svg", new OperatorValidator()
  61. .addOperatorMatch("Tm", "1 0 0 -1 55 35 Tm ")
  62. .addOperatorMatch("TJ", "[(ABCDE)] TJ\n")
  63. .addOperatorMatch("Tm", "1 0 0 -1 55 75 Tm ")
  64. .addOperatorMatch("TJ", "[(A)] TJ\n")
  65. .addOperatorMatch("Tm", "1 0 0 -1 69 85 Tm ")
  66. .addOperatorMatch("TJ", "[(B)] TJ\n")
  67. .addOperatorMatch("Tm", "1 0 0 -1 109 80 Tm ")
  68. .addOperatorMatch("TJ", "[(C)] TJ\n")
  69. .addOperatorMatch("Tm", "1 0 0 -1 91 65 Tm ")
  70. .addOperatorMatch("TJ", "[(D)] TJ\n")
  71. .addOperatorMatch("Tm", "1 0 0 -1 127 75 Tm ")
  72. .addOperatorMatch("TJ", "[(E)] TJ\n"));
  73. }
  74. @Test
  75. public void testSpacing() throws Exception {
  76. runTest("spacing.svg", new OperatorValidator()
  77. .addOperatorMatch("Tm", "1 0 0 -1 0 0 Tm ")
  78. .addOperatorMatch("TJ", "[(V) 80 (A) 70 (V)] TJ\n")
  79. .addOperatorMatch("Tm", "1 0 0 -1 0 0 Tm ")
  80. .addOperatorMatch("TJ", "[(V) 80 (A) 70 (V)] TJ\n")
  81. .addOperatorMatch("Tm", "1 0 0 -1 0 0 Tm ")
  82. .addOperatorMatch("TJ", "[(V) -20 (A) -30 (V)] TJ\n")
  83. .addOperatorMatch("Tm", "1 0 0 -1 0 0 Tm ")
  84. .addOperatorMatch("TJ", "[(ab) -111 ( ) -389 (cd)] TJ\n"));
  85. }
  86. @Test
  87. public void testGlyphOrientation() throws Exception {
  88. runTest("glyph-orientation.svg", new OperatorValidator()
  89. .addOperatorMatch("Tm", "0 1 1 0 738.5 0 Tm ")
  90. .addOperatorMatch("TJ", "[(A)] TJ\n")
  91. .addOperatorMatch("Tm", "0 1 1 0 738.5 667 Tm ")
  92. .addOperatorMatch("TJ", "[(B)] TJ\n")
  93. .addOperatorMatch("Tm", "0 1 1 0 738.5 1334 Tm ")
  94. .addOperatorMatch("TJ", "[(C)] TJ\n")
  95. .addOperatorMatch("Tm", "0 1 1 0 738.5 2056 Tm ")
  96. .addOperatorMatch("TJ", "[(D)] TJ\n")
  97. .addOperatorMatch("Tm", "1 0 0 -1 2149 718 Tm ")
  98. .addOperatorMatch("TJ", "[(E)] TJ\n")
  99. .addOperatorMatch("Tm", "1 0 0 -1 2165.5 1643 Tm ")
  100. .addOperatorMatch("TJ", "[(F)] TJ\n")
  101. .addOperatorMatch("Tm", "1 0 0 -1 2124 2568 Tm ")
  102. .addOperatorMatch("TJ", "[(G)] TJ\n")
  103. .addOperatorMatch("Tm", "1 0 0 -1 2138.5 3493 Tm ")
  104. .addOperatorMatch("TJ", "[(H)] TJ\n")
  105. .addOperatorMatch("Tm", "0 -1 -1 0 718 5000 Tm ")
  106. .addOperatorMatch("TJ", "[(I)] TJ\n")
  107. .addOperatorMatch("Tm", "0 -1 -1 0 1643 5000 Tm ")
  108. .addOperatorMatch("TJ", "[(J)] TJ\n")
  109. .addOperatorMatch("Tm", "0 -1 -1 0 2568 5000 Tm ")
  110. .addOperatorMatch("TJ", "[(K)] TJ\n")
  111. .addOperatorMatch("Tm", "0 -1 -1 0 3493 5000 Tm ")
  112. .addOperatorMatch("TJ", "[(L)] TJ\n"));
  113. }
  114. @Test
  115. public void testBaselineShift() throws Exception {
  116. runTest("baseline-shift.svg", new OperatorValidator()
  117. .addOperatorMatch("Tm", "1 0 0 -1 0 0 Tm ")
  118. .addOperatorMatch("TJ", "[(AB)] TJ\n")
  119. .addOperatorMatch("Tm", "1 0 0 -1 1334 -462.5 Tm ")
  120. .addOperatorMatch("TJ", "[(CD)] TJ\n")
  121. .addOperatorMatch("Tm", "1 0 0 -1 2778 0 Tm ")
  122. .addOperatorMatch("TJ", "[(EF)] TJ\n")
  123. .addOperatorMatch("Tm", "1 0 0 -1 4056 462.5 Tm ")
  124. .addOperatorMatch("TJ", "[(GH)] TJ\n")
  125. .addOperatorMatch("Tm", "1 0 0 -1 5556 0 Tm ")
  126. .addOperatorMatch("TJ", "[(IJ)] TJ\n"));
  127. }
  128. }