feat: pdf export in word processor
This commit is contained in:
@@ -29,6 +29,42 @@ static void wp_open_print_dialog(WordProcessorState* wp) {
|
||||
wp_set_status(wp, msg);
|
||||
}
|
||||
|
||||
static void wp_make_pdf_suggested_name(WordProcessorState* wp, char* out, int out_len) {
|
||||
if (!out || out_len <= 0) return;
|
||||
|
||||
const char* src = (wp && wp->filename[0]) ? wp->filename : "document";
|
||||
int last_dot = -1;
|
||||
for (int i = 0; src[i]; i++) {
|
||||
if (src[i] == '.') last_dot = i;
|
||||
}
|
||||
|
||||
int copy_len = (last_dot > 0) ? last_dot : montauk::slen(src);
|
||||
if (copy_len > out_len - 5) copy_len = out_len - 5;
|
||||
if (copy_len < 0) copy_len = 0;
|
||||
montauk::memcpy(out, src, (uint64_t)copy_len);
|
||||
out[copy_len] = '\0';
|
||||
montauk::strncpy(out + copy_len, ".pdf", out_len - copy_len - 1);
|
||||
out[out_len - 1] = '\0';
|
||||
}
|
||||
|
||||
static void wp_open_export_dialog(WordProcessorState* wp) {
|
||||
char path[256] = {};
|
||||
char suggested_name[128] = {};
|
||||
char msg[160] = {};
|
||||
|
||||
wp_make_pdf_suggested_name(wp, suggested_name, sizeof(suggested_name));
|
||||
if (dialogs::save_file("Export PDF",
|
||||
wp->filepath,
|
||||
suggested_name,
|
||||
path, sizeof(path),
|
||||
msg, sizeof(msg))) {
|
||||
if (wp_export_pdf_document(wp, path, msg, sizeof(msg)) || msg[0])
|
||||
wp_set_status(wp, msg);
|
||||
} else if (msg[0]) {
|
||||
wp_set_status(wp, msg);
|
||||
}
|
||||
}
|
||||
|
||||
static void wp_commit_pathbar(WordProcessorState* wp) {
|
||||
if (!wp->pathbar_text[0]) return;
|
||||
if (wp->pathbar_save_mode) {
|
||||
@@ -227,6 +263,10 @@ void wp_handle_mouse(const Montauk::WinEvent& ev) {
|
||||
wp_open_print_dialog(wp);
|
||||
return;
|
||||
}
|
||||
if (local_x >= WP_BTN_EXPORT_X && local_x < WP_BTN_EXPORT_X + 24 && local_y >= 6 && local_y < 30) {
|
||||
wp_open_export_dialog(wp);
|
||||
return;
|
||||
}
|
||||
if (local_x >= WP_BTN_UNDO_X && local_x < WP_BTN_UNDO_X + 24 && local_y >= 6 && local_y < 30) {
|
||||
wp_close_dropdowns(wp);
|
||||
wp_undo(wp);
|
||||
@@ -425,7 +465,11 @@ void wp_handle_key(const Montauk::KeyEvent& key) {
|
||||
wp_open_pathbar_for_open(wp);
|
||||
return;
|
||||
}
|
||||
if (key.ctrl && (key.ascii == 'p' || key.ascii == 'P')) {
|
||||
if (key.ctrl && key.alt && (key.ascii == 'p' || key.ascii == 'P')) {
|
||||
wp_open_export_dialog(wp);
|
||||
return;
|
||||
}
|
||||
if (key.ctrl && !key.alt && (key.ascii == 'p' || key.ascii == 'P')) {
|
||||
wp_open_print_dialog(wp);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ WPFontTable g_wp_fonts = { {{nullptr}}, false };
|
||||
SvgIcon g_icon_folder = {};
|
||||
SvgIcon g_icon_save = {};
|
||||
SvgIcon g_icon_print = {};
|
||||
SvgIcon g_icon_export_pdf = {};
|
||||
SvgIcon g_icon_undo = {};
|
||||
SvgIcon g_icon_redo = {};
|
||||
SvgIcon g_icon_align_left = {};
|
||||
@@ -34,6 +35,11 @@ void wp_load_icons() {
|
||||
g_icon_save = svg_load("0:/icons/document-save-symbolic.svg", 16, 16, def_color);
|
||||
if (!g_icon_print.pixels)
|
||||
g_icon_print = svg_load("0:/icons/printer-symbolic.svg", 16, 16, def_color);
|
||||
if (!g_icon_export_pdf.pixels) {
|
||||
g_icon_export_pdf = svg_load("0:/icons/document-export-symbolic.svg", 16, 16, def_color);
|
||||
if (!g_icon_export_pdf.pixels)
|
||||
g_icon_export_pdf = svg_load("0:/icons/text-x-generic-symbolic.svg", 16, 16, def_color);
|
||||
}
|
||||
if (!g_icon_undo.pixels)
|
||||
g_icon_undo = svg_load("0:/icons/edit-undo-symbolic.svg", 16, 16, def_color);
|
||||
if (!g_icon_redo.pixels)
|
||||
@@ -59,6 +65,7 @@ void wp_cleanup_state() {
|
||||
if (g_icon_folder.pixels) svg_free(g_icon_folder);
|
||||
if (g_icon_save.pixels) svg_free(g_icon_save);
|
||||
if (g_icon_print.pixels) svg_free(g_icon_print);
|
||||
if (g_icon_export_pdf.pixels) svg_free(g_icon_export_pdf);
|
||||
if (g_icon_undo.pixels) svg_free(g_icon_undo);
|
||||
if (g_icon_redo.pixels) svg_free(g_icon_redo);
|
||||
if (g_icon_align_left.pixels) svg_free(g_icon_align_left);
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -208,7 +208,10 @@ void wp_render() {
|
||||
if (g_icon_print.pixels)
|
||||
c.icon(WP_BTN_PRINT_X + 4, 10, g_icon_print);
|
||||
|
||||
c.vline(WP_BTN_PRINT_X + 28, 4, 28, colors::BORDER);
|
||||
wp_draw_ui_icon_button(c, WP_BTN_EXPORT_X, 6, 24, 24, g_icon_export_pdf, "P",
|
||||
btn_bg, colors::TEXT_COLOR);
|
||||
|
||||
c.vline(WP_BTN_EXPORT_X + 28, 4, 28, colors::BORDER);
|
||||
|
||||
wp_draw_ui_icon_button(c, WP_BTN_UNDO_X, 6, 24, 24, g_icon_undo, "U", btn_bg, colors::TEXT_COLOR);
|
||||
wp_draw_ui_icon_button(c, WP_BTN_REDO_X, 6, 24, 24, g_icon_redo, "R", btn_bg, colors::TEXT_COLOR);
|
||||
|
||||
@@ -44,25 +44,26 @@ static constexpr int WP_LIST_MARKER_W = 20;
|
||||
static constexpr int WP_BTN_OPEN_X = 4;
|
||||
static constexpr int WP_BTN_SAVE_X = 32;
|
||||
static constexpr int WP_BTN_PRINT_X = 60;
|
||||
static constexpr int WP_BTN_UNDO_X = 94;
|
||||
static constexpr int WP_BTN_REDO_X = 122;
|
||||
static constexpr int WP_BTN_BOLD_X = 156;
|
||||
static constexpr int WP_BTN_ITALIC_X = 184;
|
||||
static constexpr int WP_FONT_DD_X = 216;
|
||||
static constexpr int WP_BTN_EXPORT_X = 88;
|
||||
static constexpr int WP_BTN_UNDO_X = 122;
|
||||
static constexpr int WP_BTN_REDO_X = 150;
|
||||
static constexpr int WP_BTN_BOLD_X = 184;
|
||||
static constexpr int WP_BTN_ITALIC_X = 212;
|
||||
static constexpr int WP_FONT_DD_X = 244;
|
||||
static constexpr int WP_FONT_DD_W = 74;
|
||||
static constexpr int WP_SIZE_DD_X = 296;
|
||||
static constexpr int WP_SIZE_DD_X = 324;
|
||||
static constexpr int WP_SIZE_DD_W = 36;
|
||||
static constexpr int WP_BTN_ALIGN_L_X = 344;
|
||||
static constexpr int WP_BTN_ALIGN_C_X = 372;
|
||||
static constexpr int WP_BTN_ALIGN_R_X = 400;
|
||||
static constexpr int WP_BTN_BULLET_X = 432;
|
||||
static constexpr int WP_BTN_NUMBER_X = 460;
|
||||
static constexpr int WP_BTN_OUTDENT_X = 496;
|
||||
static constexpr int WP_BTN_INDENT_X = 524;
|
||||
static constexpr int WP_LINE_DD_X = 558;
|
||||
static constexpr int WP_BTN_ALIGN_L_X = 372;
|
||||
static constexpr int WP_BTN_ALIGN_C_X = 400;
|
||||
static constexpr int WP_BTN_ALIGN_R_X = 428;
|
||||
static constexpr int WP_BTN_BULLET_X = 460;
|
||||
static constexpr int WP_BTN_NUMBER_X = 488;
|
||||
static constexpr int WP_BTN_OUTDENT_X = 524;
|
||||
static constexpr int WP_BTN_INDENT_X = 552;
|
||||
static constexpr int WP_LINE_DD_X = 586;
|
||||
static constexpr int WP_LINE_DD_W = 48;
|
||||
static constexpr int WP_BTN_DIVIDER_X = 614;
|
||||
static constexpr int WP_BTN_SECTION_X = 646;
|
||||
static constexpr int WP_BTN_DIVIDER_X = 642;
|
||||
static constexpr int WP_BTN_SECTION_X = 674;
|
||||
static constexpr int WP_DIVIDER_ROW_H = 24;
|
||||
static constexpr int WP_DIVIDER_FLYOUT_W = 216;
|
||||
static constexpr int WP_SPECIAL_CHAR_ROW_H = 24;
|
||||
@@ -371,6 +372,7 @@ extern WPFontTable g_wp_fonts;
|
||||
extern SvgIcon g_icon_folder;
|
||||
extern SvgIcon g_icon_save;
|
||||
extern SvgIcon g_icon_print;
|
||||
extern SvgIcon g_icon_export_pdf;
|
||||
extern SvgIcon g_icon_undo;
|
||||
extern SvgIcon g_icon_redo;
|
||||
extern SvgIcon g_icon_align_left;
|
||||
@@ -441,6 +443,7 @@ bool wp_undo(WordProcessorState* wp);
|
||||
bool wp_redo(WordProcessorState* wp);
|
||||
|
||||
bool wp_print_document(WordProcessorState* wp, char* out_status, int out_status_len);
|
||||
bool wp_export_pdf_document(WordProcessorState* wp, const char* path, char* out_status, int out_status_len);
|
||||
|
||||
void wp_render();
|
||||
void wp_handle_mouse(const Montauk::WinEvent& ev);
|
||||
|
||||
Reference in New Issue
Block a user