##- # Author: Brian Tiffin # Dedicated to the public domain # # Date: Decemeber 2016 # Modified: 2016-12-31/04:45-0500 ##+ # # haru.icn, demonstrate a newer C FFI # $include "natives.inc" $define HPDF_COMP_ALL 15 $define HPDF_PAGE_MODE_USE_OUTLINE 1 $define HPDF_PAGE_SIZE_LETTER 0 $define HPDF_PAGE_PORTRAIT 0 procedure main() local dlHandle, pdf, page1, rc, savefile := "harutest.pdf" # will be RTLD_LAZY | RTLD_GLOBAL (so add to the search path) addLibrary := loadfunc("./uniffi.so", "addLibrary") # allow arbitrary C functions, marshalled by a piece of assembler # assume float instead of double, changes the inline assembler # movsd versus movdd native := loadfunc("./uniffi.so", "ffi") # add libhpdf to the dlsym search path, the handle is irrelevant dlHandle := addLibrary("libhpdf.so") pdf := native("HPDF_New", TYPESTAR, 0, 0) rc := native("HPDF_SetCompressionMode", TYPEINT, pdf, HPDF_COMP_ALL) rc := native("HPDF_SetPageMode", TYPEINT, pdf, HPDF_PAGE_MODE_USE_OUTLINE) $ifdef PROTECTED rc := native("HPDF_SetPassword", TYPEINT, pdf, "owner", "user") savefile := "harutest-pass.pdf" $endif page1 := native("HPDF_AddPage", TYPESTAR, pdf) rc := native("HPDF_Page_SetHeight", TYPEINT, page1, [220.0, TYPEFLOAT]); rc := native("HPDF_Page_SetWidth", TYPEINT, page1, [200.0, TYPEFLOAT]); #/* A part of libharu pie chart sample, Red*/ rc := native("HPDF_Page_SetRGBFill", TYPEINT, page1, [1.0, TYPEFLOAT], [0.0, TYPEFLOAT], [0.0, TYPEFLOAT]); rc := native("HPDF_Page_MoveTo", TYPEINT, page1, [100.0, TYPEFLOAT], [100.0, TYPEFLOAT]); rc := native("HPDF_Page_LineTo", TYPEINT, page1, [100.0, TYPEFLOAT],[180.0, TYPEFLOAT]); rc := native("HPDF_Page_Arc", TYPEINT, page1, [100.0, TYPEFLOAT], [100.0, TYPEFLOAT], [80.0, TYPEFLOAT], [0.0, TYPEFLOAT], [360 * 0.45, TYPEFLOAT]); #pos := native("HPDF_Page_GetCurrentPos (page); rc := native("HPDF_Page_LineTo", TYPEINT, page1, [100.0, TYPEFLOAT], [100.0, TYPEFLOAT]); rc := native("HPDF_Page_Fill", TYPEINT, page1); rc := native("HPDF_SaveToFile", TYPEINT, pdf, savefile); native("HPDF_Free", TYPEVOID, pdf); end