Link Here
|
9 |
import org.apache.poi.hwpf.usermodel.CharacterProperties; |
9 |
import org.apache.poi.hwpf.usermodel.CharacterProperties; |
10 |
import org.apache.poi.hwpf.usermodel.CharacterRun; |
10 |
import org.apache.poi.hwpf.usermodel.CharacterRun; |
11 |
import org.apache.poi.hwpf.usermodel.Paragraph; |
11 |
import org.apache.poi.hwpf.usermodel.Paragraph; |
|
|
12 |
import org.apache.poi.hwpf.usermodel.Picture; |
12 |
import org.apache.poi.hwpf.usermodel.Range; |
13 |
import org.apache.poi.hwpf.usermodel.Range; |
13 |
import org.apache.poi.hwpf.usermodel.Section; |
14 |
import org.apache.poi.hwpf.usermodel.Section; |
14 |
import org.apache.poi.hwpf.usermodel.SectionProperties; |
15 |
import org.apache.poi.hwpf.usermodel.SectionProperties; |
Link Here
|
179 |
} |
180 |
} |
180 |
} |
181 |
} |
181 |
|
182 |
|
|
|
183 |
public static String getJustification(int js) { |
184 |
switch (js) { |
185 |
case 0: |
186 |
return "start"; |
187 |
case 1: |
188 |
return "center"; |
189 |
case 2: |
190 |
return "end"; |
191 |
case 3: |
192 |
case 4: |
193 |
return "justify"; |
194 |
case 5: |
195 |
return "center"; |
196 |
case 6: |
197 |
return "left"; |
198 |
case 7: |
199 |
return "start"; |
200 |
case 8: |
201 |
return "end"; |
202 |
case 9: |
203 |
return "justify"; |
204 |
} |
205 |
return ""; |
206 |
} |
207 |
|
182 |
public static String getListItemNumberLabel(int number, int format) { |
208 |
public static String getListItemNumberLabel(int number, int format) { |
183 |
|
209 |
|
184 |
if (format != 0) |
210 |
if (format != 0) |
Link Here
|
244 |
} |
270 |
} |
245 |
|
271 |
|
246 |
public static void setCharactersProperties(final CharacterRun characterRun, |
272 |
public static void setCharactersProperties(final CharacterRun characterRun, |
247 |
final Element inline) { |
273 |
final Element inline) { |
248 |
final CharacterProperties clonedProperties = characterRun |
274 |
final CharacterProperties clonedProperties = characterRun |
249 |
.cloneProperties(); |
275 |
.cloneProperties(); |
250 |
StringBuilder textDecorations = new StringBuilder(); |
276 |
StringBuilder textDecorations = new StringBuilder(); |
251 |
|
277 |
|
252 |
setBorder(inline, clonedProperties.getBrc(), EMPTY); |
278 |
setBorder(inline, clonedProperties.getBrc(), EMPTY); |
253 |
|
279 |
|
254 |
if (characterRun.isCapitalized()) { |
280 |
if (characterRun.isCapitalized()) { |
255 |
inline.setAttribute("text-transform", "uppercase"); |
281 |
inline.setAttribute("text-transform", "uppercase"); |
256 |
} |
282 |
} |
257 |
if (characterRun.isHighlighted()) { |
283 |
if (characterRun.isHighlighted()) { |
258 |
inline.setAttribute("background-color", |
284 |
inline.setAttribute("background-color", |
259 |
getColor(clonedProperties.getIcoHighlight())); |
285 |
getColor(clonedProperties.getIcoHighlight())); |
260 |
} |
286 |
} |
261 |
if (characterRun.isStrikeThrough()) { |
287 |
if (characterRun.isStrikeThrough()) { |
262 |
if (textDecorations.length() > 0) |
288 |
if (textDecorations.length() > 0) |
263 |
textDecorations.append(" "); |
289 |
textDecorations.append(" "); |
264 |
textDecorations.append("line-through"); |
290 |
textDecorations.append("line-through"); |
265 |
} |
291 |
} |
266 |
if (characterRun.isShadowed()) { |
292 |
if (characterRun.isShadowed()) { |
267 |
inline.setAttribute("text-shadow", characterRun.getFontSize() / 24 |
293 |
inline.setAttribute("text-shadow", characterRun.getFontSize() / 24 |
268 |
+ "pt"); |
294 |
+ "pt"); |
269 |
} |
295 |
} |
270 |
if (characterRun.isSmallCaps()) { |
296 |
if (characterRun.isSmallCaps()) { |
271 |
inline.setAttribute("font-variant", "small-caps"); |
297 |
inline.setAttribute("font-variant", "small-caps"); |
272 |
} |
298 |
} |
273 |
if (characterRun.getSubSuperScriptIndex() == 1) { |
299 |
if (characterRun.getSubSuperScriptIndex() == 1) { |
274 |
inline.setAttribute("baseline-shift", "super"); |
300 |
inline.setAttribute("baseline-shift", "super"); |
275 |
inline.setAttribute("font-size", "smaller"); |
301 |
inline.setAttribute("font-size", "smaller"); |
276 |
} |
302 |
} |
277 |
if (characterRun.getSubSuperScriptIndex() == 2) { |
303 |
if (characterRun.getSubSuperScriptIndex() == 2) { |
278 |
inline.setAttribute("baseline-shift", "sub"); |
304 |
inline.setAttribute("baseline-shift", "sub"); |
279 |
inline.setAttribute("font-size", "smaller"); |
305 |
inline.setAttribute("font-size", "smaller"); |
280 |
} |
306 |
} |
281 |
if (characterRun.getUnderlineCode() > 0) { |
307 |
if (characterRun.getUnderlineCode() > 0) { |
282 |
if (textDecorations.length() > 0) |
308 |
if (textDecorations.length() > 0) |
283 |
textDecorations.append(" "); |
309 |
textDecorations.append(" "); |
284 |
textDecorations.append("underline"); |
310 |
textDecorations.append("underline"); |
285 |
} |
311 |
} |
286 |
if (textDecorations.length() > 0) { |
312 |
if (characterRun.isVanished()) { |
287 |
inline.setAttribute("text-decoration", textDecorations.toString()); |
313 |
inline.setAttribute("visibility", "hidden"); |
288 |
} |
314 |
} |
|
|
315 |
if (textDecorations.length() > 0) { |
316 |
inline.setAttribute("text-decoration", textDecorations.toString()); |
317 |
} |
289 |
} |
318 |
} |
290 |
|
319 |
|
291 |
public static void setFontFamily(final Element element, |
320 |
public static void setFontFamily(final Element element, |
Link Here
|
335 |
} |
364 |
} |
336 |
|
365 |
|
337 |
public static void setJustification(Paragraph paragraph, |
366 |
public static void setJustification(Paragraph paragraph, |
338 |
final Element element) { |
367 |
final Element element) { |
339 |
final int justification = paragraph.getJustification(); |
368 |
String justification = getJustification(paragraph.getJustification()); |
340 |
switch (justification) { |
369 |
if (isNotEmpty(justification)) |
341 |
case 0: |
370 |
element.setAttribute("text-align", justification); |
342 |
element.setAttribute("text-align", "start"); |
|
|
343 |
break; |
344 |
case 1: |
345 |
element.setAttribute("text-align", "center"); |
346 |
break; |
347 |
case 2: |
348 |
element.setAttribute("text-align", "end"); |
349 |
break; |
350 |
case 3: |
351 |
element.setAttribute("text-align", "justify"); |
352 |
break; |
353 |
case 4: |
354 |
element.setAttribute("text-align", "justify"); |
355 |
break; |
356 |
case 5: |
357 |
element.setAttribute("text-align", "center"); |
358 |
break; |
359 |
case 6: |
360 |
element.setAttribute("text-align", "left"); |
361 |
break; |
362 |
case 7: |
363 |
element.setAttribute("text-align", "start"); |
364 |
break; |
365 |
case 8: |
366 |
element.setAttribute("text-align", "end"); |
367 |
break; |
368 |
case 9: |
369 |
element.setAttribute("text-align", "justify"); |
370 |
break; |
371 |
} |
372 |
} |
371 |
} |
373 |
|
372 |
|
374 |
public static void setParagraphProperties(Paragraph paragraph, Element block) { |
373 |
public static void setParagraphProperties(Paragraph paragraph, Element block) { |
Link Here
|
399 |
block.setAttribute("white-space-collapse", "false"); |
398 |
block.setAttribute("white-space-collapse", "false"); |
400 |
} |
399 |
} |
401 |
|
400 |
|
|
|
401 |
public static void setPictureProperties(Picture picture, |
402 |
Element graphicElement) { |
403 |
final int aspectRatioX = picture.getAspectRatioX(); |
404 |
final int aspectRatioY = picture.getAspectRatioY(); |
405 |
|
406 |
if (aspectRatioX > 0) { |
407 |
graphicElement.setAttribute("content-width", ((picture.getDxaGoal() |
408 |
* aspectRatioX / 100) / WordToFoUtils.TWIPS_PER_PT) |
409 |
+ "pt"); |
410 |
} else |
411 |
graphicElement.setAttribute("content-width", |
412 |
(picture.getDxaGoal() / WordToFoUtils.TWIPS_PER_PT) + "pt"); |
413 |
|
414 |
if (aspectRatioY > 0) |
415 |
graphicElement |
416 |
.setAttribute("content-height", ((picture.getDyaGoal() |
417 |
* aspectRatioY / 100) / WordToFoUtils.TWIPS_PER_PT) |
418 |
+ "pt"); |
419 |
else |
420 |
graphicElement.setAttribute("content-height", |
421 |
(picture.getDyaGoal() / WordToFoUtils.TWIPS_PER_PT) + "pt"); |
422 |
|
423 |
if (aspectRatioX <= 0 || aspectRatioY <= 0) { |
424 |
graphicElement.setAttribute("scaling", "uniform"); |
425 |
} else { |
426 |
graphicElement.setAttribute("scaling", "non-uniform"); |
427 |
} |
428 |
|
429 |
graphicElement.setAttribute("vertical-align", "text-bottom"); |
430 |
|
431 |
if (picture.getDyaCropTop() != 0 || picture.getDxaCropRight() != 0 |
432 |
|| picture.getDyaCropBottom() != 0 |
433 |
|| picture.getDxaCropLeft() != 0) { |
434 |
int rectTop = picture.getDyaCropTop() / WordToFoUtils.TWIPS_PER_PT; |
435 |
int rectRight = picture.getDxaCropRight() |
436 |
/ WordToFoUtils.TWIPS_PER_PT; |
437 |
int rectBottom = picture.getDyaCropBottom() |
438 |
/ WordToFoUtils.TWIPS_PER_PT; |
439 |
int rectLeft = picture.getDxaCropLeft() |
440 |
/ WordToFoUtils.TWIPS_PER_PT; |
441 |
graphicElement.setAttribute("clip", "rect(" + rectTop + "pt, " |
442 |
+ rectRight + "pt, " + rectBottom + "pt, " + rectLeft |
443 |
+ "pt)"); |
444 |
graphicElement.setAttribute("oveerflow", "hidden"); |
445 |
} |
446 |
} |
447 |
|
402 |
public static void setTableCellProperties(TableRow tableRow, |
448 |
public static void setTableCellProperties(TableRow tableRow, |
403 |
TableCell tableCell, Element element, boolean toppest, |
449 |
TableCell tableCell, Element element, boolean toppest, |
404 |
boolean bottomest, boolean leftest, boolean rightest) { |
450 |
boolean bottomest, boolean leftest, boolean rightest) { |