Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/LibrePDF/OpenPDF
Browse files Browse the repository at this point in the history
  • Loading branch information
andreasrosdal committed Jun 24, 2019
2 parents 2d6822b + 4918595 commit e13fa2e
Show file tree
Hide file tree
Showing 37 changed files with 405 additions and 5,478 deletions.
72 changes: 72 additions & 0 deletions openpdf/src/main/java/com/lowagie/text/StandardFonts.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package com.lowagie.text;

import com.lowagie.text.pdf.BaseFont;

import java.io.IOException;

public enum StandardFonts {
// Courier
COURIER(Font.COURIER, Font.NORMAL),
COURIER_ITALIC(Font.COURIER, Font.ITALIC),
COURIER_BOLD(Font.COURIER, Font.BOLD),
COURIER_BOLDITALIC(Font.COURIER, Font.BOLDITALIC),
// Liberation Mono - Courier compatible
LIBERATION_MONO("com/lowagie/text/pdf/fonts/liberation/LiberationMono-Regular.ttf"),
LIBERATION_MONO_ITALIC("com/lowagie/text/pdf/fonts/liberation/LiberationMono-Italic.ttf"),
LIBERATION_MONO_BOLD("com/lowagie/text/pdf/fonts/liberation/LiberationMono-Bold.ttf"),
LIBERATION_MONO_BOLDITALIC("com/lowagie/text/pdf/fonts/liberation/LiberationMono-BoldItalic.ttf"),
// Helvetica
HELVETICA(Font.HELVETICA, Font.NORMAL),
HELVETICA_ITALIC(Font.HELVETICA, Font.ITALIC),
HELVETICA_BOLD(Font.HELVETICA, Font.BOLD),
HELVETICA_BOLDITALIC(Font.HELVETICA, Font.BOLDITALIC),
// Liberation Sans - Helvetica/Arial compatible
LIBERATION_SANS("com/lowagie/text/pdf/fonts/liberation/LiberationSans-Regular.ttf"),
LIBERATION_SANS_ITALIC("com/lowagie/text/pdf/fonts/liberation/LiberationSans-Italic.ttf"),
LIBERATION_SANS_BOLD("com/lowagie/text/pdf/fonts/liberation/LiberationSans-Bold.ttf"),
LIBERATION_SANS_BOLDITALIC("com/lowagie/text/pdf/fonts/liberation/LiberationSans-BoldItalic.ttf"),
// Times
TIMES(Font.TIMES_ROMAN, Font.NORMAL),
TIMES_ITALIC(Font.TIMES_ROMAN, Font.ITALIC),
TIMES_BOLD(Font.TIMES_ROMAN, Font.BOLD),
TIMES_BOLDITALIC(Font.TIMES_ROMAN, Font.BOLDITALIC),
// Liberation Serif - Times compatible
LIBERATION_SERIF("com/lowagie/text/pdf/fonts/liberation/LiberationSerif-Regular.ttf"),
LIBERATION_SERIF_ITALIC("com/lowagie/text/pdf/fonts/liberation/LiberationSerif-Italic.ttf"),
LIBERATION_SERIF_BOLD("com/lowagie/text/pdf/fonts/liberation/LiberationSerif-Bold.ttf"),
LIBERATION_SERIF_BOLDITALIC("com/lowagie/text/pdf/fonts/liberation/LiberationSerif-BoldItalic.ttf"),
// Others
SYMBOL(Font.SYMBOL, -1),
ZAPFDINGBATS(Font.ZAPFDINGBATS, -1),
;

private int family;
private int style;
private String trueTypeFile;

StandardFonts(int family, int style) {
this.family = family;
this.style = style;
}

StandardFonts(String trueTypeFile) {
this.trueTypeFile = trueTypeFile;
}

public Font create() throws IOException {
return create(Font.DEFAULTSIZE);
}

public Font create(int size) throws IOException {
final Font font;
if (trueTypeFile != null) {
final BaseFont baseFont = BaseFont.createFont(trueTypeFile, BaseFont.IDENTITY_H, false);
font = new Font(baseFont, size);
} else if (style == -1) {
font = new Font(family, size);
} else {
font = new Font(family, size, style);
}
return font;
}
}
50 changes: 27 additions & 23 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfGraphics2D.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import com.lowagie.text.pdf.internal.PolylineShape;
Expand Down Expand Up @@ -377,29 +378,32 @@ public void drawString(String s, float x, float y) {
cb.beginText();
cb.setFontAndSize(baseFont, fontSize);
// Check if we need to simulate an italic font.
// When there are different fonts for italic, bold, italic bold
// the font.getName() will be different from the font.getFontName()
// value. When they are the same value then we are normally dealing
// with a single font that has been made into an italic or bold
// font.
if (font.isItalic() && font.getFontName().equals(font.getName())) {
float angle = baseFont.getFontDescriptor(BaseFont.ITALICANGLE, 1000);
float angle2 = font.getItalicAngle();
// We don't have an italic version of this font so we need
// to set the font angle ourselves to produce an italic font.
if (angle2 == 0) {
// The JavaVM didn't have an angle setting for making
// the font an italic font so use a default of
// italic angle of 15 degrees.
angle2 = 15.0f;
} else {
// This sign of the angle for Java and PDF seams
// seams to be reversed.
angle2 = -angle2;
}
if (angle == 0) {
mx[2] = angle2 / 100.0f;
}
if (font.isItalic()) {
float angle = baseFont.getFontDescriptor(BaseFont.ITALICANGLE, 1000);
float angle2 = font.getItalicAngle();
// When there are different fonts for italic, bold, italic bold
// the font.getName() will be different from the font.getFontName()
// value. When they are the same value then we are normally dealing
// with a single font that has been made into an italic or bold
// font. When there are only a plain and a bold font available,
// we need to enter this logic too.
if (Objects.equals(font.getFontName(), font.getName()) || (angle == 0f && angle2 == 0f)) {
// We don't have an italic version of this font so we need
// to set the font angle ourselves to produce an italic font.
if (angle2 == 0) {
// The JavaVM didn't have an angle setting for making
// the font an italic font so use a default of
// italic angle of 15 degrees.
angle2 = 15.0f;
} else {
// This sign of the angle for Java and PDF seams
// seams to be reversed.
angle2 = -angle2;
}
if (angle == 0) {
mx[2] = angle2 / 100.0f;
}
}
}
cb.setTextMatrix((float)mx[0], (float)mx[1], (float)mx[2], (float)mx[3], (float)mx[4], (float)mx[5]);
Float fontTextAttributeWidth = (Float)font.getAttributes().get(TextAttribute.WIDTH);
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.

This file was deleted.

Loading

0 comments on commit e13fa2e

Please sign in to comment.