Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions crates/hwp-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ pub enum Cmd {
/// (md) 숨은 설명 텍스트도 포함 (기본: 제외)
#[arg(long = "with-hidden")]
with_hidden: bool,
/// (pdf) 추가 폰트 디렉터리 (반복 가능, 기본: HWP_FONT_DIR 또는 fonts/)
#[arg(long)]
font_dir: Vec<PathBuf>,
},

/// 페이지 렌더링
Expand Down
17 changes: 10 additions & 7 deletions crates/hwp-cli/src/commands/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! M2 범위: hwp/hwpx → markdown/JSON. hwpx 쓰기(M4)와 hwp 쓰기(M6)는
//! 이후 마일스톤.

use std::path::Path;
use std::path::{Path, PathBuf};

use crate::commands::cat::load_document;
use hwp_cli::cli::ConvertFormat;
Expand All @@ -19,6 +19,7 @@ pub struct MdOpts<'a> {
pub with_hidden: bool,
}

#[allow(clippy::too_many_arguments)]
pub fn run(
input: &Path,
output: &Path,
Expand All @@ -27,6 +28,7 @@ pub fn run(
preserve_layout: bool,
embed_bin: bool,
md_opts: &MdOpts,
font_dirs: Vec<PathBuf>,
) -> anyhow::Result<()> {
// PDF는 문서 포맷 변환이 아니라 렌더 출력 — render 경로에 위임한다
// (사용자의 "변환" 프레이밍 대응: `hwp convert in.hwp -o out.pdf`).
Expand All @@ -42,7 +44,7 @@ pub fn run(
"all",
96.0,
Some(hwp_cli::cli::RenderFormat::Pdf),
Vec::new(),
font_dirs,
);
}

Expand Down Expand Up @@ -101,7 +103,7 @@ pub fn run(
}
ConvertFormat::Pdf => {
let doc = load_document(input)?;
let result = hwp_render::render_document_pdf(&doc, &pdf_render_opts(), None)?;
let result = hwp_render::render_document_pdf(&doc, &pdf_render_opts(font_dirs), None)?;
print_warnings(&result.report);
std::fs::write(output, &result.data)?;
}
Expand Down Expand Up @@ -209,7 +211,7 @@ pub fn write_by_ext(
Vec::new()
}
Some("pdf") => {
let result = hwp_render::render_document_pdf(doc, &pdf_render_opts(), None)?;
let result = hwp_render::render_document_pdf(doc, &pdf_render_opts(Vec::new()), None)?;
std::fs::write(output, &result.data)?;
result.report
}
Expand All @@ -231,11 +233,12 @@ pub fn resolve_font_dirs(given: Vec<std::path::PathBuf>) -> Vec<std::path::PathB
)]
}

/// PDF 렌더 옵션 — 폰트는 `HWP_FONT_DIR`(없으면 `fonts/`)에서 해석.
fn pdf_render_opts() -> hwp_render::RenderOptions {
/// PDF 렌더 옵션 — 폰트는 `given`(`--font-dir`)이 비었으면 `HWP_FONT_DIR`
/// (없으면 `fonts/`)에서 해석.
fn pdf_render_opts(given: Vec<PathBuf>) -> hwp_render::RenderOptions {
hwp_render::RenderOptions {
dpi: 96.0,
font_dirs: resolve_font_dirs(Vec::new()),
font_dirs: resolve_font_dirs(given),
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/hwp-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ fn main() -> anyhow::Result<()> {
media_dir,
with_header_footer,
with_hidden,
font_dir,
} => commands::convert::run(
&input,
&output,
Expand All @@ -58,6 +59,7 @@ fn main() -> anyhow::Result<()> {
with_header_footer,
with_hidden,
},
font_dir,
),
Cmd::Render {
input,
Expand Down
1 change: 1 addition & 0 deletions docs/manual/cli-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
| `--media-dir` | `<MEDIA_DIR>` | | (md) 이미지 추출 디렉터리 — 기본 "<출력스템>.media". 상대경로는 출력 파일 기준으로 해석하고 링크는 입력한 경로 그대로 쓴다 (예: figs) |
| `--with-header-footer` | | | (md) 머리말/꼬리말 텍스트도 포함 (기본: 제외) |
| `--with-hidden` | | | (md) 숨은 설명 텍스트도 포함 (기본: 제외) |
| `--font-dir` | `<FONT_DIR>` | | (pdf) 추가 폰트 디렉터리 (반복 가능, 기본: HWP_FONT_DIR 또는 fonts/) |

## `hwp render`

Expand Down
Loading