.
This commit is contained in:
@@ -28,18 +28,45 @@ public class ResearchPdfService {
|
|||||||
* Убедитесь, что файл шрифта DejaVuSans.ttf находится в /resources/fonts/
|
* Убедитесь, что файл шрифта DejaVuSans.ttf находится в /resources/fonts/
|
||||||
*/
|
*/
|
||||||
public ResearchPdfService() {
|
public ResearchPdfService() {
|
||||||
|
BaseFont resolvedBaseFont;
|
||||||
try {
|
try {
|
||||||
// Загружаем шрифт, поддерживающий кириллицу. Это КЛЮЧЕВОЕ изменение.
|
// Пытаемся загрузить шрифт из classpath (работает внутри fat JAR)
|
||||||
this.baseFont = BaseFont.createFont("fonts/DejaVuSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
|
java.io.InputStream is = Thread.currentThread().getContextClassLoader()
|
||||||
this.titleFont = new Font(baseFont, 18, Font.BOLD);
|
.getResourceAsStream("fonts/DejaVuSans.ttf");
|
||||||
this.headingFont = new Font(baseFont, 14, Font.BOLD);
|
if (is != null) {
|
||||||
this.subheadingFont = new Font(baseFont, 12, Font.BOLD);
|
try (is) {
|
||||||
this.normalFont = new Font(baseFont, 10, Font.NORMAL);
|
byte[] fontBytes = is.readAllBytes();
|
||||||
this.smallFont = new Font(baseFont, 8, Font.ITALIC);
|
resolvedBaseFont = BaseFont.createFont(
|
||||||
this.linkFont = new Font(baseFont, 8, Font.UNDERLINE);
|
"DejaVuSans.ttf",
|
||||||
|
BaseFont.IDENTITY_H,
|
||||||
|
BaseFont.EMBEDDED,
|
||||||
|
false,
|
||||||
|
fontBytes,
|
||||||
|
null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Фолбэк: пробуем загрузить по файловому пути (на случай, если ресурс не
|
||||||
|
// упакован)
|
||||||
|
resolvedBaseFont = BaseFont.createFont("fonts/DejaVuSans.ttf", BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException("Failed to load font", e);
|
// Фолбэк на стандартный шрифт, чтобы не падал бином (кириллица может
|
||||||
|
// отображаться некорректно)
|
||||||
|
try {
|
||||||
|
resolvedBaseFont = BaseFont.createFont(BaseFont.HELVETICA, BaseFont.WINANSI, BaseFont.NOT_EMBEDDED);
|
||||||
|
System.err.println("ResearchPdfService: DejaVuSans.ttf not found. Falling back to Helvetica.");
|
||||||
|
} catch (Exception inner) {
|
||||||
|
throw new RuntimeException("Failed to load font", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.baseFont = resolvedBaseFont;
|
||||||
|
this.titleFont = new Font(baseFont, 18, Font.BOLD);
|
||||||
|
this.headingFont = new Font(baseFont, 14, Font.BOLD);
|
||||||
|
this.subheadingFont = new Font(baseFont, 12, Font.BOLD);
|
||||||
|
this.normalFont = new Font(baseFont, 10, Font.NORMAL);
|
||||||
|
this.smallFont = new Font(baseFont, 8, Font.ITALIC);
|
||||||
|
this.linkFont = new Font(baseFont, 8, Font.UNDERLINE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user