💄 fix formatting for project PDF export
This commit is contained in:
@@ -395,6 +395,7 @@ export function registerIpcHandlers(): void {
|
||||
pageFrom: number | null
|
||||
pageTo: number | null
|
||||
font: 'courier' | 'times' | 'georgia'
|
||||
fontSize: number
|
||||
pageSize: 'letter' | 'a4'
|
||||
titleOnFirstPage: boolean
|
||||
boldHeadings: boolean
|
||||
@@ -455,7 +456,7 @@ export function registerIpcHandlers(): void {
|
||||
@page { size: ${pageSizeCss}; }
|
||||
body {
|
||||
font-family: ${fontFamily};
|
||||
font-size: 12pt;
|
||||
font-size: ${opts.fontSize}pt;
|
||||
line-height: 1.5;
|
||||
color: #000;
|
||||
margin: 0;
|
||||
@@ -482,7 +483,7 @@ export function registerIpcHandlers(): void {
|
||||
text-align: center;
|
||||
line-height: 2;
|
||||
}
|
||||
.cover-title { font-size: 12pt; text-transform: uppercase; margin: 0; }
|
||||
.cover-title { font-size: ${opts.fontSize}pt; text-transform: uppercase; margin: 0; }
|
||||
.cover-by { margin: 0; }
|
||||
.cover-byline{ margin: 0; }
|
||||
`
|
||||
@@ -577,9 +578,9 @@ export function registerIpcHandlers(): void {
|
||||
// CSS shared by chapter/part sections — cover page uses its own CSS (set above).
|
||||
const pageCSS = `
|
||||
@page { size: ${pageSizeCss}; }
|
||||
body { font-family: ${fontFamily}; font-size: 12pt; line-height: 2; color: #000; margin: 0; padding: 0; }
|
||||
h1 { font-weight: bold; font-size: 14pt; text-align: center; text-transform: uppercase; margin: 0; line-height: 2; }
|
||||
h2, h3 { font-weight: ${headingWeight}; font-size: 12pt; text-align: center; text-transform: uppercase; margin: 0; line-height: 2; }
|
||||
body { font-family: ${fontFamily}; font-size: ${opts.fontSize}pt; line-height: 2; color: #000; margin: 0; padding: 0; }
|
||||
h1 { font-weight: bold; font-size: ${opts.fontSize + 2}pt; text-align: center; text-transform: uppercase; margin: 0; line-height: 2; }
|
||||
h2, h3 { font-weight: ${headingWeight}; font-size: ${opts.fontSize}pt; text-align: center; text-transform: uppercase; margin: 0; line-height: 2; }
|
||||
p { margin: 0; text-indent: 0.5in; text-align: left; }
|
||||
h1 + p, h2 + p, h3 + p, hr + p, .chapter > p:first-child { text-indent: 0; }
|
||||
hr { border: none; margin: 0; height: 2em; text-align: center; }
|
||||
@@ -590,7 +591,7 @@ export function registerIpcHandlers(): void {
|
||||
ul, ol { margin: 0 0 0 0.5in; }
|
||||
li { margin: 0; }
|
||||
.chapter { padding-top: 2.5in; }
|
||||
.part-heading { font-family: ${fontFamily}; font-weight: bold; font-size: 14pt; text-align: center; text-transform: uppercase; letter-spacing: 0.15em; margin: 0; line-height: 2; }
|
||||
.part-heading { font-family: ${fontFamily}; font-weight: bold; font-size: ${opts.fontSize + 2}pt; text-align: center; text-transform: uppercase; letter-spacing: 0.15em; margin: 0; line-height: 2; }
|
||||
`
|
||||
|
||||
// Print each section to its own PDF buffer. Cover page uses its own CSS;
|
||||
@@ -642,6 +643,7 @@ export function registerIpcHandlers(): void {
|
||||
for (let i = 0; i < allPages.length; i++) {
|
||||
if (pageOwners[i].isCover) continue // no header/number on cover page
|
||||
bodyPageNum++
|
||||
if (bodyPageNum === 1) continue // no running header on first body page
|
||||
const page = allPages[i]
|
||||
const { width, height } = page.getSize()
|
||||
const chapterUpper = pageOwners[i].title.toUpperCase()
|
||||
|
||||
@@ -10,6 +10,7 @@ export interface ExportOptions {
|
||||
pageFrom: number | null
|
||||
pageTo: number | null
|
||||
font: 'courier' | 'times' | 'georgia'
|
||||
fontSize: number
|
||||
pageSize: 'letter' | 'a4'
|
||||
titleOnFirstPage: boolean
|
||||
boldHeadings: boolean
|
||||
@@ -17,12 +18,12 @@ export interface ExportOptions {
|
||||
|
||||
const STORAGE_KEY = 'exportDialogPrefs'
|
||||
|
||||
function loadPrefs(): Pick<ExportOptions, 'romanNumerals' | 'showChapterTitle' | 'includeCover' | 'includeFrontMatter' | 'includePartSeparators' | 'font' | 'pageSize' | 'titleOnFirstPage' | 'boldHeadings'> {
|
||||
function loadPrefs(): Pick<ExportOptions, 'romanNumerals' | 'showChapterTitle' | 'includeCover' | 'includeFrontMatter' | 'includePartSeparators' | 'font' | 'fontSize' | 'pageSize' | 'titleOnFirstPage' | 'boldHeadings'> {
|
||||
try {
|
||||
const raw = localStorage.getItem(STORAGE_KEY)
|
||||
if (raw) return { font: 'courier', pageSize: 'letter', titleOnFirstPage: false, boldHeadings: false, includePartSeparators: true, ...JSON.parse(raw) }
|
||||
if (raw) return { font: 'courier', fontSize: 12, pageSize: 'letter', titleOnFirstPage: false, boldHeadings: false, includePartSeparators: true, ...JSON.parse(raw) }
|
||||
} catch { /* ignore */ }
|
||||
return { romanNumerals: true, showChapterTitle: false, includeCover: true, includeFrontMatter: true, includePartSeparators: true, font: 'courier', pageSize: 'letter', titleOnFirstPage: false, boldHeadings: false }
|
||||
return { romanNumerals: true, showChapterTitle: false, includeCover: true, includeFrontMatter: true, includePartSeparators: true, font: 'courier', fontSize: 12, pageSize: 'letter', titleOnFirstPage: false, boldHeadings: false }
|
||||
}
|
||||
|
||||
interface Props {
|
||||
@@ -38,6 +39,7 @@ export function ExportDialog({ onClose, onExport }: Props): JSX.Element {
|
||||
const [includeFrontMatter, setIncludeFrontMatter] = useState(prefs.includeFrontMatter)
|
||||
const [includePartSeparators, setIncludePartSeparators] = useState(prefs.includePartSeparators)
|
||||
const [font, setFont] = useState(prefs.font)
|
||||
const [fontSize, setFontSize] = useState(prefs.fontSize)
|
||||
const [pageSize, setPageSize] = useState(prefs.pageSize)
|
||||
const [titleOnFirstPage, setTitleOnFirstPage] = useState(prefs.titleOnFirstPage)
|
||||
const [boldHeadings, setBoldHeadings] = useState(prefs.boldHeadings)
|
||||
@@ -58,14 +60,14 @@ export function ExportDialog({ onClose, onExport }: Props): JSX.Element {
|
||||
}
|
||||
|
||||
const savePrefs = (patch: Partial<typeof prefs>): void => {
|
||||
const next = { romanNumerals, showChapterTitle, includeCover, includeFrontMatter, includePartSeparators, font, pageSize, titleOnFirstPage, boldHeadings, ...patch }
|
||||
const next = { romanNumerals, showChapterTitle, includeCover, includeFrontMatter, includePartSeparators, font, fontSize, pageSize, titleOnFirstPage, boldHeadings, ...patch }
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(next))
|
||||
}
|
||||
|
||||
const handleExport = (): void => {
|
||||
const from = pageFrom.trim() ? parseInt(pageFrom, 10) : null
|
||||
const to = pageTo.trim() ? parseInt(pageTo, 10) : null
|
||||
onExport({ romanNumerals, showChapterTitle, includeCover, includeFrontMatter, includePartSeparators, pageFrom: from, pageTo: to, font, pageSize, titleOnFirstPage, boldHeadings })
|
||||
onExport({ romanNumerals, showChapterTitle, includeCover, includeFrontMatter, includePartSeparators, pageFrom: from, pageTo: to, font, fontSize, pageSize, titleOnFirstPage, boldHeadings })
|
||||
}
|
||||
|
||||
const pageRangeValid = (): boolean => {
|
||||
@@ -151,6 +153,19 @@ export function ExportDialog({ onClose, onExport }: Props): JSX.Element {
|
||||
<option value="georgia">Georgia</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="settings-field export-format-field">
|
||||
<span className="settings-label">Font size</span>
|
||||
<select
|
||||
className="settings-input"
|
||||
value={fontSize}
|
||||
onChange={e => { const v = parseInt(e.target.value, 10); setFontSize(v); savePrefs({ fontSize: v }) }}
|
||||
>
|
||||
<option value={11}>11pt</option>
|
||||
<option value={12}>12pt</option>
|
||||
<option value={13}>13pt</option>
|
||||
<option value={14}>14pt</option>
|
||||
</select>
|
||||
</div>
|
||||
<div className="settings-field export-format-field">
|
||||
<span className="settings-label">Page size</span>
|
||||
<select
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user