![Laughing :lol:](./images/smilies/icon_lol.gif)
The MS Gothic font was chosen because several other fonts simply refused to load, causing failure HPDF_INVALID_FONT_NAME.
Latest LIBHPDF.ahk library (some constants was added, also cosmetic and QoL changes)
Code: Select all
HPDF_Page_SetSlideShow(hPage, type, disp_time, trans_time) => DllCall("libhpdf\HPDF_Free", "Ptr", hPage, "Int", type, "Float", disp_time, "Float", trans_time, "UInt")
Code: Select all
HPDF_Page_SetSlideShow(hPage, type, disp_time, trans_time) => DllCall("libhpdf\HPDF_Page_SetSlideShow", "Ptr", hPage, "Int", type, "Float", disp_time, "Float", trans_time, "UInt")
Code: Select all
HPDF_Page_CreateLinkAnnot(hPage, rect, dst) => DllCall("libhpdf\HPDF_Page_CreateLinkAnnot", "Ptr", hPage, "Ptr", rect, "Ptr", dst, "Ptr")
Code: Select all
#include "apdf.h"
HPDF_Annotation
HPDF_Page_CreateLinkAnnot (HPDF_Page page,
HPDF_Rect rect,
HPDF_Destination dst);
Code: Select all
HPDF_Page_CreateLinkAnnot(hPage, rect, dst) => DllCall("libhpdf\HPDF_Page_CreateLinkAnnot", "Ptr", hPage,
"Float", rect.left, "Float", rect.bottom,
"Float", rect.right, "Float", rect.top,
"Ptr", dst, "Ptr")
Excellent job my friend! Thank you very much!
Yep. This annoying bug come from V1 source. And no anyone had noticed him before...just me wrote: ↑10 Nov 2023, 06:17I've been quite sure that the libhpdf.dll is using __stdcall. So I removed the Cdecl from libhpdf.ahk.
After that i got an error for HPDF_Page_SetSlideShow(): Too many parameters or needs Cdecl. Looking at the function I found
I fixed the function name and it worked.
Very, very strange API. With an equally strange wrapper. A crutch on a crutch. And bugs.just me wrote: ↑10 Nov 2023, 06:17After that a new error was thrown by the error_handler: 0x1023 HPDF_INVALID_DESTINATION. It was caused by the HPDF_Page_CreateLinkAnnot() function call.
This function is dokumented as
The second parameter rect is expected to be passed by value, not as a pointer. That's also true for all other function expecting a HPDF_Rect structure. So I changed the function toThe demo is working now.Code: Select all
HPDF_Page_CreateLinkAnnot(hPage, rect, dst) => DllCall("libhpdf\HPDF_Page_CreateLinkAnnot", "Ptr", hPage, "Float", rect.left, "Float", rect.bottom, "Float", rect.right, "Float", rect.top, "Ptr", dst, "Ptr")
This could be my fault. Try library linked below (unpack to Libharu folder and confirm overwriting if asked):
Nope. Try this:
Code: Select all
/*
* << Haru Free PDF Library 2.0.0 >> -- character_map.c
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
* provided that the above copyright notice appear in all copies and
* that both that copyright notice and this permission notice appear
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
* usage character_map <encoding-name> <low-range-from> <low-range-to>
* <high-range-from> <high-range-to>
* ex. character_map 90ms-RKSJ-V 0x80 0x
*
*/
#Requires Autohotkey v2.0 32-bit
#include "Lib\LIBHPDF.ahk"
hDll := HPDF_LoadDLL(A_ScriptDir "\Lib\libhpdf.dll")
; printf('libhpdf version {:s}`n', HPDF_GetVersion())
main()
HPDF_UnloadDLL(hDll)
/* end of program */
Chr2(num) {
static ANSI := Buffer(3, 0), byte, btype
if ( Abs(num) >> 8 )
byte := 2, btype := 'UShort'
else
byte := 1, btype := 'UChar'
return StrGet(NumPut(btype, num, ANSI) - byte, byte, 0)
}
draw_page(pdf, page, title_font, font, h_byte, l_byte)
{
PAGE_WIDTH := 420
CELL_HEIGHT := 20
CELL_WIDTH := 20
idiv := Integer(l_byte / 16) ; /* <<< Float -> Integer */
l_byte := idiv * 16
h_count := 16 - idiv
page_height := 40 + 40 + (h_count + 1) * CELL_HEIGHT
HPDF_Page_SetHeight(page, page_height)
HPDF_Page_SetWidth(page, PAGE_WIDTH)
HPDF_Page_SetFontAndSize(page, title_font, 10)
ypos := h_count + 1
loop
{
y := ypos * CELL_HEIGHT + 40
HPDF_Page_MoveTo(page, 40, y)
HPDF_Page_LineTo(page, 380, y)
HPDF_Page_Stroke(page)
if (ypos < h_count)
{
; unsigned char buf[2];
; buf[0] = 16 - ypos - 1
; if (buf[0] < 10)
; buf[0] += '0'
; else
; buf[0] += ('A' - 10)
buf := 16 - ypos - 1
if (buf < 10)
buf += Ord('0')
else
buf += Ord('A') - 10
; buf[1] = 0
w := HPDF_Page_TextWidth(page, Chr2(buf))
HPDF_Page_BeginText(page)
HPDF_Page_MoveTextPos(page, 40 + (20 - w) / 2, y + 5)
HPDF_Page_ShowText(page, Chr2(buf))
HPDF_Page_EndText(page)
}
if (ypos = 0)
break
ypos--
}
; for (xpos = 0; xpos <= 17; xpos++)
loop 18
{
xpos := A_Index - 1 ; /* <<< actual index */
y := (h_count + 1) * CELL_HEIGHT + 40
x := xpos * CELL_WIDTH + 40
HPDF_Page_MoveTo(page, x, 40)
HPDF_Page_LineTo(page, x, y)
HPDF_Page_Stroke(page)
if (xpos > 0 && xpos <= 16)
{
; unsigned char buf[2];
; buf[0] = xpos - 1
; if (buf[0] < 10)
; buf[0] += '0'
; else
; buf[0] += ('A' - 10)
buf := xpos - 1
if (buf < 10)
buf += Ord('0')
else
buf += Ord('A') - 10
; buf[1] = 0
w := HPDF_Page_TextWidth(page, Chr2(buf))
HPDF_Page_BeginText(page)
HPDF_Page_MoveTextPos(page, x + (20 - w) / 2, h_count * CELL_HEIGHT + 45)
HPDF_Page_ShowText(page, Chr2(buf))
HPDF_Page_EndText(page)
}
}
HPDF_Page_SetFontAndSize(page, font, 15)
ypos := h_count
loop
{
y := (ypos - 1) * CELL_HEIGHT + 45
; for (xpos = 0; xpos < 16; xpos++)
loop 16
{
xpos := A_Index - 1 ; /* <<< actual index */
x := xpos * CELL_WIDTH + 40 + CELL_WIDTH
; unsigned char buf[3];
buf0 := h_byte
buf1 := (16 - ypos) * 16 + xpos
buf := (buf1 << 8) | buf0
; buf[2] := 0x00
_char := Chr2(buf)
w := HPDF_Page_TextWidth(page, _char)
if (w > 0)
{
HPDF_Page_BeginText(page)
HPDF_Page_MoveTextPos(page, x + (20 - w) / 2, y)
HPDF_Page_ShowText(page, _char)
HPDF_Page_EndText(page)
}
}
if (ypos = 0)
break
ypos--
}
}
main()
{
; HPDF_UINT16 flg[256];
flg := [], flg.Length := 256
SplitPath(A_ScriptName,,,, &NoExt)
fname := A_ScriptDir "\" NoExt ".pdf"
; if (argc < 3) {
; printf ("usage: character_map <encoding-name> <font-name>\n");
; return 1;
; }
argv := ["GBK-EUC-H", "MS-Gothic"]
pdf := HPDF_New(error_handler, NULL)
if (!pdf)
{
MsgBox("ERROR: cannot create PdfDoc object")
ExitApp(1)
}
/* configure pdf-document (showing outline, compression enabled) */
HPDF_SetPageMode(pdf, HPDF_PAGE_MODE_USE_OUTLINE)
HPDF_SetCompressionMode(pdf, HPDF_COMP_ALL)
HPDF_SetPagesConfiguration(pdf, 10)
HPDF_UseJPEncodings(pdf)
HPDF_UseJPFonts(pdf)
HPDF_UseKREncodings(pdf)
HPDF_UseKRFonts(pdf)
HPDF_UseCNSEncodings(pdf)
HPDF_UseCNSFonts(pdf)
HPDF_UseCNTEncodings(pdf)
HPDF_UseCNTFonts(pdf)
encoder := HPDF_GetEncoder(pdf, argv[1])
if (HPDF_Encoder_GetType(encoder) != HPDF_ENCODER_TYPE_DOUBLE_BYTE)
{
MsgBox(Format("ERROR: {:} is not cmap-encoder", argv[1]))
HPDF_Free(pdf)
ExitApp(1)
}
font := HPDF_GetFont(pdf, argv[2], argv[1])
min_l := 255
min_h := 256
max_l := 0
max_h := 0
loop 256
flg[A_Index] := 0
; for (i = 0; i <= 255; i++)
loop 256
{
i := A_Index - 1 ; /* <<< actual index */
; for (j = 20; j <= 255; j++)
loop 236
{
j := A_Index + 19 ; /* <<< actual index */
; unsigned char buf[3];
; HPDF_ByteType btype;
; HPDF_UINT16 code = i * 256 + j;
; HPDF_UNICODE unicode;
code := i * 256 + j
; buf[0] := i
; buf[1] := j
; buf[2] := 0
buf := i * 256 + j
; buf := (i << 8) | j
btype := HPDF_Encoder_GetByteType(encoder, Chr2(buf), 0) ; /* <<< Chr2(HPDF_UINT16) */
unicode := HPDF_Encoder_GetUnicode(encoder, code)
if (btype = HPDF_BYTE_TYPE_LEAD && unicode != 0x25A1)
{
if (min_l > j)
min_l := j
if (max_l < j)
max_l := j
if (min_h > i)
min_h := i
if (max_h < i)
max_h := i
flg[i + 1] := 1 ; /* <<< actual index */
}
}
}
OutputDebug(Format("min_h={:02X}00 max_h={:02X}00 min_l={:04X} max_l={:04X}`n", min_h, max_h, min_l, max_l))
/* create outline root */
root := HPDF_CreateOutline(pdf, NULL, argv[1], NULL)
HPDF_Outline_SetOpened(root, HPDF_TRUE)
; for (i = 0; i <= 255; i++)
loop 256
{
i := A_Index - 1 ; /* <<< actual index */
if (flg[A_Index]) ; /* <<< actual index */
{
; char buf[256];
buf := ""
page := HPDF_AddPage(pdf)
title_font := HPDF_GetFont(pdf, "Helvetica", NULL)
; _snprintf(buf, 256, "0x%04X-0x%04X", (i * 256 + min_l), (i * 256 + max_l))
buf := Format("0x{:04X}-0x{:04X}", (i * 256 + min_l), (i * 256 + max_l))
outline := HPDF_CreateOutline(pdf, root, buf, NULL)
dst := HPDF_Page_CreateDestination(page)
HPDF_Outline_SetDestination(outline, dst)
draw_page(pdf, page, title_font, font, i, min_l)
; _snprintf(buf, 256, "%s (%s) 0x%04X-0x%04X", argv[1], argv[2], (i * 256 + min_l), (i * 256 + max_l))
buf := Format("{:} ({:}) 0x{:04X}-0x{:04X}", argv[1], argv[2], (i * 256 + min_l), (i * 256 + max_l))
HPDF_Page_SetFontAndSize(page, title_font, 10)
HPDF_Page_BeginText(page)
HPDF_Page_MoveTextPos(page, 40, HPDF_Page_GetHeight(page) - 35)
HPDF_Page_ShowText(page, buf)
HPDF_Page_EndText(page)
}
}
HPDF_SaveToFile(pdf, fname)
HPDF_Free(pdf)
; return 0
}
Code: Select all
#
# << Haru Free PDF Library 2.0.0 >> -- font_example.rb
#
# Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
#
# Permission to use, copy, modify, distribute and sell this software
# and its documentation for any purpose is hereby granted without fee,
# provided that the above copyright notice appear in all copies and
# that both that copyright notice and this permission notice appear
# in supporting documentation.
# It is provided "as is" without express or implied warranty.
#
require "hpdf"
font_list = ["Courier", "Courier-Bold", "Courier-Oblique", "Courier-BoldOblique", "Helvetica", "Helvetica-Bold", "Helvetica-Oblique", "Helvetica-BoldOblique", "Times-Roman", "Times-Bold", "Times-Italic", "Times-BoldItalic", "Symbol", "ZapfDingbats", nil]
pdf = HPDFDoc.new
page = pdf.add_page
height = page.get_height
width = page.get_width
page.set_line_width(1.0)
page.rectangle(50.0, 50.0, width - 100.0, height - 110.0)
page.stroke
font1 = pdf.get_font("Helvetica", nil)
title = "Font Example"
page.set_font_and_size(font1, 24.0)
tw = page.text_width(title)
page.begin_text
page.text_out((width - tw) / 2, height - 50.0, title)
page.set_font_and_size(font1, 16.0)
page.text_out(60.0, height - 80.0, "<Standerd Type1 fonts samples>")
page.end_text
samp_text = "abcdefgABCDEFG12345!#$\%&+-@?"
page.begin_text
page.move_text_pos(60.0, height - 105.0)
i = 0
while font_list[i]
font2 = pdf.get_font(font_list[i], nil)
page.set_font_and_size(font1, 9.0)
page.show_text(font_list[i])
page.move_text_pos(0.0, -18.0)
page.set_font_and_size(font2, 20.0)
page.show_text(samp_text)
page.move_text_pos(0.0, -20.0)
i = i + 1
end
page.end_text
pdf.save_to_file($0 + ".pdf")