You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BorderAttributesConverter.java 6.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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.render.rtf;
  19. /*
  20. * This file is part of the RTF library of the FOP project, which was originally
  21. * created by Bertrand Delacretaz <bdelacretaz@codeconsult.ch> and by other
  22. * contributors to the jfor project (www.jfor.org), who agreed to donate jfor to
  23. * the FOP project.
  24. */
  25. import org.apache.fop.fo.Constants;
  26. import org.apache.fop.fo.properties.CommonBorderPaddingBackground;
  27. import org.apache.fop.render.rtf.rtflib.rtfdoc.IBorderAttributes;
  28. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfAttributes;
  29. import org.apache.fop.render.rtf.rtflib.rtfdoc.RtfText;
  30. /** Constants for RTF border attribute names, and a static method for converting
  31. * fo attribute strings. */
  32. public final class BorderAttributesConverter {
  33. /**
  34. * Constructor is private, because it's just a utility class.
  35. */
  36. private BorderAttributesConverter() {
  37. }
  38. /**
  39. * Create a border control word in attributes, with border properties
  40. * as specified in color, style and width.
  41. * @param border The CommonBorderPaddingBackground object.
  42. * @param side The START, END, BEFORE, AFTER enum from CommonBorderPaddingBackground.
  43. * @param attributes The attributes list to set the border control word.
  44. * @param controlWord The border control word.
  45. */
  46. public static void makeBorder(CommonBorderPaddingBackground border, int side,
  47. RtfAttributes attributes, String controlWord) {
  48. int styleEnum = border.getBorderStyle(side);
  49. if (styleEnum != Constants.EN_NONE) {
  50. FOPRtfAttributes attrs = new FOPRtfAttributes();
  51. attrs.set(IBorderAttributes.BORDER_COLOR, border.getBorderColor(side));
  52. attrs.set(convertAttributetoRtf(styleEnum));
  53. //division by 50 to convert millipoints to twips
  54. attrs.set(IBorderAttributes.BORDER_WIDTH, border.getBorderWidth(side, false) / 50);
  55. attributes.set(controlWord, attrs);
  56. //Don't set BORDER_SPACE, because it makes the table look quite broken:
  57. //vertical and horizontal borders don't meet at corners.
  58. //attrs.setTwips(IBorderAttributes.BORDER_SPACE, border.getPadding(side, false, null));
  59. //attributes.set(controlWord, attrs);
  60. } else {
  61. // Here padding specified, but corresponding border is not available
  62. // Padding in millipoints
  63. double paddingPt = border.getPadding(side, false, null) / 1000.0;
  64. // Padding in twips
  65. int padding = (int) Math.round(paddingPt * FoUnitsConverter.POINT_TO_TWIPS);
  66. // Add padding to corresponding space (space-before or space-after)
  67. // if side == START or END, do nothing
  68. if (padding != 0) {
  69. if (side == CommonBorderPaddingBackground.BEFORE) {
  70. attributes.addIntegerValue(padding, RtfText.SPACE_BEFORE);
  71. } else if (side == CommonBorderPaddingBackground.AFTER) {
  72. attributes.addIntegerValue(padding, RtfText.SPACE_AFTER);
  73. }
  74. }
  75. }
  76. }
  77. /**
  78. *
  79. * @param iBorderStyle the border style to be converted
  80. * @return String with the converted border style
  81. */
  82. public static String convertAttributetoRtf(int iBorderStyle) {
  83. // Added by Normand Masse
  84. // "solid" is interpreted like "thin"
  85. if (iBorderStyle == Constants.EN_NONE) {
  86. return IBorderAttributes.BORDER_NIL;
  87. } else if (iBorderStyle == Constants.EN_SOLID) {
  88. return IBorderAttributes.BORDER_SINGLE_THICKNESS;
  89. /* } else if (iBorderStyle==Constants.EN_THIN) {
  90. return IBorderAttributes.BORDER_SINGLE_THICKNESS;
  91. } else if (iBorderStyle==Constants.EN_THICK) {
  92. return IBorderAttributes.BORDER_DOUBLE_THICKNESS;
  93. } else if (iBorderStyle==Constants.EN_ value.equals("shadowed")) {
  94. return IBorderAttributes.BORDER_SHADOWED;*/
  95. } else if (iBorderStyle == Constants.EN_DOUBLE) {
  96. return IBorderAttributes.BORDER_DOUBLE;
  97. } else if (iBorderStyle == Constants.EN_DOTTED) {
  98. return IBorderAttributes.BORDER_DOTTED;
  99. } else if (iBorderStyle == Constants.EN_DASHED) {
  100. return IBorderAttributes.BORDER_DASH;
  101. } else if (iBorderStyle == Constants.EN_GROOVE) {
  102. return IBorderAttributes.BORDER_ENGRAVE;
  103. } else if (iBorderStyle == Constants.EN_RIDGE) {
  104. return IBorderAttributes.BORDER_EMBOSS;
  105. } else if (iBorderStyle == Constants.EN_INSET) {
  106. return IBorderAttributes.BORDER_ENGRAVE;
  107. } else if (iBorderStyle == Constants.EN_OUTSET) {
  108. return IBorderAttributes.BORDER_EMBOSS;
  109. /* } else if (iBorderStyle==Constants value.equals("hairline")) {
  110. return IBorderAttributes.BORDER_HAIRLINE;*/
  111. /* } else if (iBorderStyle==Constant value.equals("dot-dash")) {
  112. return IBorderAttributes.BORDER_DOT_DASH;
  113. } else if (iBorderStyle==Constant value.equals("dot-dot-dash")) {
  114. return IBorderAttributes.BORDER_DOT_DOT_DASH;
  115. } else if (iBorderStyle==Constant value.equals("triple")) {
  116. return IBorderAttributes.BORDER_TRIPLE;
  117. } else if (iBorderStyle==Constant value.equals("wavy")) {
  118. return IBorderAttributes.BORDER_WAVY;
  119. } else if (iBorderStyle==Constant value.equals("wavy-double")) {
  120. return IBorderAttributes.BORDER_WAVY_DOUBLE;
  121. } else if (iBorderStyle==Constant value.equals("striped")) {
  122. return IBorderAttributes.BORDER_STRIPED;
  123. } else if (iBorderStyle==Constant value.equals("emboss")) {
  124. return IBorderAttributes.BORDER_EMBOSS;
  125. } else if (iBorderStyle==Constant value.equals("engrave")) {
  126. return IBorderAttributes.BORDER_ENGRAVE;*/
  127. } else {
  128. return IBorderAttributes.BORDER_SINGLE_THICKNESS;
  129. }
  130. }
  131. }