upgrade libHaru to 2.3.0; make UTF-8 encoding default; some internal modifications and fixes

This commit is contained in:
Alex Fabijanic 2017-11-21 20:42:14 -06:00
parent 1724e8ba53
commit e067b19903
100 changed files with 8241 additions and 1179 deletions

File diff suppressed because it is too large Load Diff

View File

@ -219,7 +219,7 @@ public:
/// Loads type 1 font from file. Returns font name.
std::string loadTTFont(const std::string& fileName, bool embedding, int index = -1);
/// Loads type 1 font from file. Returns font name.
/// Loads true type font from file. Returns font name.
/// If the embedding parameter is true, the glyph data of the font is embedded,
/// otherwise only the matrix data is included in PDF file.
@ -253,6 +253,9 @@ public:
void addPageLabel(int pageNum, PageNumberStyle style, int firstPage, const std::string& prefix = "");
/// adds page labeling range for the document.
void useUTF8Encoding();
/// Enables use of UTF-8 encoding (default enabled).
void useJapaneseFonts();
/// Enables use of Japanese fonts.
@ -304,7 +307,13 @@ public:
std::size_t pageCount() const;
/// Returns number of pages in the document.
private:
HPDF_Doc& handle();
void init(Poco::UInt32 pageCount,
Page::Size pageSize, Page::Orientation orientation);
void reset(bool all = false);
/// Resets the current document. If all is true, the loaded
/// resources (e.g. fonts, encodings ...)are unloaded. Otherwise
@ -321,6 +330,8 @@ private:
EncoderContainer _encoders;
OutlineContainer _outlines;
ImageContainer _images;
friend class Page;
};
@ -360,8 +371,7 @@ inline Document::PageMode Document::getPageMode() const
/*
inline void openAction()
{
HPDF_SetOpenAction(_pdf,
HPDF_Destination open_action);
HPDF_SetOpenAction(_pdf, HPDF_Destination open_action);
}
*/
@ -394,6 +404,12 @@ inline void Document::addPageLabel(int pageNum, PageNumberStyle style, int first
}
inline void Document::useUTF8Encoding()
{
HPDF_UseUTFEncodings(_pdf);
}
inline void Document::useJapaneseFonts()
{
HPDF_UseJPFonts(_pdf);
@ -478,6 +494,12 @@ inline std::size_t Document::pageCount() const
}
inline HPDF_Doc& Document::handle()
{
return _pdf;
}
} } // namespace Poco::PDF

View File

@ -34,6 +34,9 @@ namespace Poco {
namespace PDF {
class Document;
class PDF_API Page
/// A Page represents a PDF page object.
{
@ -74,9 +77,9 @@ public:
enum Orientation
{
ORIENTATION_PORTRAIT = HPDF_PAGE_PORTRAIT,
// Portrait orientation.
// Portrait orientation.
ORIENTATION_LANDSCAPE = HPDF_PAGE_LANDSCAPE
// Landscape orientation.
// Landscape orientation.
};
enum RenderMode
@ -141,7 +144,7 @@ public:
/// Add spaces between the words to justify both left and right side.
};
Page(HPDF_Doc* pPDF,
Page(Document* pDocument,
const HPDF_Page& page,
Size pageSize = PAGE_SIZE_LETTER,
Orientation orientation = ORIENTATION_PORTRAIT);
@ -199,6 +202,9 @@ public:
void setFont(const Font& font, float size);
/// Sets the font.
void setFont(const std::string& fontName, float size, const std::string& encoding = "");
/// Sets the font.
float textWidth(const std::string& text);
/// Returns the width of the supplied text.
@ -511,7 +517,7 @@ public:
private:
Page();
HPDF_Doc* _pPDF;
Document* _pDocument;
HPDF_Page _page;
Size _size;
Orientation _orientation;
@ -533,12 +539,6 @@ inline Page::operator const Page::Type& () const
}
inline bool Page::operator == (const Page& other) const
{
return _pPDF == other._pPDF && _page == other._page;
}
inline void Page::setWidth(float value)
{
HPDF_Page_SetWidth(_page, value);
@ -795,13 +795,6 @@ inline void Page::moveTextNextLine()
}
inline const Font& Page::getFont() const
{
delete _pCurrentFont;
return *(_pCurrentFont = new Font(_pPDF, HPDF_Page_GetCurrentFont(_page)));
}
inline float Page::getFontSize() const
{
return HPDF_Page_GetCurrentFontSize(_page);

View File

@ -1,7 +1,7 @@
/*
* << Haru Free PDF Library 2.0.8 >> -- hpdf.h
*
* URL http://libharu.sourceforge.net/
* URL http://libharu.org/
*
* Copyright (c) 1999-2006 Takeshi Kanno
*
@ -17,6 +17,11 @@
#ifndef _HPDF_H
#define _HPDF_H
#include "hpdf_config.h"
#include "hpdf_version.h"
#define HPDF_UNUSED(a) ((void)(a))
#ifdef HPDF_DLL_MAKE
# define HPDF_EXPORT(A) __declspec(dllexport) A __stdcall
#else
@ -57,10 +62,21 @@ typedef HPDF_HANDLE HPDF_Image;
typedef HPDF_HANDLE HPDF_Font;
typedef HPDF_HANDLE HPDF_Outline;
typedef HPDF_HANDLE HPDF_Encoder;
typedef HPDF_HANDLE HPDF_3DMeasure;
typedef HPDF_HANDLE HPDF_ExData;
typedef HPDF_HANDLE HPDF_Destination;
typedef HPDF_HANDLE HPDF_XObject;
typedef HPDF_HANDLE HPDF_Annotation;
typedef HPDF_HANDLE HPDF_ExtGState;
typedef HPDF_HANDLE HPDF_FontDef;
typedef HPDF_HANDLE HPDF_U3D;
typedef HPDF_HANDLE HPDF_JavaScript;
typedef HPDF_HANDLE HPDF_Error;
typedef HPDF_HANDLE HPDF_MMgr;
typedef HPDF_HANDLE HPDF_Dict;
typedef HPDF_HANDLE HPDF_EmbeddedFile;
typedef HPDF_HANDLE HPDF_OutputIntent;
typedef HPDF_HANDLE HPDF_Xref;
#else
@ -70,6 +86,8 @@ typedef HPDF_HANDLE HPDF_ExtGState;
#include "hpdf_consts.h"
#include "hpdf_doc.h"
#include "hpdf_error.h"
#include "hpdf_pdfa.h"
#endif /* HPDF_SHARED */
@ -121,6 +139,10 @@ HPDF_FreeDocAll (HPDF_Doc pdf);
HPDF_EXPORT(HPDF_STATUS)
HPDF_SaveToStream (HPDF_Doc pdf);
HPDF_EXPORT(HPDF_STATUS)
HPDF_GetContents (HPDF_Doc pdf,
HPDF_BYTE *buf,
HPDF_UINT32 *size);
HPDF_EXPORT(HPDF_UINT32)
HPDF_GetStreamSize (HPDF_Doc pdf);
@ -152,6 +174,10 @@ HPDF_EXPORT(void)
HPDF_ResetError (HPDF_Doc pdf);
HPDF_EXPORT(HPDF_STATUS)
HPDF_CheckError (HPDF_Error error);
HPDF_EXPORT(HPDF_STATUS)
HPDF_SetPagesConfiguration (HPDF_Doc pdf,
HPDF_UINT page_per_pages);
@ -233,6 +259,10 @@ HPDF_EXPORT(HPDF_STATUS)
HPDF_Page_SetRotate (HPDF_Page page,
HPDF_UINT16 angle);
HPDF_EXPORT(HPDF_STATUS)
HPDF_Page_SetZoom (HPDF_Page page,
HPDF_REAL zoom);
/*---------------------------------------------------------------------------*/
/*----- font handling -------------------------------------------------------*/
@ -249,6 +279,11 @@ HPDF_LoadType1FontFromFile (HPDF_Doc pdf,
const char *data_file_name);
HPDF_EXPORT(HPDF_FontDef)
HPDF_GetTTFontDefFromFile (HPDF_Doc pdf,
const char *file_name,
HPDF_BOOL embedding);
HPDF_EXPORT(const char*)
HPDF_LoadTTFontFromFile (HPDF_Doc pdf,
const char *file_name,
@ -411,15 +446,34 @@ HPDF_EXPORT(HPDF_STATUS)
HPDF_UseCNTEncodings (HPDF_Doc pdf);
HPDF_EXPORT(HPDF_STATUS)
HPDF_UseUTFEncodings (HPDF_Doc pdf);
/*--------------------------------------------------------------------------*/
/*----- annotation ---------------------------------------------------------*/
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_Create3DAnnot (HPDF_Page page,
HPDF_Rect rect,
HPDF_U3D u3d);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateTextAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateFreeTextAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateLineAnnot (HPDF_Page page,
const char *text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateLinkAnnot (HPDF_Page page,
@ -433,6 +487,67 @@ HPDF_Page_CreateURILinkAnnot (HPDF_Page page,
const char *uri);
HPDF_Annotation
HPDF_Page_CreateTextMarkupAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder,
HPDF_AnnotType subType);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateHighlightAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateUnderlineAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateSquigglyAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateStrikeOutAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreatePopupAnnot ( HPDF_Page page,
HPDF_Rect rect,
HPDF_Annotation parent);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateStampAnnot ( HPDF_Page page,
HPDF_Rect rect,
HPDF_StampAnnotName name,
const char* text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateProjectionAnnot(HPDF_Page page,
HPDF_Rect rect,
const char* text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateSquareAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateCircleAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_STATUS)
HPDF_LinkAnnot_SetHighlightMode (HPDF_Annotation annot,
HPDF_AnnotHighlightMode mode);
@ -454,11 +569,179 @@ HPDF_EXPORT(HPDF_STATUS)
HPDF_TextAnnot_SetOpened (HPDF_Annotation annot,
HPDF_BOOL opened);
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetRGBColor (HPDF_Annotation annot, HPDF_RGBColor color);
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetCMYKColor (HPDF_Annotation annot, HPDF_CMYKColor color);
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetGrayColor (HPDF_Annotation annot, HPDF_REAL color);
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetNoColor (HPDF_Annotation annot);
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetTitle (HPDF_Annotation annot, const char* name);
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetSubject (HPDF_Annotation annot, const char* name);
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetCreationDate (HPDF_Annotation annot, HPDF_Date value);
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetTransparency (HPDF_Annotation annot, HPDF_REAL value);
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetIntent (HPDF_Annotation annot, HPDF_AnnotIntent intent);
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetPopup (HPDF_Annotation annot, HPDF_Annotation popup);
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetRectDiff (HPDF_Annotation annot, HPDF_Rect rect); /* RD entry */
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetCloudEffect (HPDF_Annotation annot, HPDF_INT cloudIntensity); /* BE entry */
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorRGBColor (HPDF_Annotation annot, HPDF_RGBColor color); /* IC with RGB entry */
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorCMYKColor (HPDF_Annotation annot, HPDF_CMYKColor color); /* IC with CMYK entry */
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorGrayColor (HPDF_Annotation annot, HPDF_REAL color); /* IC with Gray entry */
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorTransparent (HPDF_Annotation annot); /* IC with No Color entry */
HPDF_EXPORT(HPDF_STATUS)
HPDF_TextMarkupAnnot_SetQuadPoints ( HPDF_Annotation annot, HPDF_Point lb, HPDF_Point rb, HPDF_Point rt, HPDF_Point lt); /* l-left, r-right, b-bottom, t-top positions */
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_Set3DView ( HPDF_MMgr mmgr,
HPDF_Annotation annot,
HPDF_Annotation annot3d,
HPDF_Dict view);
HPDF_EXPORT(HPDF_STATUS)
HPDF_PopupAnnot_SetOpened (HPDF_Annotation annot,
HPDF_BOOL opened);
HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_SetLineEndingStyle (HPDF_Annotation annot, HPDF_LineAnnotEndingStyle startStyle, HPDF_LineAnnotEndingStyle endStyle);
HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_Set3PointCalloutLine (HPDF_Annotation annot, HPDF_Point startPoint, HPDF_Point kneePoint, HPDF_Point endPoint); /* Callout line will be in default user space */
HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_Set2PointCalloutLine (HPDF_Annotation annot, HPDF_Point startPoint, HPDF_Point endPoint); /* Callout line will be in default user space */
HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_SetDefaultStyle (HPDF_Annotation annot, const char* style);
HPDF_EXPORT(HPDF_STATUS)
HPDF_LineAnnot_SetPosition (HPDF_Annotation annot,
HPDF_Point startPoint, HPDF_LineAnnotEndingStyle startStyle,
HPDF_Point endPoint, HPDF_LineAnnotEndingStyle endStyle);
HPDF_EXPORT(HPDF_STATUS)
HPDF_LineAnnot_SetLeader (HPDF_Annotation annot, HPDF_INT leaderLen, HPDF_INT leaderExtLen, HPDF_INT leaderOffsetLen);
HPDF_EXPORT(HPDF_STATUS)
HPDF_LineAnnot_SetCaption (HPDF_Annotation annot, HPDF_BOOL showCaption, HPDF_LineAnnotCapPosition position, HPDF_INT horzOffset, HPDF_INT vertOffset);
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annotation_SetBorderStyle (HPDF_Annotation annot,
HPDF_BSSubtype subtype,
HPDF_REAL width,
HPDF_UINT16 dash_on,
HPDF_UINT16 dash_off,
HPDF_UINT16 dash_phase);
HPDF_EXPORT(HPDF_STATUS)
HPDF_ProjectionAnnot_SetExData(HPDF_Annotation annot, HPDF_ExData exdata);
/*--------------------------------------------------------------------------*/
/*----- 3D Measure ---------------------------------------------------------*/
HPDF_EXPORT(HPDF_3DMeasure)
HPDF_Page_Create3DC3DMeasure(HPDF_Page page,
HPDF_Point3D firstanchorpoint,
HPDF_Point3D textanchorpoint
);
HPDF_EXPORT(HPDF_3DMeasure)
HPDF_Page_CreatePD33DMeasure(HPDF_Page page,
HPDF_Point3D annotationPlaneNormal,
HPDF_Point3D firstAnchorPoint,
HPDF_Point3D secondAnchorPoint,
HPDF_Point3D leaderLinesDirection,
HPDF_Point3D measurementValuePoint,
HPDF_Point3D textYDirection,
HPDF_REAL value,
const char* unitsString
);
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DMeasure_SetName(HPDF_3DMeasure measure,
const char* name);
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DMeasure_SetColor(HPDF_3DMeasure measure,
HPDF_RGBColor color);
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DMeasure_SetTextSize(HPDF_3DMeasure measure,
HPDF_REAL textsize);
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DC3DMeasure_SetTextBoxSize(HPDF_3DMeasure measure,
HPDF_INT32 x,
HPDF_INT32 y);
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DC3DMeasure_SetText(HPDF_3DMeasure measure,
const char* text,
HPDF_Encoder encoder);
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DC3DMeasure_SetProjectionAnotation(HPDF_3DMeasure measure,
HPDF_Annotation projectionanotation);
/*--------------------------------------------------------------------------*/
/*----- External Data ---------------------------------------------------------*/
HPDF_EXPORT(HPDF_ExData)
HPDF_Page_Create3DAnnotExData(HPDF_Page page );
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DAnnotExData_Set3DMeasurement(HPDF_ExData exdata, HPDF_3DMeasure measure);
/*--------------------------------------------------------------------------*/
/*--------------------------------------------------------------------------*/
/*----- 3D View ---------------------------------------------------------*/
HPDF_EXPORT(HPDF_Dict)
HPDF_Page_Create3DView (HPDF_Page page,
HPDF_U3D u3d,
HPDF_Annotation annot3d,
const char *name);
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DView_Add3DC3DMeasure(HPDF_Dict view,
HPDF_3DMeasure measure);
/*--------------------------------------------------------------------------*/
/*----- image data ---------------------------------------------------------*/
HPDF_EXPORT(HPDF_Image)
HPDF_LoadPngImageFromMem (HPDF_Doc pdf,
const HPDF_BYTE *buffer,
HPDF_UINT size);
HPDF_EXPORT(HPDF_Image)
HPDF_LoadPngImageFromFile (HPDF_Doc pdf,
const char *filename);
@ -473,6 +756,29 @@ HPDF_EXPORT(HPDF_Image)
HPDF_LoadJpegImageFromFile (HPDF_Doc pdf,
const char *filename);
HPDF_EXPORT(HPDF_Image)
HPDF_LoadJpegImageFromMem (HPDF_Doc pdf,
const HPDF_BYTE *buffer,
HPDF_UINT size);
HPDF_EXPORT(HPDF_Image)
HPDF_LoadU3DFromFile (HPDF_Doc pdf,
const char *filename);
HPDF_EXPORT(HPDF_Image)
HPDF_LoadU3DFromMem (HPDF_Doc pdf,
const HPDF_BYTE *buffer,
HPDF_UINT size);
HPDF_EXPORT(HPDF_Image)
HPDF_Image_LoadRaw1BitImageFromMem (HPDF_Doc pdf,
const HPDF_BYTE *buf,
HPDF_UINT width,
HPDF_UINT height,
HPDF_UINT line_width,
HPDF_BOOL black_is1,
HPDF_BOOL top_is_first);
HPDF_EXPORT(HPDF_Image)
HPDF_LoadRawImageFromFile (HPDF_Doc pdf,
@ -490,6 +796,9 @@ HPDF_LoadRawImageFromMem (HPDF_Doc pdf,
HPDF_ColorSpace color_space,
HPDF_UINT bits_per_component);
HPDF_EXPORT(HPDF_STATUS)
HPDF_Image_AddSMask (HPDF_Image image,
HPDF_Image smask);
HPDF_EXPORT(HPDF_Point)
HPDF_Image_GetSize (HPDF_Image image);
@ -632,6 +941,14 @@ HPDF_Font_MeasureText (HPDF_Font font,
HPDF_REAL *real_width);
/*--------------------------------------------------------------------------*/
/*----- attachements -------------------------------------------------------*/
HPDF_EXPORT(HPDF_EmbeddedFile)
HPDF_AttachFile (HPDF_Doc pdf,
const char *file);
/*--------------------------------------------------------------------------*/
/*----- extended graphics state --------------------------------------------*/
@ -1148,6 +1465,17 @@ HPDF_EXPORT(HPDF_STATUS)
HPDF_Page_ExecuteXObject (HPDF_Page page,
HPDF_XObject obj);
/*--- Content streams ----------------------------------------------------*/
HPDF_EXPORT(HPDF_STATUS)
HPDF_Page_New_Content_Stream (HPDF_Page page,
HPDF_Dict* new_stream);
HPDF_EXPORT(HPDF_STATUS)
HPDF_Page_Insert_Shared_Content_Stream (HPDF_Page page,
HPDF_Dict shared_stream);
/*--- Marked content -----------------------------------------------------*/
/* BMC --not implemented yet */
@ -1219,6 +1547,18 @@ HPDF_Page_SetSlideShow (HPDF_Page page,
HPDF_REAL trans_time);
HPDF_EXPORT(HPDF_OutputIntent)
HPDF_ICC_LoadIccFromMem (HPDF_Doc pdf,
HPDF_MMgr mmgr,
HPDF_Stream iccdata,
HPDF_Xref xref,
int numcomponent);
HPDF_EXPORT(HPDF_OutputIntent)
HPDF_LoadIccProfileFromFile (HPDF_Doc pdf,
const char* icc_file_name,
int numcomponent);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -0,0 +1,57 @@
/*
* << Haru Free PDF Library >> -- hpdf_annotation.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* 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.
*
*/
#ifndef _HPDF_3DMEASURE_H
#define _HPDF_3DMEASURE_H
#include "hpdf_objects.h"
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*/
/*------ HPDF_3DMeasure -----------------------------------------------------*/
HPDF_3DMeasure
HPDF_3DC3DMeasure_New(HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Point3D firstanchorpoint,
HPDF_Point3D textanchorpoint
);
HPDF_3DMeasure
HPDF_PD33DMeasure_New(HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Point3D annotationPlaneNormal,
HPDF_Point3D firstAnchorPoint,
HPDF_Point3D secondAnchorPoint,
HPDF_Point3D leaderLinesDirection,
HPDF_Point3D measurementValuePoint,
HPDF_Point3D textYDirection,
HPDF_REAL value,
const char* unitsString
);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _HPDF_3DMEASURE_H */

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_annotation.h
* << Haru Free PDF Library >> -- hpdf_annotation.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -47,21 +50,39 @@ HPDF_URILinkAnnot_New (HPDF_MMgr mmgr,
HPDF_Annotation
HPDF_TextAnnot_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder);
HPDF_3DAnnot_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Rect rect,
HPDF_U3D u3d);
HPDF_Annotation
HPDF_MarkupAnnot_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder,
HPDF_AnnotType subtype);
HPDF_STATUS
HPDF_Annotation_SetBorderStyle (HPDF_Annotation annot,
HPDF_BSSubtype subtype,
HPDF_REAL width,
HPDF_UINT16 dash_on,
HPDF_UINT16 dash_off,
HPDF_UINT16 dash_phase);
HPDF_Annotation
HPDF_PopupAnnot_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Rect rect,
HPDF_Annotation parent);
HPDF_Annotation
HPDF_StampAnnot_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Rect rect,
HPDF_StampAnnotName name,
const char* text,
HPDF_Encoder encoder);
HPDF_Annotation
HPDF_ProjectionAnnot_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Rect rect,
const char* text,
HPDF_Encoder encoder);
HPDF_BOOL
HPDF_Annotation_Validate (HPDF_Annotation annot);

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_catalog.h
* << Haru Free PDF Library >> -- hpdf_catalog.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -28,6 +31,15 @@ HPDF_Catalog_New (HPDF_MMgr mmgr,
HPDF_Xref xref);
HPDF_NameDict
HPDF_Catalog_GetNames (HPDF_Catalog catalog);
HPDF_STATUS
HPDF_Catalog_SetNames (HPDF_Catalog catalog,
HPDF_NameDict dict);
HPDF_Pages
HPDF_Catalog_GetRoot (HPDF_Catalog catalog);

View File

@ -1,9 +1,10 @@
/*
* << Haru Free PDF Library 2.0.7 >> -- hpdf_conf.h
* << Haru Free PDF Library >> -- hpdf_conf.h
*
* URL http://libharu.sourceforge.net/
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -19,6 +20,14 @@
#include <stdlib.h>
#include <stdio.h>
#if defined(_MSC_VER)
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES 1
#endif /* _USE_MATH_DEFINES */
#endif
#ifndef __USE_XOPEN
#define __USE_XOPEN /* for M_PI */
#endif /* __USE_XOPEN */
#include <math.h>
/*----------------------------------------------------------------------------*/

View File

@ -0,0 +1,75 @@
/* include/hpdf_config.h.in. Generated from configure.in by autoheader. */
/* Define to 1 if you have the <dlfcn.h> header file. */
#undef LIBHPDF_HAVE_DLFCN_H
/* Define to 1 if you have the <inttypes.h> header file. */
#undef LIBHPDF_HAVE_INTTYPES_H
/* Define to 1 if you have the `png' library (-lpng). */
#define LIBHPDF_HAVE_LIBPNG 1
/* Define to 1 if you have the `z' library (-lz). */
#define LIBHPDF_HAVE_LIBZ 1
/* Define to 1 if you have the <memory.h> header file. */
#undef LIBHPDF_HAVE_MEMORY_H
/* Define to 1 if you have the <stdint.h> header file. */
#undef LIBHPDF_HAVE_STDINT_H
/* Define to 1 if you have the <stdlib.h> header file. */
#define LIBHPDF_HAVE_STDLIB_H 1
/* Define to 1 if you have the <strings.h> header file. */
#define LIBHPDF_HAVE_STRINGS_H 1
/* Define to 1 if you have the <string.h> header file. */
#define LIBHPDF_HAVE_STRING_H 1
/* Define to 1 if you have the <sys/stat.h> header file. */
#define LIBHPDF_HAVE_SYS_STAT_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#undef LIBHPDF_HAVE_SYS_TYPES_H
/* Define to 1 if you have the <unistd.h> header file. */
#define LIBHPDF_HAVE_UNISTD_H 1
/* define pi */
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif /* M_PI */
/* debug build */
#undef LIBHPDF_DEBUG
/* debug trace enabled */
#undef LIBHPDF_DEBUG_TRACE
/* libpng is not available */
#undef LIBHPDF_HAVE_NOPNGLIB
/* zlib is not available */
#undef LIBHPDF_HAVE_NOZLIB
/* Define to the address where bug reports for this package should be sent. */
#undef LIBHPDF_PACKAGE_BUGREPORT
/* Define to the full name of this package. */
#undef LIBHPDF_PACKAGE_NAME
/* Define to the full name and version of this package. */
#define LIBHPDF_PACKAGE_STRING "libhpdf 2.2.0"
/* Define to the one symbol short name of this package. */
#undef LIBHPDF_PACKAGE_TARNAME
/* Define to the version of this package. */
#define LIBHPDF_PACKAGE_VERSION "2.2.0"
/* Define to 1 if you have the ANSI C header files. */
#define LIBHPDF_STDC_HEADERS 1
/* Define to `unsigned int' if <sys/types.h> does not define. */
#undef size_t

View File

@ -1,9 +1,10 @@
/*
* << Haru Free PDF Library 2.0.8 >> -- hpdf_consts.h
* << Haru Free PDF Library >> -- hpdf_consts.h
*
* URL http://libharu.sourceforge.net/
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -67,8 +68,6 @@
#define HPDF_DEF_PAGE_WIDTH 595.276F
#define HPDF_DEF_PAGE_HEIGHT 841.89F
#define HPDF_VERSION_TEXT "2.0.8"
/*---------------------------------------------------------------------------*/
/*----- compression mode ----------------------------------------------------*/
@ -101,6 +100,7 @@
#define HPDF_HIDE_WINDOW_UI 4
#define HPDF_FIT_WINDOW 8
#define HPDF_CENTER_WINDOW 16
#define HPDF_PRINT_SCALING_NONE 32
/*---------------------------------------------------------------------------*/
@ -115,7 +115,7 @@
#define HPDF_LIMIT_MAX_STRING_LEN 65535
#define HPDF_LIMIT_MAX_NAME_LEN 127
#define HPDF_LIMIT_MAX_ARRAY 8191
#define HPDF_LIMIT_MAX_ARRAY 32767
#define HPDF_LIMIT_MAX_DICT_ELEMENT 4095
#define HPDF_LIMIT_MAX_XREF_ELEMENT 8388607
#define HPDF_LIMIT_MAX_GSTATE 28
@ -142,7 +142,7 @@
#define HPDF_MAX_WORDSPACE 300
#define HPDF_MIN_CHARSPACE -30
#define HPDF_MAX_CHARSPACE 300
#define HPDF_MAX_FONTSIZE 300
#define HPDF_MAX_FONTSIZE 600
#define HPDF_MAX_ZOOMSIZE 10
#define HPDF_MAX_LEADING 300
#define HPDF_MAX_LINEWIDTH 100

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_destination.c
* << Haru Free PDF Library >> -- hpdf_destination.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_doc.h
* << Haru Free PDF Library >> -- hpdf_doc.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,9 +1,10 @@
/*
* << Haru Free PDF Library 2.0.2 >> -- hpdf_encoder.h
* << Haru Free PDF Library >> -- hpdf_encoder.h
*
* URL http://libharu.sourceforge.net/
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -92,6 +93,11 @@ typedef HPDF_UNICODE
(*HPDF_Encoder_ToUnicode_Func) (HPDF_Encoder encoder,
HPDF_UINT16 code);
typedef char *
(*HPDF_Encoder_EncodeText_Func) (HPDF_Encoder encoder,
const char *text,
HPDF_UINT len,
HPDF_UINT *encoded_length);
typedef HPDF_STATUS
(*HPDF_Encoder_Write_Func) (HPDF_Encoder encoder,
@ -108,13 +114,14 @@ typedef void
typedef struct _HPDF_Encoder_Rec {
HPDF_UINT32 sig_bytes;
char name[HPDF_LIMIT_MAX_NAME_LEN + 1];
char name[HPDF_LIMIT_MAX_NAME_LEN + 1];
HPDF_MMgr mmgr;
HPDF_Error error;
HPDF_EncoderType type;
HPDF_Encoder_ByteType_Func byte_type_fn;
HPDF_Encoder_ToUnicode_Func to_unicode_fn;
HPDF_Encoder_EncodeText_Func encode_text_fn;
HPDF_Encoder_Write_Func write_fn;
HPDF_Encoder_Free_Func free_fn;
HPDF_Encoder_Init_Func init_fn;
@ -230,7 +237,7 @@ typedef struct _HPDF_CMapEncoderAttr_Rec {
HPDF_Encoder
HPDF_CMapEncoder_New (HPDF_MMgr mmgr,
char *name,
char *name,
HPDF_Encoder_Init_Func init_fn);

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_encrypt.h
* << Haru Free PDF Library >> -- hpdf_encrypt.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_encryptdict.h
* << Haru Free PDF Library >> -- hpdf_encryptdict.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,9 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_error.h
* << Haru Free PDF Library >> -- hpdf_error.h
*
* URL http://libharu.sourceforge.net/
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -141,6 +142,11 @@ extern "C" {
#define HPDF_EXT_GSTATE_OUT_OF_RANGE 0x1080
#define HPDF_INVALID_EXT_GSTATE 0x1081
#define HPDF_EXT_GSTATE_READ_ONLY 0x1082
#define HPDF_INVALID_U3D_DATA 0x1083
#define HPDF_NAME_CANNOT_GET_NAMES 0x1084
#define HPDF_INVALID_ICC_COMPONENT_NUM 0x1085
/*---------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------*/
/*----- HPDF_Error ----------------------------------------------------------*/
@ -184,10 +190,6 @@ HPDF_SetError (HPDF_Error error,
HPDF_STATUS detail_no);
HPDF_STATUS
HPDF_CheckError (HPDF_Error error);
HPDF_STATUS
HPDF_RaiseError (HPDF_Error error,
HPDF_STATUS error_no,

View File

@ -0,0 +1,41 @@
/*
* << Haru Free PDF Library >> -- hpdf_annotation.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* 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.
*
*/
#ifndef _HPDF_EXDATA_H
#define _HPDF_EXDATA_H
#include "hpdf_objects.h"
#ifdef __cplusplus
extern "C" {
#endif
/*----------------------------------------------------------------------------*/
/*------ HPDF_ExData -----------------------------------------------------*/
HPDF_ExData
HPDF_3DAnnotExData_New(HPDF_MMgr mmgr,
HPDF_Xref xref );
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _HPDF_EXDATA_H */

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_ext_gstate.h
* << Haru Free PDF Library >> -- hpdf_ext_gstate.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_font.h
* << Haru Free PDF Library >> -- hpdf_font.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.4 >> -- hpdf_fontdef.h
* << Haru Free PDF Library >> -- hpdf_fontdef.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -300,7 +303,8 @@ typedef struct _HPDF_TTFontDefAttr_Rec {
HPDF_TTF_OffsetTbl offset_tbl;
HPDF_TTF_CmapRange cmap;
HPDF_UINT16 fs_type;
HPDF_BYTE panose[12];
HPDF_BYTE sfamilyclass[2];
HPDF_BYTE panose[10];
HPDF_UINT32 code_page_range1;
HPDF_UINT32 code_page_range2;
@ -400,4 +404,3 @@ HPDF_CIDFontDef_ChangeStyle (HPDF_FontDef fontdef,
#endif /* __cplusplus */
#endif /* _HPDF_FONTDEF_H */

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_gstate.h
* << Haru Free PDF Library >> -- hpdf_gstate.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_image.h
* << Haru Free PDF Library >> -- hpdf_image.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -21,7 +24,18 @@
extern "C" {
#endif
#ifndef HPDF_NOPNGLIB
HPDF_Image
HPDF_Image_Load1BitImageFromMem (HPDF_MMgr mmgr,
const HPDF_BYTE *buf,
HPDF_Xref xref,
HPDF_UINT width,
HPDF_UINT height,
HPDF_UINT line_width,
HPDF_BOOL top_is_first
);
#ifndef LIBHPDF_HAVE_NOPNGLIB
HPDF_Image
HPDF_Image_LoadPngImage (HPDF_MMgr mmgr,
@ -36,6 +50,11 @@ HPDF_Image_LoadJpegImage (HPDF_MMgr mmgr,
HPDF_Stream jpeg_data,
HPDF_Xref xref);
HPDF_Image
HPDF_Image_LoadJpegImageFromMem (HPDF_MMgr mmgr,
const HPDF_BYTE *buf,
HPDF_UINT size,
HPDF_Xref xref);
HPDF_Image
HPDF_Image_LoadRawImage (HPDF_MMgr mmgr,
@ -64,6 +83,14 @@ HPDF_STATUS
HPDF_Image_SetMask (HPDF_Image image,
HPDF_BOOL mask);
HPDF_STATUS
HPDF_Image_SetColorSpace (HPDF_Image image,
HPDF_Array colorspace);
HPDF_STATUS
HPDF_Image_SetRenderingIntent (HPDF_Image image,
const char* intent);
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_info.c
* << Haru Free PDF Library >> -- hpdf_info.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_list.h
* << Haru Free PDF Library >> -- hpdf_list.h
*
* Copyright (c) 1999-2005 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_mmgr.h
* << Haru Free PDF Library >> -- hpdf_mmgr.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -0,0 +1,76 @@
/*
* << Haru Free PDF Library >> -- hpdf_namedict.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* 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.
*
*/
#ifndef _HPDF_NAMEDICT_H
#define _HPDF_NAMEDICT_H
#include "hpdf_objects.h"
#ifdef __cplusplus
extern "C" {
#endif
HPDF_NameDict
HPDF_NameDict_New (HPDF_MMgr mmgr,
HPDF_Xref xref);
HPDF_NameTree
HPDF_NameDict_GetNameTree (HPDF_NameDict namedict,
HPDF_NameDictKey key);
HPDF_STATUS
HPDF_NameDict_SetNameTree (HPDF_NameDict namedict,
HPDF_NameDictKey key,
HPDF_NameTree tree);
HPDF_BOOL
HPDF_NameDict_Validate (HPDF_NameDict namedict);
/*------- NameTree -------*/
HPDF_NameTree
HPDF_NameTree_New (HPDF_MMgr mmgr,
HPDF_Xref xref);
HPDF_STATUS
HPDF_NameTree_Add (HPDF_NameTree tree,
HPDF_String name,
void *obj);
HPDF_BOOL
HPDF_NameTree_Validate (HPDF_NameTree tree);
/*------- EmbeddedFile -------*/
HPDF_EmbeddedFile
HPDF_EmbeddedFile_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
const char *file);
HPDF_BOOL
HPDF_EmbeddedFile_Validate (HPDF_EmbeddedFile emfile);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _HPDF_NAMEDICT_H */

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.5 >> -- hpdf_objects.c
* << Haru Free PDF Library >> -- hpdf_objects.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -56,6 +59,8 @@ extern "C" {
#define HPDF_OSUBCLASS_ENCRYPT 0x0900
#define HPDF_OSUBCLASS_EXT_GSTATE 0x0A00
#define HPDF_OSUBCLASS_EXT_GSTATE_R 0x0B00 /* read only object */
#define HPDF_OSUBCLASS_NAMEDICT 0x0C00
#define HPDF_OSUBCLASS_NAMETREE 0x0D00
@ -268,10 +273,9 @@ HPDF_String_Write (HPDF_String obj,
HPDF_Stream stream,
HPDF_Encrypt e);
HPDF_STATUS
HPDF_String_SetValue (HPDF_String obj,
const char *value);
HPDF_INT32
HPDF_String_Cmp (HPDF_String s1,
HPDF_String s2);
/*---------------------------------------------------------------------------*/
@ -386,6 +390,10 @@ void
HPDF_Array_Clear (HPDF_Array array);
HPDF_UINT
HPDF_Array_Items (HPDF_Array array);
/*---------------------------------------------------------------------------*/
/*----- HPDF_Dict -----------------------------------------------------------*/
@ -417,6 +425,7 @@ typedef struct _HPDF_Dict_Rec {
HPDF_Dict_FreeFunc free_fn;
HPDF_Stream stream;
HPDF_UINT filter;
HPDF_Dict filterParams;
void *attr;
} HPDF_Dict_Rec;
@ -568,16 +577,24 @@ HPDF_Xref_GetEntryByObjectId (HPDF_Xref xref,
typedef HPDF_Dict HPDF_EmbeddedFile;
typedef HPDF_Dict HPDF_NameDict;
typedef HPDF_Dict HPDF_NameTree;
typedef HPDF_Dict HPDF_Pages;
typedef HPDF_Dict HPDF_Page;
typedef HPDF_Dict HPDF_Annotation;
typedef HPDF_Dict HPDF_3DMeasure;
typedef HPDF_Dict HPDF_ExData;
typedef HPDF_Dict HPDF_XObject;
typedef HPDF_Dict HPDF_Image;
typedef HPDF_Dict HPDF_Outline;
typedef HPDF_Dict HPDF_EncryptDict;
typedef HPDF_Dict HPDF_Action;
typedef HPDF_Dict HPDF_ExtGState;
typedef HPDF_Array HPDF_Destination;
typedef HPDF_Array HPDF_Destination;
typedef HPDF_Dict HPDF_U3D;
typedef HPDF_Dict HPDF_OutputIntent;
typedef HPDF_Dict HPDF_JavaScript;
#ifdef __cplusplus
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_outline.h
* << Haru Free PDF Library >> -- hpdf_outline.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_page_label.h
* << Haru Free PDF Library >> -- hpdf_page_label.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_pages.c
* << Haru Free PDF Library >> -- hpdf_pages.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -0,0 +1,43 @@
/*
* << Haru Free PDF Library >> -- hpdf_pdfa.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* 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.
*
*/
#ifndef _HPDF_PDFA_H
#define _HPDF_PDFA_H
#include "hpdf_doc.h"
#include "hpdf_objects.h"
#ifdef __cplusplus
extern "C" {
#endif
HPDF_STATUS
HPDF_PDFA_AppendOutputIntents(HPDF_Doc pdf, const char *iccname, HPDF_Dict iccdict);
HPDF_STATUS
HPDF_PDFA_SetPDFAConformance (HPDF_Doc pdf,
HPDF_PDFAType pdfatype);
HPDF_STATUS
HPDF_PDFA_GenerateID(HPDF_Doc);
#ifdef __cplusplus
}
#endif
#endif

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_streams.h
* << Haru Free PDF Library >> -- hpdf_streams.h
*
* Copyright (c) 1999-2004 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -31,7 +34,7 @@ typedef enum _HPDF_StreamType {
HPDF_STREAM_UNKNOWN = 0,
HPDF_STREAM_CALLBACK,
HPDF_STREAM_FILE,
HPDF_STREAM_MEMORY,
HPDF_STREAM_MEMORY
} HPDF_StreamType;
#define HPDF_STREAM_FILTER_NONE 0x0000
@ -39,6 +42,7 @@ typedef enum _HPDF_StreamType {
#define HPDF_STREAM_FILTER_ASCII85 0x0200
#define HPDF_STREAM_FILTER_FLATE_DECODE 0x0400
#define HPDF_STREAM_FILTER_DCT_DECODE 0x0800
#define HPDF_STREAM_FILTER_CCITT_DECODE 0x1000
typedef enum _HPDF_WhenceMode {
HPDF_SEEK_SET = 0,

View File

@ -1,9 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_types.h
* << Haru Free PDF Library >> -- hpdf_types.h
*
* URL http://libharu.sourceforge.net/
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -107,6 +108,14 @@ typedef struct _HPDF_Rect {
HPDF_REAL top;
} HPDF_Rect;
/* HPDF_Point3D struct
*/
typedef struct _HPDF_Point3D {
HPDF_REAL x;
HPDF_REAL y;
HPDF_REAL z;
} HPDF_Point3D;
typedef struct _HPDF_Rect HPDF_Box;
/* HPDF_Date struct
@ -136,9 +145,19 @@ typedef enum _HPDF_InfoType {
HPDF_INFO_TITLE,
HPDF_INFO_SUBJECT,
HPDF_INFO_KEYWORDS,
HPDF_INFO_TRAPPED,
HPDF_INFO_GTS_PDFX,
HPDF_INFO_EOF
} HPDF_InfoType;
/* PDF-A Types */
typedef enum _HPDF_PDFA_TYPE
{
HPDF_PDFA_1A = 0,
HPDF_PDFA_1B = 1
} HPDF_PDFAType;
typedef enum _HPDF_PdfVer {
HPDF_VER_12 = 0,
@ -146,6 +165,7 @@ typedef enum _HPDF_PdfVer {
HPDF_VER_14,
HPDF_VER_15,
HPDF_VER_16,
HPDF_VER_17,
HPDF_VER_EOF
} HPDF_PDFVer;
@ -290,6 +310,8 @@ typedef enum _HPDF_PageLayout {
HPDF_PAGE_LAYOUT_ONE_COLUMN,
HPDF_PAGE_LAYOUT_TWO_COLUMN_LEFT,
HPDF_PAGE_LAYOUT_TWO_COLUMN_RIGHT,
HPDF_PAGE_LAYOUT_TWO_PAGE_LEFT,
HPDF_PAGE_LAYOUT_TWO_PAGE_RIGHT,
HPDF_PAGE_LAYOUT_EOF
} HPDF_PageLayout;
@ -342,7 +364,11 @@ typedef enum _HPDF_AnnotType {
HPDF_ANNOT_UNDERLINE,
HPDF_ANNOT_INK,
HPDF_ANNOT_FILE_ATTACHMENT,
HPDF_ANNOT_POPUP
HPDF_ANNOT_POPUP,
HPDF_ANNOT_3D,
HPDF_ANNOT_SQUIGGLY,
HPDF_ANNOT_LINE,
HPDF_ANNOT_PROJECTION
} HPDF_AnnotType;
@ -377,7 +403,50 @@ typedef enum _HPDF_AnnotIcon {
HPDF_ANNOT_ICON_EOF
} HPDF_AnnotIcon;
typedef enum _HPDF_AnnotIntent {
HPDF_ANNOT_INTENT_FREETEXTCALLOUT = 0,
HPDF_ANNOT_INTENT_FREETEXTTYPEWRITER,
HPDF_ANNOT_INTENT_LINEARROW,
HPDF_ANNOT_INTENT_LINEDIMENSION,
HPDF_ANNOT_INTENT_POLYGONCLOUD,
HPDF_ANNOT_INTENT_POLYLINEDIMENSION,
HPDF_ANNOT_INTENT_POLYGONDIMENSION
} HPDF_AnnotIntent;
typedef enum _HPDF_LineAnnotEndingStyle {
HPDF_LINE_ANNOT_NONE = 0,
HPDF_LINE_ANNOT_SQUARE,
HPDF_LINE_ANNOT_CIRCLE,
HPDF_LINE_ANNOT_DIAMOND,
HPDF_LINE_ANNOT_OPENARROW,
HPDF_LINE_ANNOT_CLOSEDARROW,
HPDF_LINE_ANNOT_BUTT,
HPDF_LINE_ANNOT_ROPENARROW,
HPDF_LINE_ANNOT_RCLOSEDARROW,
HPDF_LINE_ANNOT_SLASH
} HPDF_LineAnnotEndingStyle;
typedef enum _HPDF_LineAnnotCapPosition{
HPDF_LINE_ANNOT_CAP_INLINE = 0,
HPDF_LINE_ANNOT_CAP_TOP
} HPDF_LineAnnotCapPosition;
typedef enum _HPDF_StampAnnotName{
HPDF_STAMP_ANNOT_APPROVED = 0,
HPDF_STAMP_ANNOT_EXPERIMENTAL,
HPDF_STAMP_ANNOT_NOTAPPROVED,
HPDF_STAMP_ANNOT_ASIS,
HPDF_STAMP_ANNOT_EXPIRED,
HPDF_STAMP_ANNOT_NOTFORPUBLICRELEASE,
HPDF_STAMP_ANNOT_CONFIDENTIAL,
HPDF_STAMP_ANNOT_FINAL,
HPDF_STAMP_ANNOT_SOLD,
HPDF_STAMP_ANNOT_DEPARTMENTAL,
HPDF_STAMP_ANNOT_FORCOMMENT,
HPDF_STAMP_ANNOT_TOPSECRET,
HPDF_STAMP_ANNOT_DRAFT,
HPDF_STAMP_ANNOT_FORPUBLICRELEASE
} HPDF_StampAnnotName;
/*----------------------------------------------------------------------------*/
/*------ border stype --------------------------------------------------------*/
@ -480,6 +549,14 @@ typedef enum _HPDF_TextAlignment {
HPDF_TALIGN_JUSTIFY
} HPDF_TextAlignment;
/*----------------------------------------------------------------------------*/
/* Name Dictionary values -- see PDF reference section 7.7.4 */
typedef enum _HPDF_NameDictKey {
HPDF_NAME_EMBEDDED_FILES = 0, /* TODO the rest */
HPDF_NAME_EOF
} HPDF_NameDictKey;
#ifdef __cplusplus
}
#endif /* __cplusplus */

View File

@ -0,0 +1,53 @@
/*
* << Haru Free PDF Library >> -- hpdf_u3d.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* 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.
*
*/
#ifndef _HPDF_U3D_H
#define _HPDF_U3D_H
#include "hpdf_objects.h"
#ifdef __cplusplus
extern "C" {
#endif
HPDF_EXPORT(HPDF_JavaScript) HPDF_CreateJavaScript(HPDF_Doc pdf, const char *code);
HPDF_EXPORT(HPDF_U3D) HPDF_LoadU3DFromFile (HPDF_Doc pdf, const char *filename);
HPDF_EXPORT(HPDF_Image) HPDF_LoadU3DFromMem (HPDF_Doc pdf, const HPDF_BYTE *buffer, HPDF_UINT size);
HPDF_EXPORT(HPDF_Dict) HPDF_Create3DView (HPDF_MMgr mmgr, const char *name);
HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_Add3DView(HPDF_U3D u3d, HPDF_Dict view);
HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_SetDefault3DView(HPDF_U3D u3d, const char *name);
HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_AddOnInstanciate(HPDF_U3D u3d, HPDF_JavaScript javaScript);
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_AddNode(HPDF_Dict view, const char *name, HPDF_REAL opacity, HPDF_BOOL visible);
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetLighting(HPDF_Dict view, const char *scheme);
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetBackgroundColor(HPDF_Dict view, HPDF_REAL r, HPDF_REAL g, HPDF_REAL b);
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetPerspectiveProjection(HPDF_Dict view, HPDF_REAL fov);
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetOrthogonalProjection(HPDF_Dict view, HPDF_REAL mag);
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetCamera(HPDF_Dict view, HPDF_REAL coox, HPDF_REAL cooy, HPDF_REAL cooz, HPDF_REAL c2cx, HPDF_REAL c2cy, HPDF_REAL c2cz, HPDF_REAL roo, HPDF_REAL roll);
HPDF_Dict
HPDF_3DView_New ( HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_U3D u3d,
const char *name);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* _HPDF_U3D_H */

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- fpdf_utils.h
* << Haru Free PDF Library >> -- fpdf_utils.h
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -15,6 +18,7 @@
#ifndef _HPDF_UTILS_H
#define _HPDF_UTILS_H
#include "hpdf_config.h"
#include "hpdf_types.h"
#ifdef __cplusplus
@ -114,7 +118,7 @@ HPDF_UInt16Swap (HPDF_UINT16 *value);
}
#endif /* __cplusplus */
#define HPDF_NEEDS_ESCAPE(c) (c < 0x21 || \
#define HPDF_NEEDS_ESCAPE(c) (c < 0x20 || \
c > 0x7e || \
c == '\\' || \
c == '%' || \
@ -139,11 +143,11 @@ HPDF_UInt16Swap (HPDF_UINT16 *value);
/*----------------------------------------------------------------------------*/
/*----- macros for debug -----------------------------------------------------*/
#ifdef HPDF_DEBUG
#ifdef LIBHPDF_DEBUG_TRACE
#ifndef HPDF_PTRACE_ON
#define HPDF_PTRACE_ON
#endif /* HPDF_PTRACE_ON */
#endif /* HPDF_DEBUG */
#endif /* LIBHPDF_DEBUG_TRACE */
#ifdef HPDF_PTRACE_ON
#define HPDF_PTRACE(ARGS) HPDF_PRINTF ARGS
@ -151,7 +155,7 @@ HPDF_UInt16Swap (HPDF_UINT16 *value);
#define HPDF_PTRACE(ARGS) /* do nothing */
#endif /* HPDF_PTRACE */
#ifdef HPDF_DEBUG
#ifdef LIBHPDF_DEBUG
#define HPDF_PRINT_BINARY(BUF, LEN, CAPTION) HPDF_PrintBinary(BUF, LEN, CAPTION)
#else
#define HPDF_PRINT_BINARY(BUF, LEN, CAPTION) /* do nothing */

View File

@ -0,0 +1,8 @@
/* automatically generated by configure */
/* edit configure.in to change version number */
#define HPDF_MAJOR_VERSION 2
#define HPDF_MINOR_VERSION 3
#define HPDF_BUGFIX_VERSION 0
#define HPDF_EXTRA_VERSION "RC2"
#define HPDF_VERSION_TEXT "2.3.0RC2"
#define HPDF_VERSION_ID 20300

BIN
PDF/samples/Image/Image.pdf Normal file

Binary file not shown.

Binary file not shown.

BIN
PDF/samples/Text/Text.pdf Normal file

Binary file not shown.

Binary file not shown.

View File

@ -36,9 +36,7 @@ Document::Document(const std::string fileName,
_pRawData(0),
_size(0)
{
compression(COMPRESSION_ALL);
for (Poco::UInt32 i = 0; i < pageCount; ++i)
addPage(pageSize, orientation);
init(pageCount, pageSize, orientation);
}
@ -49,9 +47,7 @@ Document::Document(Poco::UInt32 pageCount,
_pRawData(0),
_size(0)
{
compression(COMPRESSION_ALL);
for (Poco::UInt32 i = 0; i < pageCount; ++i)
addPage();
init(pageCount, pageSize, orientation);
}
@ -62,6 +58,16 @@ Document::~Document()
}
void Document::init(Poco::UInt32 pageCount,
Page::Size pageSize, Page::Orientation orientation)
{
useUTF8Encoding();
compression(COMPRESSION_ALL);
for (Poco::UInt32 i = 0; i < pageCount; ++i)
addPage(pageSize, orientation);
}
void Document::createNew(bool resetAll)
{
reset(resetAll);
@ -99,7 +105,7 @@ Document::SizeType Document::size()
const Page& Document::addPage(Page::Size pageSize, Page::Orientation orientation)
{
Page page(&_pdf, HPDF_AddPage(_pdf), pageSize);
Page page(this, HPDF_AddPage(_pdf), pageSize);
page.setSizeAndOrientation(pageSize, orientation);
_pages.push_back(page);
return _pages.back();
@ -114,7 +120,7 @@ const Page& Document::insertPage(int index,
poco_assert (index < _pages.size());
HPDF_Page target = *((HPDF_Page*) HPDF_List_ItemAt(_pdf->page_list, static_cast<HPDF_UINT>(index)));
return *_pages.insert(_pages.begin() + index,
Page(&_pdf,
Page(this,
HPDF_InsertPage(_pdf, target),
pageSize,
orientation));
@ -123,7 +129,7 @@ const Page& Document::insertPage(int index,
const Page& Document::getCurrentPage()
{
Page p(&_pdf, HPDF_GetCurrentPage(_pdf));
Page p(this, HPDF_GetCurrentPage(_pdf));
PageContainer::iterator it = _pages.begin();
PageContainer::iterator end = _pages.end();
for (;it != end; ++it)

View File

@ -13,6 +13,7 @@
#include "Poco/PDF/Page.h"
#include "Poco/PDF/Document.h"
#include "Poco/PDF/PDFException.h"
#undef min
#undef max
@ -23,24 +24,25 @@ namespace Poco {
namespace PDF {
Page::Page(HPDF_Doc* pPDF,
Page::Page(Document* pDocument,
const HPDF_Page& page,
Size pageSize,
Orientation orientation):
_pPDF(pPDF),
_page(page),
_size(pageSize),
_orientation(orientation),
_pCurrentFont(0)
Orientation orientation):
_pDocument(pDocument),
_page(page),
_size(pageSize),
_orientation(orientation),
_pCurrentFont(0)
{
}
Page::Page(const Page& other):
_pPDF(other._pPDF),
Page::Page(const Page& other):
_pDocument(other._pDocument),
_page(other._page),
_size(other._size),
_orientation(other._orientation)
_orientation(other._orientation),
_pCurrentFont(other._pCurrentFont ? new Font(*other._pCurrentFont) : (Font*)0)
{
}
@ -58,14 +60,21 @@ Page& Page::operator = (const Page& page)
}
bool Page::operator == (const Page& other) const
{
return &_pDocument->handle() == &other._pDocument->handle() && _page == other._page;
}
void Page::swap(Page& other)
{
using std::swap;
swap(_pPDF, other._pPDF);
swap(_pDocument, other._pDocument);
swap(_page, other._page);
swap(_size, other._size);
swap(_orientation, other._orientation);
swap(_pCurrentFont, other._pCurrentFont);
}
@ -97,6 +106,20 @@ float Page::textWidth(const std::string& text)
}
void Page::setFont(const std::string& name, float size, const std::string& encoding)
{
Font font(&_pDocument->handle(), HPDF_GetFont(_pDocument->handle(), name.c_str(), encoding.empty() ? 0 : encoding.c_str()));
setFont(font, size);
}
const Font& Page::getFont() const
{
delete _pCurrentFont;
return *(_pCurrentFont = new Font(&_pDocument->handle(), HPDF_Page_GetCurrentFont(_page)));
}
void Page::setRotation(int angle)
{
if (0 != angle % 90 || angle > std::numeric_limits<HPDF_UINT16>::max())
@ -112,7 +135,7 @@ const Destination& Page::createDestination(const std::string& name)
if (_destinations.end() != it)
throw InvalidArgumentException("Destination already exists.");
Destination dest(_pPDF, HPDF_Page_CreateDestination(_page), name);
Destination dest(&_pDocument->handle(), HPDF_Page_CreateDestination(_page), name);
std::pair<DestinationContainer::iterator, bool> ret =
_destinations.insert(DestinationContainer::value_type(name, dest));
@ -131,7 +154,7 @@ const TextAnnotation& Page::createTextAnnotation(const std::string& name,
if (_textAnnotations.end() != it)
throw InvalidArgumentException("Annotation already exists.");
TextAnnotation ann(_pPDF,
TextAnnotation ann(&_pDocument->handle(),
HPDF_Page_CreateTextAnnot(_page, rect, text.c_str(), encoder),
name);
@ -152,7 +175,7 @@ const LinkAnnotation& Page::createLinkAnnotation(const std::string& name,
if (_linkAnnotations.end() != it)
throw InvalidArgumentException("Annotation already exists.");
LinkAnnotation ann(_pPDF,
LinkAnnotation ann(&_pDocument->handle(),
HPDF_Page_CreateLinkAnnot(_page, rect, dest),
name);
std::pair<LinkAnnotationContainer::iterator, bool> ret =
@ -172,7 +195,7 @@ const LinkAnnotation& Page::createURILinkAnnotation(const std::string& name,
if (_linkAnnotations.end() != it)
throw InvalidArgumentException("Annotation already exists.");
LinkAnnotation ann(_pPDF,
LinkAnnotation ann(&_pDocument->handle(),
HPDF_Page_CreateURILinkAnnot(_page, rect, uri.c_str()),
name);
std::pair<LinkAnnotationContainer::iterator, bool> ret =

235
PDF/src/hpdf_3dmeasure.c Normal file
View File

@ -0,0 +1,235 @@
/*
* << Haru Free PDF Library >> -- hpdf_annotation.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* 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.
*
*/
#include "hpdf_conf.h"
#include "hpdf_utils.h"
#include "hpdf_info.h"
#include "hpdf_3dmeasure.h"
#include "hpdf.h"
/*----------------------------------------------------------------------------*/
/*------ HPDF_3DMeasure -----------------------------------------------------*/
HPDF_STATUS
HPDF_Dict_AddPoint3D(HPDF_Dict dict, const char* key, HPDF_Point3D point)
{
HPDF_Array array;
HPDF_STATUS ret = HPDF_OK;
array = HPDF_Array_New (dict->mmgr);
if (!array)
return HPDF_Error_GetCode ( dict->error);
if (HPDF_Dict_Add (dict, key, array) != HPDF_OK)
return HPDF_Error_GetCode ( dict->error);
ret += HPDF_Array_AddReal(array, point.x);
ret += HPDF_Array_AddReal(array, point.y);
ret += HPDF_Array_AddReal(array, point.z);
return ret;
}
HPDF_3DMeasure
HPDF_3DC3DMeasure_New(HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Point3D firstanchorpoint,
HPDF_Point3D textanchorpoint
)
{
HPDF_3DMeasure measure;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_3DC3DMeasure_New\n"));
measure = HPDF_Dict_New (mmgr);
if (!measure)
return NULL;
if (HPDF_Xref_Add (xref, measure) != HPDF_OK)
return NULL;
ret += HPDF_Dict_AddPoint3D(measure, "A1", firstanchorpoint);
ret += HPDF_Dict_AddPoint3D(measure, "TP", textanchorpoint);
ret += HPDF_Dict_AddName (measure, "Type", "3DMeasure");
ret += HPDF_Dict_AddName (measure, "Subtype", "3DC");
if (ret != HPDF_OK)
return NULL;
return measure;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DMeasure_SetColor(HPDF_3DMeasure measure,
HPDF_RGBColor color)
{
HPDF_Array array;
HPDF_STATUS ret = HPDF_OK;
array = HPDF_Array_New (measure->mmgr);
if (!array)
return HPDF_Error_GetCode (measure->error);
ret = HPDF_Dict_Add (measure, "C", array);
if (ret != HPDF_OK)
return ret;
ret += HPDF_Array_AddName(array, "DeviceRGB");
ret += HPDF_Array_AddReal(array, color.r);
ret += HPDF_Array_AddReal(array, color.g);
ret += HPDF_Array_AddReal(array, color.b);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DMeasure_SetTextSize(HPDF_3DMeasure measure,
HPDF_REAL textsize)
{
HPDF_STATUS ret = HPDF_OK;
ret = HPDF_Dict_AddReal(measure, "TS", textsize);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DMeasure_SetName(HPDF_3DMeasure measure,
const char* name)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_String s;
s = HPDF_String_New (measure->mmgr, name, 0);
if (!s)
return HPDF_Error_GetCode ( s->error);
ret = HPDF_Dict_Add(measure, "TRL", s);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DC3DMeasure_SetTextBoxSize(HPDF_3DMeasure measure,
HPDF_INT32 x,
HPDF_INT32 y)
{
HPDF_Array array;
HPDF_STATUS ret = HPDF_OK;
array = HPDF_Array_New (measure->mmgr);
if (!array)
return HPDF_Error_GetCode (measure->error);
ret = HPDF_Dict_Add (measure, "TB", array);
if (ret != HPDF_OK)
return ret;
ret += HPDF_Array_AddNumber(array, x);
ret += HPDF_Array_AddNumber(array, y);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DC3DMeasure_SetText(HPDF_3DMeasure measure,
const char* text,
HPDF_Encoder encoder)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_String s;
s = HPDF_String_New (measure->mmgr, text, encoder);
if (!s)
return HPDF_Error_GetCode ( s->error);
ret = HPDF_Dict_Add(measure, "UT", s);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DC3DMeasure_SetProjectionAnotation(HPDF_3DMeasure measure,
HPDF_Annotation projectionanotation)
{
HPDF_STATUS ret = HPDF_OK;
ret = HPDF_Dict_Add(measure, "S", projectionanotation);
return ret;
}
HPDF_3DMeasure
HPDF_PD33DMeasure_New(HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Point3D annotationPlaneNormal,
HPDF_Point3D firstAnchorPoint,
HPDF_Point3D secondAnchorPoint,
HPDF_Point3D leaderLinesDirection,
HPDF_Point3D measurementValuePoint,
HPDF_Point3D textYDirection,
HPDF_REAL value,
const char* unitsString
)
{
HPDF_3DMeasure measure;
HPDF_STATUS ret = HPDF_OK;
HPDF_String s;
HPDF_PTRACE((" HPDF_3DC3DMeasure_New\n"));
measure = HPDF_Dict_New (mmgr);
if (!measure)
return NULL;
if (HPDF_Xref_Add (xref, measure) != HPDF_OK)
return NULL;
ret += HPDF_Dict_AddPoint3D(measure, "AP", annotationPlaneNormal);
ret += HPDF_Dict_AddPoint3D(measure, "A1", firstAnchorPoint);
ret += HPDF_Dict_AddPoint3D(measure, "A2", secondAnchorPoint);
ret += HPDF_Dict_AddPoint3D(measure, "D1", leaderLinesDirection);
ret += HPDF_Dict_AddPoint3D(measure, "TP", measurementValuePoint);
ret += HPDF_Dict_AddPoint3D(measure, "TY", textYDirection);
ret += HPDF_Dict_AddReal(measure, "V", value);
s = HPDF_String_New (measure->mmgr, unitsString, 0);
if (!s)
return NULL;
ret = HPDF_Dict_Add(measure, "U", s);
ret += HPDF_Dict_AddName (measure, "Type", "3DMeasure");
ret += HPDF_Dict_AddName (measure, "Subtype", "PD3");
if (ret != HPDF_OK)
return NULL;
return measure;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_annotation.c
* << Haru Free PDF Library >> -- hpdf_annotation.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -14,10 +17,11 @@
#include "hpdf_conf.h"
#include "hpdf_utils.h"
#include "hpdf_info.h"
#include "hpdf_annotation.h"
#include "hpdf.h"
const static char *HPDF_ANNOT_TYPE_NAMES[] = {
static const char * const HPDF_ANNOT_TYPE_NAMES[] = {
"Text",
"Link",
"Sound",
@ -30,10 +34,14 @@ const static char *HPDF_ANNOT_TYPE_NAMES[] = {
"Underline",
"Ink",
"FileAttachment",
"Popup"
"Popup",
"3D",
"Squiggly",
"Line",
"Projection"
};
const static char *HPDF_ANNOT_ICON_NAMES_NAMES[] = {
static const char * const HPDF_ANNOT_ICON_NAMES_NAMES[] = {
"Comment",
"Key",
"Note",
@ -43,6 +51,50 @@ const static char *HPDF_ANNOT_ICON_NAMES_NAMES[] = {
"Insert"
};
static const char * const HPDF_ANNOT_INTENT_NAMES[] = {
"FreeTextCallout",
"FreeTextTypeWriter",
"LineArrow",
"LineDimension",
"PolygonCloud",
"PolyLineDimension",
"PolygonDimension"
};
static const char * const HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[] = {
"None",
"Square",
"Circle",
"Diamond",
"OpenArrow",
"ClosedArrow",
"Butt",
"ROpenArrow",
"RClosedArrow",
"Slash"
};
static const char * const HPDF_LINE_ANNOT_CAP_POSITION_NAMES[] = {
"Inline",
"Top"
};
static const char * const HPDF_STAMP_ANNOT_NAME_NAMES[] = {
"Approved",
"Experimental",
"NotApproved",
"AsIs",
"Expired",
"NotForPublicRelease",
"Confidential",
"Final",
"Sold",
"Departmental",
"ForComment",
"TopSecret",
"Draft",
"ForPublicRelease"
};
static HPDF_BOOL
CheckSubType (HPDF_Annotation annot,
@ -104,7 +156,7 @@ HPDF_Annotation_New (HPDF_MMgr mmgr,
}
HPDF_STATUS
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annotation_SetBorderStyle (HPDF_Annotation annot,
HPDF_BSSubtype subtype,
HPDF_REAL width,
@ -268,12 +320,12 @@ HPDF_LinkAnnot_SetBorderStyle (HPDF_Annotation annot,
ret += HPDF_Array_AddNumber (dash, dash_on);
ret += HPDF_Array_AddNumber (dash, dash_off);
if (ret != HPDF_OK)
return HPDF_CheckError (annot->error);
}
if (ret != HPDF_OK)
return HPDF_CheckError (annot->error);
return ret;
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
@ -309,19 +361,101 @@ HPDF_LinkAnnot_SetHighlightMode (HPDF_Annotation annot,
return ret;
}
HPDF_Annotation
HPDF_TextAnnot_New (HPDF_MMgr mmgr,
HPDF_3DAnnot_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Rect rect,
HPDF_U3D u3d)
{
HPDF_Annotation annot;
HPDF_Dict action, appearance, stream;
HPDF_STATUS ret;
HPDF_PTRACE((" HPDF_3DAnnot_New\n"));
annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_3D, rect);
if (!annot) {
return NULL;
}
HPDF_Dict_Add(annot, "Contents", HPDF_String_New (mmgr, "3D Model", NULL));
action = HPDF_Dict_New (mmgr);
if (!action) {
return NULL;
}
ret = HPDF_Dict_Add (annot, "3DA", action);
if (ret != HPDF_OK) {
return NULL;
}
ret += HPDF_Dict_AddName (action, "A", "PV");
ret += HPDF_Dict_AddBoolean(action, "TB", HPDF_FALSE);
if (ret != HPDF_OK) {
return NULL;
}
if (HPDF_Dict_Add (annot, "3DD", u3d) != HPDF_OK) {
return NULL;
}
appearance = HPDF_Dict_New (mmgr);
if (!appearance) {
return NULL;
}
ret = HPDF_Dict_Add (annot, "AP", appearance);
if (ret != HPDF_OK) {
return NULL;
}
stream = HPDF_Dict_New (mmgr);
if (!stream) {
return NULL;
}
ret = HPDF_Dict_Add (appearance, "N", stream);
if (ret != HPDF_OK) {
return NULL;
}
return annot;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DAnnot_Set3DView (HPDF_Annotation annot)
{
HPDF_Boolean b;
HPDF_PTRACE((" HPDF_3DAnnot_Set3DView\n"));
if (!CheckSubType (annot, HPDF_ANNOT_3D))
return HPDF_INVALID_ANNOTATION;
b = HPDF_Boolean_New (annot->mmgr, 0);
if (!b)
return HPDF_CheckError (annot->error);
return HPDF_Dict_Add (annot, "3DD", b);
}
HPDF_Annotation
HPDF_MarkupAnnot_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder)
HPDF_Encoder encoder,
HPDF_AnnotType subtype)
{
HPDF_Annotation annot;
HPDF_String s;
HPDF_PTRACE((" HPDF_TextAnnot_New\n"));
HPDF_PTRACE((" HPDF_MarkupAnnot_New\n"));
annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_TEXT_NOTES, rect);
annot = HPDF_Annotation_New (mmgr, xref, subtype, rect);
if (!annot)
return NULL;
@ -335,6 +469,90 @@ HPDF_TextAnnot_New (HPDF_MMgr mmgr,
return annot;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetRGBColor (HPDF_Annotation annot, HPDF_RGBColor color)
{
HPDF_Array cArray;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_Annot_SetRGBColor\n"));
cArray = HPDF_Array_New ( annot->mmgr);
if (!cArray)
return HPDF_Error_GetCode ( annot->error);
ret += HPDF_Dict_Add (annot, "C", cArray);
ret += HPDF_Array_AddReal (cArray, color.r);
ret += HPDF_Array_AddReal (cArray, color.g);
ret += HPDF_Array_AddReal (cArray, color.b);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (annot->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetCMYKColor (HPDF_Annotation annot, HPDF_CMYKColor color)
{
HPDF_Array cArray;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_Annot_SetCMYKColor\n"));
cArray = HPDF_Array_New (annot->mmgr);
if (!cArray)
return HPDF_Error_GetCode (annot->error);
ret += HPDF_Dict_Add (annot, "C", cArray);
ret += HPDF_Array_AddReal (cArray, color.c);
ret += HPDF_Array_AddReal (cArray, color.m);
ret += HPDF_Array_AddReal (cArray, color.y);
ret += HPDF_Array_AddReal (cArray, color.k);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (annot->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetGrayColor (HPDF_Annotation annot, HPDF_REAL color)
{
HPDF_Array cArray;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_Annot_SetGrayColor\n"));
cArray = HPDF_Array_New (annot->mmgr);
if (!cArray)
return HPDF_Error_GetCode ( annot->error);
ret += HPDF_Dict_Add (annot, "C", cArray);
ret += HPDF_Array_AddReal ( cArray, color);
if (ret != HPDF_OK)
return HPDF_Error_GetCode ( annot->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_SetNoColor (HPDF_Annotation annot)
{
HPDF_Array cArray;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_Annot_SetNoColor\n"));
cArray = HPDF_Array_New (annot->mmgr);
if (!cArray)
return HPDF_Error_GetCode ( annot->error);
ret = HPDF_Dict_Add (annot, "C", cArray);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_TextAnnot_SetIcon (HPDF_Annotation annot,
@ -345,7 +563,7 @@ HPDF_TextAnnot_SetIcon (HPDF_Annotation annot,
if (!CheckSubType (annot, HPDF_ANNOT_TEXT_NOTES))
return HPDF_INVALID_ANNOTATION;
if (icon < 0 || icon >= HPDF_ANNOT_ICON_EOF)
if (icon >= HPDF_ANNOT_ICON_EOF)
return HPDF_RaiseError (annot->error, HPDF_ANNOT_INVALID_ICON,
(HPDF_STATUS)icon);
@ -375,6 +593,162 @@ HPDF_TextAnnot_SetOpened (HPDF_Annotation annot,
return HPDF_Dict_Add (annot, "Open", b);
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_PopupAnnot_SetOpened (HPDF_Annotation annot,
HPDF_BOOL opened)
{
HPDF_Boolean b;
HPDF_PTRACE((" HPDF_TextAnnot_SetOpend\n"));
if (!CheckSubType (annot, HPDF_ANNOT_POPUP))
return HPDF_INVALID_ANNOTATION;
b = HPDF_Boolean_New (annot->mmgr, opened);
if (!b)
return HPDF_CheckError (annot->error);
return HPDF_Dict_Add (annot, "Open", b);
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetTitle (HPDF_Annotation annot, const char* name)
{
HPDF_PTRACE((" HPDF_MarkupAnnot_SetTitle\n"));
return HPDF_Dict_Add( annot, "T", HPDF_String_New( annot->mmgr, name, NULL));
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetSubject (HPDF_Annotation annot, const char* name)
{
HPDF_PTRACE((" HPDF_MarkupAnnot_SetSubject\n"));
return HPDF_Dict_Add( annot, "Subj", HPDF_String_New( annot->mmgr, name, NULL));
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetCreationDate (HPDF_Annotation annot, HPDF_Date value)
{
HPDF_PTRACE((" HPDF_MarkupAnnot_SetCreationDate\n"));
return HPDF_Info_SetInfoDateAttr( annot, HPDF_INFO_CREATION_DATE, value);
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetTransparency (HPDF_Annotation annot, HPDF_REAL value)
{
HPDF_PTRACE((" HPDF_MarkupAnnot_SetTransparency\n"));
return HPDF_Dict_AddReal( annot, "CA", value);
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetIntent (HPDF_Annotation annot,
HPDF_AnnotIntent intent)
{
HPDF_PTRACE((" HPDF_MarkupAnnot_SetIntent\n"));
if (HPDF_Dict_AddName (annot, "IT",
HPDF_ANNOT_INTENT_NAMES[(HPDF_INT)intent]) != HPDF_OK)
return HPDF_CheckError (annot->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetPopup (HPDF_Annotation annot,
HPDF_Annotation popup)
{
HPDF_PTRACE((" HPDF_MarkupAnnot_SetPopup\n"));
return HPDF_Dict_Add( annot, "Popup", popup);
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorRGBColor (HPDF_Annotation annot, HPDF_RGBColor color)/* IC with RGB entry */
{
HPDF_Array cArray;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorRGBColor\n"));
cArray = HPDF_Array_New ( annot->mmgr);
if (!cArray)
return HPDF_Error_GetCode ( annot->error);
ret += HPDF_Dict_Add (annot, "IC", cArray);
ret += HPDF_Array_AddReal (cArray, color.r);
ret += HPDF_Array_AddReal (cArray, color.g);
ret += HPDF_Array_AddReal (cArray, color.b);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (annot->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorCMYKColor (HPDF_Annotation annot, HPDF_CMYKColor color)/* IC with CMYK entry */
{
HPDF_Array cArray;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorCMYKColor\n"));
cArray = HPDF_Array_New ( annot->mmgr);
if (!cArray)
return HPDF_Error_GetCode ( annot->error);
ret += HPDF_Dict_Add (annot, "IC", cArray);
ret += HPDF_Array_AddReal (cArray, color.c);
ret += HPDF_Array_AddReal (cArray, color.m);
ret += HPDF_Array_AddReal (cArray, color.y);
ret += HPDF_Array_AddReal (cArray, color.k);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (annot->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorGrayColor (HPDF_Annotation annot, HPDF_REAL color)/* IC with Gray entry */
{
HPDF_Array cArray;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorGrayColor\n"));
cArray = HPDF_Array_New ( annot->mmgr);
if (!cArray)
return HPDF_Error_GetCode ( annot->error);
ret += HPDF_Dict_Add (annot, "IC", cArray);
ret += HPDF_Array_AddReal (cArray, color);
if (ret != HPDF_OK)
return HPDF_Error_GetCode ( annot->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetInteriorTransparent (HPDF_Annotation annot) /* IC with No Color entry */
{
HPDF_Array cArray;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_MarkupAnnot_SetInteriorTransparent\n"));
cArray = HPDF_Array_New ( annot->mmgr);
if (!cArray)
return HPDF_Error_GetCode ( annot->error);
ret = HPDF_Dict_Add (annot, "IC", cArray);
return ret;
}
HPDF_BOOL
HPDF_Annotation_Validate (HPDF_Annotation annot)
@ -413,3 +787,380 @@ CheckSubType (HPDF_Annotation annot,
return HPDF_TRUE;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_Annot_Set3DView ( HPDF_MMgr mmgr,
HPDF_Annotation annot,
HPDF_Annotation annot3d,
HPDF_Dict view3d)
{
HPDF_Proxy proxyView3d;
HPDF_Dict exData = HPDF_Dict_New( mmgr);
HPDF_STATUS retS = HPDF_OK;
retS += HPDF_Dict_AddName( exData, "Type", "ExData");
retS += HPDF_Dict_AddName( exData, "Subtype", "Markup3D");
retS += HPDF_Dict_Add( exData, "3DA", annot3d);
proxyView3d = HPDF_Proxy_New( mmgr, view3d);
retS += HPDF_Dict_Add( exData, "3DV", proxyView3d);
retS += HPDF_Dict_Add( annot, "ExData", exData);
return retS;
}
HPDF_Annotation
HPDF_PopupAnnot_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Rect rect,
HPDF_Annotation parent)
{
HPDF_Annotation annot;
HPDF_PTRACE((" HPDF_PopupAnnot_New\n"));
annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_POPUP, rect);
if (!annot)
return NULL;
if (HPDF_Dict_Add (annot, "Parent", parent) != HPDF_OK)
return NULL;
return annot;
}
HPDF_Annotation
HPDF_StampAnnot_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Rect rect,
HPDF_StampAnnotName name,
const char* text,
HPDF_Encoder encoder)
{
HPDF_Annotation annot;
HPDF_String s;
HPDF_PTRACE((" HPDF_StampAnnot_New\n"));
annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_STAMP, rect);
if (!annot)
return NULL;
if (HPDF_Dict_AddName ( annot, "Name", HPDF_STAMP_ANNOT_NAME_NAMES[name]) != HPDF_OK)
return NULL;
s = HPDF_String_New (mmgr, text, encoder);
if (!s)
return NULL;
if (HPDF_Dict_Add (annot, "Contents", s) != HPDF_OK)
return NULL;
return annot;
}
HPDF_Annotation
HPDF_ProjectionAnnot_New(HPDF_MMgr mmgr,
HPDF_Xref xref,
HPDF_Rect rect,
const char* text,
HPDF_Encoder encoder)
{
HPDF_Annotation annot;
HPDF_String s;
HPDF_PTRACE((" HPDF_StampAnnot_New\n"));
annot = HPDF_Annotation_New (mmgr, xref, HPDF_ANNOT_PROJECTION, rect);
if (!annot)
return NULL;
s = HPDF_String_New (mmgr, text, encoder);
if (!s)
return NULL;
if (HPDF_Dict_Add (annot, "Contents", s) != HPDF_OK)
return NULL;
return annot;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_TextMarkupAnnot_SetQuadPoints ( HPDF_Annotation annot, HPDF_Point lb, HPDF_Point rb, HPDF_Point lt, HPDF_Point rt) /* l-left, r-right, b-bottom, t-top positions */
{
HPDF_Array quadPoints;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_TextMarkupAnnot_SetQuadPoints\n"));
quadPoints = HPDF_Array_New ( annot->mmgr);
if ( !quadPoints)
return HPDF_Error_GetCode ( annot->error);
if ((ret = HPDF_Dict_Add ( annot, "QuadPoints", quadPoints)) != HPDF_OK)
return ret;
ret += HPDF_Array_AddReal (quadPoints, lb.x);
ret += HPDF_Array_AddReal (quadPoints, lb.y);
ret += HPDF_Array_AddReal (quadPoints, rb.x);
ret += HPDF_Array_AddReal (quadPoints, rb.y);
ret += HPDF_Array_AddReal (quadPoints, lt.x);
ret += HPDF_Array_AddReal (quadPoints, lt.y);
ret += HPDF_Array_AddReal (quadPoints, rt.x);
ret += HPDF_Array_AddReal (quadPoints, rt.y);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (quadPoints->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_SetLineEndingStyle (HPDF_Annotation annot, HPDF_LineAnnotEndingStyle startStyle, HPDF_LineAnnotEndingStyle endStyle)
{
HPDF_Array lineEndStyles;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_FreeTextAnnot_SetLineEndingStyle\n"));
lineEndStyles = HPDF_Array_New ( annot->mmgr);
if ( !lineEndStyles)
return HPDF_Error_GetCode ( annot->error);
if ((ret = HPDF_Dict_Add ( annot, "LE", lineEndStyles)) != HPDF_OK)
return ret;
ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)startStyle]);
ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)endStyle]);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (lineEndStyles->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetRectDiff (HPDF_Annotation annot, HPDF_Rect rect) /* RD entry : this is the difference between Rect and the text annotation rectangle */
{
HPDF_Array array;
HPDF_STATUS ret = HPDF_OK;
HPDF_REAL tmp;
HPDF_PTRACE((" HPDF_MarkupAnnot_SetRectDiff\n"));
array = HPDF_Array_New ( annot->mmgr);
if ( !array)
return HPDF_Error_GetCode ( annot->error);
if ((ret = HPDF_Dict_Add ( annot, "RD", array)) != HPDF_OK)
return ret;
if (rect.top < rect.bottom) {
tmp = rect.top;
rect.top = rect.bottom;
rect.bottom = tmp;
}
ret += HPDF_Array_AddReal (array, rect.left);
ret += HPDF_Array_AddReal (array, rect.bottom);
ret += HPDF_Array_AddReal (array, rect.right);
ret += HPDF_Array_AddReal (array, rect.top);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (array->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_SetDefaultStyle (HPDF_Annotation annot,
const char* style)
{
HPDF_String s;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_FreeTextAnnot_SetDefaultStyle\n"));
s = HPDF_String_New ( annot->mmgr, style, NULL);
if ( !s)
return HPDF_Error_GetCode ( annot->error);
ret = HPDF_Dict_Add ( annot, "DS", s);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_Set3PointCalloutLine ( HPDF_Annotation annot, HPDF_Point startPoint, HPDF_Point kneePoint, HPDF_Point endPoint) /* Callout line will be in default user space */
{
HPDF_Array clPoints;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_FreeTextAnnot_Set3PointCalloutLine\n"));
clPoints = HPDF_Array_New ( annot->mmgr);
if ( !clPoints)
return HPDF_Error_GetCode ( annot->error);
if ((ret = HPDF_Dict_Add ( annot, "CL", clPoints)) != HPDF_OK)
return ret;
ret += HPDF_Array_AddReal (clPoints, startPoint.x);
ret += HPDF_Array_AddReal (clPoints, startPoint.y);
ret += HPDF_Array_AddReal (clPoints, kneePoint.x);
ret += HPDF_Array_AddReal (clPoints, kneePoint.y);
ret += HPDF_Array_AddReal (clPoints, endPoint.x);
ret += HPDF_Array_AddReal (clPoints, endPoint.y);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (clPoints->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_FreeTextAnnot_Set2PointCalloutLine ( HPDF_Annotation annot, HPDF_Point startPoint, HPDF_Point endPoint) /* Callout line will be in default user space */
{
HPDF_Array clPoints;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_FreeTextAnnot_Set3PointCalloutLine\n"));
clPoints = HPDF_Array_New ( annot->mmgr);
if ( !clPoints)
return HPDF_Error_GetCode ( annot->error);
if ((ret = HPDF_Dict_Add ( annot, "CL", clPoints)) != HPDF_OK)
return ret;
ret += HPDF_Array_AddReal (clPoints, startPoint.x);
ret += HPDF_Array_AddReal (clPoints, startPoint.y);
ret += HPDF_Array_AddReal (clPoints, endPoint.x);
ret += HPDF_Array_AddReal (clPoints, endPoint.y);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (clPoints->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_MarkupAnnot_SetCloudEffect (HPDF_Annotation annot, HPDF_INT cloudIntensity) /* BE entry */
{
HPDF_Dict borderEffect;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_MarkupAnnot_SetCloudEffect\n"));
borderEffect = HPDF_Dict_New ( annot->mmgr);
if (!borderEffect)
return HPDF_Error_GetCode ( annot->error);
ret += HPDF_Dict_Add ( annot, "BE", borderEffect);
ret += HPDF_Dict_AddName ( borderEffect, "S", "C");
ret += HPDF_Dict_AddNumber ( borderEffect, "I", cloudIntensity);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (annot->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_LineAnnot_SetPosition (HPDF_Annotation annot,
HPDF_Point startPoint, HPDF_LineAnnotEndingStyle startStyle,
HPDF_Point endPoint, HPDF_LineAnnotEndingStyle endStyle)
{
HPDF_Array lineEndPoints;
HPDF_Array lineEndStyles;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_LineAnnot_SetPosition\n"));
lineEndPoints = HPDF_Array_New ( annot->mmgr);
if ( !lineEndPoints)
return HPDF_Error_GetCode ( annot->error);
if ((ret = HPDF_Dict_Add ( annot, "L", lineEndPoints)) != HPDF_OK)
return ret;
ret += HPDF_Array_AddReal (lineEndPoints, startPoint.x);
ret += HPDF_Array_AddReal (lineEndPoints, startPoint.y);
ret += HPDF_Array_AddReal (lineEndPoints, endPoint.x);
ret += HPDF_Array_AddReal (lineEndPoints, endPoint.y);
if (ret != HPDF_OK)
return HPDF_Error_GetCode ( lineEndPoints->error);
lineEndStyles = HPDF_Array_New ( annot->mmgr);
if ( !lineEndStyles)
return HPDF_Error_GetCode ( annot->error);
if ((ret = HPDF_Dict_Add ( annot, "LE", lineEndStyles)) != HPDF_OK)
return ret;
ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)startStyle]);
ret += HPDF_Array_AddName (lineEndStyles, HPDF_LINE_ANNOT_ENDING_STYLE_NAMES[(HPDF_INT)endStyle]);
if (ret != HPDF_OK)
return HPDF_Error_GetCode ( lineEndStyles->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_LineAnnot_SetLeader (HPDF_Annotation annot, HPDF_INT leaderLen, HPDF_INT leaderExtLen, HPDF_INT leaderOffsetLen)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_LineAnnot_SetLeader\n"));
ret += HPDF_Dict_AddNumber ( annot, "LL", leaderLen);
ret += HPDF_Dict_AddNumber ( annot, "LLE", leaderExtLen);
ret += HPDF_Dict_AddNumber ( annot, "LLO", leaderOffsetLen);
if (ret != HPDF_OK)
return HPDF_Error_GetCode ( annot->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_LineAnnot_SetCaption (HPDF_Annotation annot, HPDF_BOOL showCaption, HPDF_LineAnnotCapPosition position, HPDF_INT horzOffset, HPDF_INT vertOffset)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_Array capOffset;
HPDF_PTRACE((" HPDF_LineAnnot_SetCaption\n"));
ret += HPDF_Dict_AddBoolean ( annot, "Cap", showCaption);
ret += HPDF_Dict_AddName( annot, "CP", HPDF_LINE_ANNOT_CAP_POSITION_NAMES[(HPDF_INT)position]);
if (ret != HPDF_OK)
return HPDF_Error_GetCode ( annot->error);
capOffset = HPDF_Array_New ( annot->mmgr);
if ( !capOffset)
return HPDF_Error_GetCode ( annot->error);
if ((ret = HPDF_Dict_Add ( annot, "CO", capOffset)) != HPDF_OK)
return ret;
ret += HPDF_Array_AddNumber (capOffset, horzOffset);
ret += HPDF_Array_AddNumber (capOffset, vertOffset);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (capOffset->error);
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_ProjectionAnnot_SetExData(HPDF_Annotation annot, HPDF_ExData exdata)
{
HPDF_STATUS ret = HPDF_OK;
ret = HPDF_Dict_Add(annot, "ExData", exdata);
return ret;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_array.c
* << Haru Free PDF Library >> -- hpdf_array.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -211,6 +214,13 @@ HPDF_Array_Add (HPDF_Array array,
}
HPDF_UINT
HPDF_Array_Items (HPDF_Array array)
{
return array->list->count;
}
HPDF_STATUS
HPDF_Array_Insert (HPDF_Array array,
void *target,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_binary.c
* << Haru Free PDF Library >> -- hpdf_binary.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_boolean.h
* << Haru Free PDF Library >> -- hpdf_boolean.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.5 >> -- hpdf_catalog.c
* << Haru Free PDF Library >> -- hpdf_catalog.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -10,8 +13,6 @@
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
* 2006.08.07 modified.
* 2006.09.01 added ViewerPreference functions.
*/
#include "hpdf_conf.h"
@ -19,16 +20,18 @@
#include "hpdf_catalog.h"
#include "hpdf_pages.h"
static const char *HPDF_PAGE_LAYOUT_NAMES[] = {
static const char * const HPDF_PAGE_LAYOUT_NAMES[] = {
"SinglePage",
"OneColumn",
"TwoColumnLeft",
"TwoColumnRight",
"TwoPageLeft",
"TwoPageRight",
NULL
};
static const char *HPDF_PAGE_MODE_NAMES[] = {
static const char * const HPDF_PAGE_MODE_NAMES[] = {
"UseNone",
"UseOutlines",
"UseThumbs",
@ -83,6 +86,23 @@ HPDF_Catalog_GetRoot (HPDF_Catalog catalog)
}
HPDF_NameDict
HPDF_Catalog_GetNames (HPDF_Catalog catalog)
{
if (!catalog)
return NULL;
return HPDF_Dict_GetItem (catalog, "Names", HPDF_OCLASS_DICT);
}
HPDF_STATUS
HPDF_Catalog_SetNames (HPDF_Catalog catalog,
HPDF_NameDict dict)
{
return HPDF_Dict_Add (catalog, "Names", dict);
}
HPDF_PageLayout
HPDF_Catalog_GetPageLayout (HPDF_Catalog catalog)
{
@ -296,6 +316,17 @@ HPDF_Catalog_SetViewerPreference (HPDF_Catalog catalog,
return ret;
}
if (value & HPDF_PRINT_SCALING_NONE) {
if ((ret = HPDF_Dict_AddName (preferences, "PrintScaling",
"None")) != HPDF_OK)
return ret;
} else {
if ((ret = HPDF_Dict_RemoveElement (preferences, "PrintScaling")) !=
HPDF_OK)
if (ret != HPDF_DICT_ITEM_NOT_FOUND)
return ret;
}
return HPDF_OK;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_destination.c
* << Haru Free PDF Library >> -- hpdf_destination.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -16,7 +19,7 @@
#include "hpdf_utils.h"
#include "hpdf.h"
const char *HPDF_DESTINATION_TYPE_NAMES[] = {
const char * const HPDF_DESTINATION_TYPE_NAMES[] = {
"XYZ",
"Fit",
"FitH",
@ -82,8 +85,10 @@ HPDF_Destination_Validate (HPDF_Destination dst)
return HPDF_FALSE;
target = (HPDF_Page)HPDF_Array_GetItem (dst, 0, HPDF_OCLASS_DICT);
if (!HPDF_Page_Validate (target))
return HPDF_SetError (dst->error, HPDF_INVALID_PAGE, 0);
if (!HPDF_Page_Validate (target)) {
HPDF_SetError (dst->error, HPDF_INVALID_PAGE, 0);
return HPDF_FALSE;
}
return HPDF_TRUE;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.5 >> -- HPDF_Dict.c
* << Haru Free PDF Library >> -- hpdf_dict.c
*
* Copyright (c) 1999-2004 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -113,6 +116,25 @@ HPDF_Dict_Free (HPDF_Dict dict)
HPDF_FreeMem (dict->mmgr, dict);
}
HPDF_STATUS
HPDF_Dict_Add_FilterParams(HPDF_Dict dict, HPDF_Dict filterParam)
{
HPDF_Array paramArray;
/* prepare params object */
paramArray = HPDF_Dict_GetItem (dict, "DecodeParms",
HPDF_OCLASS_ARRAY);
if(paramArray==NULL) {
paramArray = HPDF_Array_New (dict->mmgr);
if (!paramArray)
return HPDF_Error_GetCode (dict->error);
/* add parameters */
HPDF_Dict_Add(dict, "DecodeParms", paramArray);
}
HPDF_Array_Add(paramArray, filterParam);
return HPDF_OK;
}
HPDF_STATUS
HPDF_Dict_Write (HPDF_Dict dict,
@ -155,13 +177,21 @@ HPDF_Dict_Write (HPDF_Dict dict,
HPDF_Array_Clear (array);
#ifndef HPDF_NOZLIB
#ifndef LIBHPDF_HAVE_NOZLIB
if (dict->filter & HPDF_STREAM_FILTER_FLATE_DECODE)
HPDF_Array_AddName (array, "FlateDecode");
#endif /* HPDF_NOZLIB */
#endif /* LIBHPDF_HAVE_NOZLIB */
if (dict->filter & HPDF_STREAM_FILTER_DCT_DECODE)
HPDF_Array_AddName (array, "DCTDecode");
if(dict->filter & HPDF_STREAM_FILTER_CCITT_DECODE)
HPDF_Array_AddName (array, "CCITTFaxDecode");
if(dict->filterParams!=NULL)
{
HPDF_Dict_Add_FilterParams(dict, dict->filterParams);
}
}
}
@ -220,7 +250,7 @@ HPDF_Dict_Write (HPDF_Dict dict,
0);
}
if ((ret = HPDF_Stream_WriteStr (stream, "\012stream\015\012"))
if ((ret = HPDF_Stream_WriteStr (stream, "\012stream\015\012")) /* Acrobat 8.15 requires both \r and \n here */
!= HPDF_OK)
return ret;

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.5 >> -- hpdf_doc.c
* << Haru Free PDF Library >> -- hpdf_doc.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -16,18 +19,20 @@
#include "hpdf_conf.h"
#include "hpdf_utils.h"
#include "hpdf_encryptdict.h"
#include "hpdf_namedict.h"
#include "hpdf_destination.h"
#include "hpdf_info.h"
#include "hpdf_page_label.h"
#include "hpdf.h"
static const char *HPDF_VERSION_STR[5] = {
static const char * const HPDF_VERSION_STR[6] = {
"%PDF-1.2\012%\267\276\255\252\012",
"%PDF-1.3\012%\267\276\255\252\012",
"%PDF-1.4\012%\267\276\255\252\012",
"%PDF-1.5\012%\267\276\255\252\012",
"%PDF-1.6\012%\267\276\255\252\012"
"%PDF-1.6\012%\267\276\255\252\012",
"%PDF-1.7\012%\267\276\255\252\012"
};
@ -255,7 +260,7 @@ HPDF_NewDoc (HPDF_Doc pdf)
pdf->cur_pages = pdf->root_pages;
ptr = HPDF_StrCpy (ptr, "Haru Free PDF Library ", eptr);
ptr = (char *)HPDF_StrCpy (ptr, (const char *)"Haru Free PDF Library ", eptr);
version = HPDF_GetVersion ();
HPDF_StrCpy (ptr, version, eptr);
@ -647,6 +652,39 @@ HPDF_SaveToStream (HPDF_Doc pdf)
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_GetContents (HPDF_Doc pdf,
HPDF_BYTE *buf,
HPDF_UINT32 *size)
{
HPDF_Stream stream;
HPDF_UINT isize = *size;
HPDF_STATUS ret;
HPDF_PTRACE ((" HPDF_GetContents\n"));
if (!HPDF_HasDoc (pdf)) {
return HPDF_INVALID_DOCUMENT;
}
stream = HPDF_MemStream_New (pdf->mmgr, HPDF_STREAM_BUF_SIZ);
if (!stream) {
return HPDF_CheckError (&pdf->error);
}
if (InternalSaveToStream (pdf, stream) != HPDF_OK) {
HPDF_Stream_Free (stream);
return HPDF_CheckError (&pdf->error);
}
ret = HPDF_Stream_Read (stream, buf, &isize);
*size = isize;
HPDF_Stream_Free (stream);
return ret;
}
HPDF_EXPORT(HPDF_UINT32)
HPDF_GetStreamSize (HPDF_Doc pdf)
@ -1186,11 +1224,12 @@ HPDF_SetCurrentEncoder (HPDF_Doc pdf,
return HPDF_GetError (pdf);
encoder = HPDF_GetEncoder (pdf, encoding_name);
pdf->cur_encoder = encoder;
if (!pdf)
if (!encoder)
return HPDF_GetError (pdf);
pdf->cur_encoder = encoder;
return HPDF_OK;
}
@ -1281,6 +1320,11 @@ HPDF_GetFont (HPDF_Doc pdf,
return NULL;
}
if (!encoder) {
HPDF_CheckError (&pdf->error);
return NULL;
}
font = HPDF_Doc_FindFont (pdf, font_name, encoder->name);
} else {
font = HPDF_Doc_FindFont (pdf, font_name, encoding_name);
@ -1412,10 +1456,33 @@ LoadType1FontFromStream (HPDF_Doc pdf,
HPDF_FontDef_Free (def);
return NULL;
}
return def->base_font;
}
return def->base_font;
return NULL;
}
HPDF_EXPORT(HPDF_FontDef)
HPDF_GetTTFontDefFromFile (HPDF_Doc pdf,
const char *file_name,
HPDF_BOOL embedding)
{
HPDF_Stream font_data;
HPDF_FontDef def;
HPDF_PTRACE ((" HPDF_GetTTFontDefFromFile\n"));
/* create file stream */
font_data = HPDF_FileReader_New (pdf->mmgr, file_name);
if (HPDF_Stream_Validate (font_data)) {
def = HPDF_TTFontDef_Load (pdf->mmgr, font_data, embedding);
} else {
HPDF_CheckError (&pdf->error);
return NULL;
}
return def;
}
HPDF_EXPORT(const char*)
HPDF_LoadTTFontFromFile (HPDF_Doc pdf,
@ -1454,14 +1521,14 @@ LoadTTFontFromStream (HPDF_Doc pdf,
HPDF_FontDef def;
HPDF_PTRACE ((" HPDF_LoadTTFontFromStream\n"));
HPDF_UNUSED (file_name);
def = HPDF_TTFontDef_Load (pdf->mmgr, font_data, embedding);
if (def) {
HPDF_FontDef tmpdef = HPDF_Doc_FindFontDef (pdf, def->base_font);
if (tmpdef) {
HPDF_FontDef_Free (def);
HPDF_SetError (&pdf->error, HPDF_FONT_EXISTS, 0);
return NULL;
return tmpdef->base_font;
}
if (HPDF_List_Add (pdf->fontdef_list, def) != HPDF_OK) {
@ -1473,7 +1540,7 @@ LoadTTFontFromStream (HPDF_Doc pdf,
if (embedding) {
if (pdf->ttfont_tag[0] == 0) {
HPDF_MemCpy (pdf->ttfont_tag, "HPDFAA", 6);
HPDF_MemCpy (pdf->ttfont_tag, (HPDF_BYTE *)"HPDFAA", 6);
} else {
HPDF_INT i;
@ -1486,7 +1553,7 @@ LoadTTFontFromStream (HPDF_Doc pdf,
}
}
HPDF_TTFontDef_SetTagName (def, pdf->ttfont_tag);
HPDF_TTFontDef_SetTagName (def, (char *)pdf->ttfont_tag);
}
return def->base_font;
@ -1532,14 +1599,14 @@ LoadTTFontFromStream2 (HPDF_Doc pdf,
HPDF_FontDef def;
HPDF_PTRACE ((" HPDF_LoadTTFontFromStream2\n"));
HPDF_UNUSED (file_name);
def = HPDF_TTFontDef_Load2 (pdf->mmgr, font_data, index, embedding);
if (def) {
HPDF_FontDef tmpdef = HPDF_Doc_FindFontDef (pdf, def->base_font);
if (tmpdef) {
HPDF_FontDef_Free (def);
HPDF_SetError (&pdf->error, HPDF_FONT_EXISTS, 0);
return NULL;
return tmpdef->base_font;
}
if (HPDF_List_Add (pdf->fontdef_list, def) != HPDF_OK) {
@ -1551,7 +1618,7 @@ LoadTTFontFromStream2 (HPDF_Doc pdf,
if (embedding) {
if (pdf->ttfont_tag[0] == 0) {
HPDF_MemCpy (pdf->ttfont_tag, "HPDFAA", 6);
HPDF_MemCpy (pdf->ttfont_tag, (HPDF_BYTE *)"HPDFAA", 6);
} else {
HPDF_INT i;
@ -1564,7 +1631,7 @@ LoadTTFontFromStream2 (HPDF_Doc pdf,
}
}
HPDF_TTFontDef_SetTagName (def, pdf->ttfont_tag);
HPDF_TTFontDef_SetTagName (def, (char *)pdf->ttfont_tag);
}
return def->base_font;
@ -1601,7 +1668,7 @@ HPDF_LoadRawImageFromFile (HPDF_Doc pdf,
if (!image)
HPDF_CheckError (&pdf->error);
if (pdf->compression_mode & HPDF_COMP_IMAGE)
if (image && pdf->compression_mode & HPDF_COMP_IMAGE)
image->filter = HPDF_STREAM_FILTER_FLATE_DECODE;
return image;
@ -1623,14 +1690,19 @@ HPDF_LoadRawImageFromMem (HPDF_Doc pdf,
if (!HPDF_HasDoc (pdf))
return NULL;
image = HPDF_Image_LoadRawImageFromMem (pdf->mmgr, buf, pdf->xref, width,
height, color_space, bits_per_component);
/* Use directly HPDF_Image_LoadRaw1BitImageFromMem to save B/W images */
if(color_space == HPDF_CS_DEVICE_GRAY && bits_per_component == 1) {
return HPDF_Image_LoadRaw1BitImageFromMem (pdf, buf, width, height, (width+7)/8, HPDF_TRUE, HPDF_TRUE);
}
image = HPDF_Image_LoadRawImageFromMem (pdf->mmgr, buf, pdf->xref, width, height, color_space, bits_per_component);
if (!image)
HPDF_CheckError (&pdf->error);
if (pdf->compression_mode & HPDF_COMP_IMAGE)
if (image && pdf->compression_mode & HPDF_COMP_IMAGE) {
image->filter = HPDF_STREAM_FILTER_FLATE_DECODE;
}
return image;
}
@ -1665,6 +1737,27 @@ HPDF_LoadJpegImageFromFile (HPDF_Doc pdf,
return image;
}
HPDF_EXPORT(HPDF_Image)
HPDF_LoadJpegImageFromMem (HPDF_Doc pdf,
const HPDF_BYTE *buffer,
HPDF_UINT size)
{
HPDF_Image image;
HPDF_PTRACE ((" HPDF_LoadJpegImageFromMem\n"));
if (!HPDF_HasDoc (pdf)) {
return NULL;
}
image = HPDF_Image_LoadJpegImageFromMem (pdf->mmgr, buffer, size , pdf->xref);
if (!image) {
HPDF_CheckError (&pdf->error);
}
return image;
}
/*----- Catalog ------------------------------------------------------------*/
@ -1695,6 +1788,9 @@ HPDF_SetPageLayout (HPDF_Doc pdf,
return HPDF_RaiseError (&pdf->error, HPDF_PAGE_LAYOUT_OUT_OF_RANGE,
(HPDF_STATUS)layout);
if ((layout == HPDF_PAGE_LAYOUT_TWO_PAGE_LEFT || layout == HPDF_PAGE_LAYOUT_TWO_PAGE_RIGHT) && pdf->pdf_version < HPDF_VER_15)
pdf->pdf_version = HPDF_VER_15 ;
ret = HPDF_Catalog_SetPageLayout (pdf->catalog, layout);
if (ret != HPDF_OK)
HPDF_CheckError (&pdf->error);
@ -1786,6 +1882,8 @@ HPDF_SetViewerPreference (HPDF_Doc pdf,
if (ret != HPDF_OK)
return HPDF_CheckError (&pdf->error);
pdf->pdf_version = HPDF_VER_16;
return HPDF_OK;
}
@ -1822,6 +1920,58 @@ HPDF_AddPageLabel (HPDF_Doc pdf,
}
HPDF_EXPORT(HPDF_EmbeddedFile)
HPDF_AttachFile (HPDF_Doc pdf,
const char *file)
{
HPDF_NameDict names;
HPDF_NameTree ntree;
HPDF_EmbeddedFile efile;
HPDF_String name;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE ((" HPDF_AttachFile\n"));
if (!HPDF_HasDoc (pdf))
return NULL;
names = HPDF_Catalog_GetNames (pdf->catalog);
if (!names) {
names = HPDF_NameDict_New (pdf->mmgr, pdf->xref);
if (!names)
return NULL;
ret = HPDF_Catalog_SetNames (pdf->catalog, names);
if (ret != HPDF_OK)
return NULL;
}
ntree = HPDF_NameDict_GetNameTree (names, HPDF_NAME_EMBEDDED_FILES);
if (!ntree) {
ntree = HPDF_NameTree_New (pdf->mmgr, pdf->xref);
if (!ntree)
return NULL;
ret = HPDF_NameDict_SetNameTree (names, HPDF_NAME_EMBEDDED_FILES, ntree);
if (ret != HPDF_OK)
return NULL;
}
efile = HPDF_EmbeddedFile_New (pdf->mmgr, pdf->xref, file);
if (!efile)
return NULL;
name = HPDF_String_New (pdf->mmgr, file, NULL);
if (!name)
return NULL;
ret += HPDF_NameTree_Add (ntree, name, efile);
if (ret != HPDF_OK)
return NULL;
return efile;
}
/*----- Info ---------------------------------------------------------------*/
static HPDF_Dict
@ -1976,16 +2126,16 @@ HPDF_SetCompressionMode (HPDF_Doc pdf,
if (mode != (mode & HPDF_COMP_MASK))
return HPDF_RaiseError (&pdf->error, HPDF_INVALID_COMPRESSION_MODE, 0);
#ifndef HPDF_NOZLIB
#ifndef LIBHPDF_HAVE_NOZLIB
pdf->compression_mode = mode;
return HPDF_OK;
#else /* HPDF_NOZLIB */
#else /* LIBHPDF_HAVE_NOZLIB */
return HPDF_INVALID_COMPRESSION_MODE;
#endif /* HPDF_NOZLIB */
#endif /* LIBHPDF_HAVE_NOZLIB */
}
@ -2018,3 +2168,201 @@ HPDF_ResetError (HPDF_Doc pdf)
HPDF_Error_Reset (&pdf->error);
}
/*
* create an intententry
*/
HPDF_EXPORT(HPDF_OutputIntent)
HPDF_OutputIntent_New (HPDF_Doc pdf,
const char* identifier,
const char* condition,
const char* registry,
const char* info,
HPDF_Array outputprofile)
{
HPDF_OutputIntent intent;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_OutputIntent_New\n"));
if (!HPDF_HasDoc (pdf))
return NULL;
intent = HPDF_Dict_New (pdf->mmgr);
if (!intent)
return NULL;
if (HPDF_Xref_Add (pdf->xref, intent) != HPDF_OK) {
HPDF_Dict_Free(intent);
return NULL;
}
ret += HPDF_Dict_AddName (intent, "Type", "OutputIntent");
ret += HPDF_Dict_AddName (intent, "S", "GTS_PDFX");
ret += HPDF_Dict_Add (intent, "OutputConditionIdentifier", HPDF_String_New (pdf->mmgr, identifier, NULL));
ret += HPDF_Dict_Add (intent, "OutputCondition", HPDF_String_New (pdf->mmgr, condition,NULL));
ret += HPDF_Dict_Add (intent, "RegistryName", HPDF_String_New (pdf->mmgr, registry, NULL));
if (info != NULL) {
ret += HPDF_Dict_Add (intent, "Info", HPDF_String_New (pdf->mmgr, info, NULL));
}
/* add ICC base stream */
if (outputprofile != NULL) {
ret += HPDF_Dict_Add (intent, "DestOutputProfile ", outputprofile);
}
if (ret != HPDF_OK) {
HPDF_Dict_Free(intent);
return NULL;
}
return intent;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_AddIntent(HPDF_Doc pdf,
HPDF_OutputIntent intent)
{
HPDF_Array intents;
if (!HPDF_HasDoc (pdf))
return HPDF_INVALID_DOCUMENT;
intents = HPDF_Dict_GetItem (pdf->catalog, "OutputIntents", HPDF_OCLASS_ARRAY);
if (intents == NULL) {
intents = HPDF_Array_New (pdf->mmgr);
if (intents) {
HPDF_STATUS ret = HPDF_Dict_Add (pdf->catalog, "OutputIntents", intents);
if (ret != HPDF_OK) {
HPDF_CheckError (&pdf->error);
return HPDF_Error_GetDetailCode (&pdf->error);
}
}
}
HPDF_Array_Add(intents,intent);
return HPDF_Error_GetDetailCode (&pdf->error);
}
/* "Perceptual", "RelativeColorimetric", "Saturation", "AbsoluteColorimetric" */
HPDF_EXPORT(HPDF_OutputIntent)
HPDF_ICC_LoadIccFromMem (HPDF_Doc pdf,
HPDF_MMgr mmgr,
HPDF_Stream iccdata,
HPDF_Xref xref,
int numcomponent)
{
HPDF_OutputIntent icc;
HPDF_STATUS ret;
HPDF_PTRACE ((" HPDF_ICC_LoadIccFromMem\n"));
icc = HPDF_DictStream_New (mmgr, xref);
if (!icc)
return NULL;
HPDF_Dict_AddNumber (icc, "N", numcomponent);
switch (numcomponent) {
case 1 :
HPDF_Dict_AddName (icc, "Alternate", "DeviceGray");
break;
case 3 :
HPDF_Dict_AddName (icc, "Alternate", "DeviceRGB");
break;
case 4 :
HPDF_Dict_AddName (icc, "Alternate", "DeviceCMYK");
break;
default : /* unsupported */
HPDF_RaiseError (&pdf->error, HPDF_INVALID_ICC_COMPONENT_NUM, 0);
HPDF_Dict_Free(icc);
return NULL;
}
for (;;) {
HPDF_BYTE buf[HPDF_STREAM_BUF_SIZ];
HPDF_UINT len = HPDF_STREAM_BUF_SIZ;
ret = HPDF_Stream_Read (iccdata, buf, &len);
if (ret != HPDF_OK) {
if (ret == HPDF_STREAM_EOF) {
if (len > 0) {
ret = HPDF_Stream_Write (icc->stream, buf, len);
if (ret != HPDF_OK) {
HPDF_Dict_Free(icc);
return NULL;
}
}
break;
} else {
HPDF_Dict_Free(icc);
return NULL;
}
}
if (HPDF_Stream_Write (icc->stream, buf, len) != HPDF_OK) {
HPDF_Dict_Free(icc);
return NULL;
}
}
return icc;
}
HPDF_EXPORT(HPDF_Array)
HPDF_AddColorspaceFromProfile (HPDF_Doc pdf,
HPDF_Dict icc)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_Array iccentry;
if (!HPDF_HasDoc (pdf))
return NULL;
iccentry = HPDF_Array_New(pdf->mmgr);
if (!iccentry)
return NULL;
ret = HPDF_Array_AddName (iccentry, "ICCBased" );
if (ret != HPDF_OK) {
HPDF_Array_Free(iccentry);
HPDF_CheckError (&pdf->error);
return NULL;
}
ret = HPDF_Array_Add (iccentry, icc );
if (ret != HPDF_OK) {
HPDF_Array_Free(iccentry);
return NULL;
}
return iccentry;
}
HPDF_EXPORT(HPDF_OutputIntent)
HPDF_LoadIccProfileFromFile (HPDF_Doc pdf,
const char* icc_file_name,
int numcomponent)
{
HPDF_Stream iccdata;
HPDF_OutputIntent iccentry;
HPDF_PTRACE ((" HPDF_LoadIccProfileFromFile\n"));
if (!HPDF_HasDoc (pdf))
return NULL;
/* create file stream */
iccdata = HPDF_FileReader_New (pdf->mmgr, icc_file_name);
if (HPDF_Stream_Validate (iccdata)) {
iccentry = HPDF_ICC_LoadIccFromMem(pdf, pdf->mmgr, iccdata, pdf->xref, numcomponent);
} else
iccentry = NULL;
/* destroy file stream */
if (iccdata)
HPDF_Stream_Free (iccdata);
if (!iccentry)
HPDF_CheckError (&pdf->error);
return iccentry;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_doc_png.c
* << Haru Free PDF Library >> -- hpdf_doc_png.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -24,6 +27,46 @@ LoadPngImageFromStream (HPDF_Doc pdf,
HPDF_Stream imagedata,
HPDF_BOOL delayed_loading);
HPDF_EXPORT(HPDF_Image)
HPDF_LoadPngImageFromMem (HPDF_Doc pdf,
const HPDF_BYTE *buffer,
HPDF_UINT size)
{
HPDF_Stream imagedata;
HPDF_Image image;
HPDF_PTRACE ((" HPDF_LoadPngImageFromFile\n"));
if (!HPDF_HasDoc (pdf)) {
return NULL;
}
/* create file stream */
imagedata = HPDF_MemStream_New (pdf->mmgr, size);
if (!HPDF_Stream_Validate (imagedata)) {
HPDF_RaiseError (&pdf->error, HPDF_INVALID_STREAM, 0);
return NULL;
}
if (HPDF_Stream_Write (imagedata, buffer, size) != HPDF_OK) {
HPDF_Stream_Free (imagedata);
return NULL;
}
image = LoadPngImageFromStream (pdf, imagedata, HPDF_FALSE);
/* destroy file stream */
HPDF_Stream_Free (imagedata);
if (!image) {
HPDF_CheckError (&pdf->error);
}
return image;
}
HPDF_EXPORT(HPDF_Image)
HPDF_LoadPngImageFromFile (HPDF_Doc pdf,
@ -81,8 +124,10 @@ HPDF_LoadPngImageFromFile2 (HPDF_Doc pdf,
if (imagedata)
HPDF_Stream_Free (imagedata);
if (!image)
if (!image) {
HPDF_CheckError (&pdf->error);
return NULL;
}
/* add file-name to image dictionary as a hidden entry.
* it is used when the image data is needed.
@ -103,7 +148,7 @@ HPDF_LoadPngImageFromFile2 (HPDF_Doc pdf,
return image;
}
#ifndef HPDF_NOPNGLIB
#ifndef LIBHPDF_HAVE_NOPNGLIB
static HPDF_Image
LoadPngImageFromStream (HPDF_Doc pdf,
HPDF_Stream imagedata,
@ -129,9 +174,11 @@ LoadPngImageFromStream (HPDF_Doc pdf,
HPDF_BOOL delayed_loading)
{
HPDF_SetError (&pdf->error, HPDF_UNSUPPORTED_FUNC, 0);
HPDF_UNUSED (delayed_loading);
HPDF_UNUSED (imagedata);
return NULL;
}
#endif /* HPDF_NOPNGLIB */
#endif /* LIBHPDF_HAVE_NOPNGLIB */

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_encoder.c
* << Haru Free PDF Library >> -- hpdf_encoder.c
*
* Copyright (c) 1999-2004 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -1094,7 +1097,7 @@ static const HPDF_UNICODE HPDF_UNICODE_MAP_STANDARD[] = {
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x00D1, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
@ -1129,9 +1132,9 @@ static const HPDF_UNICODE HPDF_UNICODE_MAP_WIN_ANSI[] = {
0x02C6, 0x2030, 0x0160, 0x2039, 0x0152, 0x0000, 0x017D, 0x0000,
0x0000, 0x2018, 0x2019, 0x201C, 0x201D, 0x2022, 0x2013, 0x2014,
0x02DC, 0x2122, 0x0161, 0x203A, 0x0153, 0x0000, 0x017E, 0x0178,
0x0000, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x0000, 0x00AE, 0x00AF,
0x02DA, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
@ -1156,21 +1159,21 @@ static const HPDF_UNICODE HPDF_UNICODE_MAP_MAC_ROMAN[] = {
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x0000,
0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x0000, 0x00D6, 0x00DC, 0x00E1,
0x00C4, 0x00C5, 0x00C7, 0x00C9, 0x00D1, 0x00D6, 0x00DC, 0x00E1,
0x00E0, 0x00E2, 0x00E4, 0x00E3, 0x00E5, 0x00E7, 0x00E9, 0x00E8,
0x00EA, 0x00EB, 0x00ED, 0x00EC, 0x00EE, 0x00EF, 0x00F1, 0x00F3,
0x00F2, 0x00F4, 0x00F6, 0x00F5, 0x00FA, 0x00F9, 0x00FB, 0x00FC,
0x2020, 0x00B0, 0x00A2, 0x00A3, 0x00A7, 0x2022, 0x00B6, 0x00DF,
0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x0000, 0x00C6, 0x00D8,
0x0000, 0x00B1, 0x0000, 0x0000, 0x00A5, 0x00B5, 0x0000, 0x0000,
0x0000, 0x0000, 0x0000, 0x00AA, 0x00BA, 0x0000, 0x00E6, 0x00F8,
0x00BF, 0x00A1, 0x00AC, 0x0000, 0x0192, 0x0000, 0x0000, 0x00AB,
0x00BB, 0x2026, 0x0020, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153,
0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x0000,
0x00FF, 0x0178, 0x2044, 0x00A4, 0x2039, 0x203A, 0xFB01, 0xFB02,
0x00AE, 0x00A9, 0x2122, 0x00B4, 0x00A8, 0x2260, 0x00C6, 0x00D8,
0x221E, 0x00B1, 0x2264, 0x2265, 0x00A5, 0x00B5, 0x2202, 0x2211,
0x220F, 0x03C0, 0x222B, 0x00AA, 0x00BA, 0x03A9, 0x00E6, 0x00F8,
0x00BF, 0x00A1, 0x00AC, 0x221A, 0x0192, 0x2248, 0x2206, 0x00AB,
0x00BB, 0x2026, 0x00A0, 0x00C0, 0x00C3, 0x00D5, 0x0152, 0x0153,
0x2013, 0x2014, 0x201C, 0x201D, 0x2018, 0x2019, 0x00F7, 0x25CA,
0x00FF, 0x0178, 0x2044, 0x20AC, 0x2039, 0x203A, 0xFB01, 0xFB02,
0x2021, 0x00B7, 0x201A, 0x201E, 0x2030, 0x00C2, 0x00CA, 0x00C1,
0x00CB, 0x00C8, 0x00CD, 0x00CE, 0x00CF, 0x00CC, 0x00D3, 0x00D4,
0x0000, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC,
0xF8FF, 0x00D2, 0x00DA, 0x00DB, 0x00D9, 0x0131, 0x02C6, 0x02DC,
0x00AF, 0x02D8, 0x02D9, 0x02DA, 0x00B8, 0x02DD, 0x02DB, 0x02C7
};
@ -2232,6 +2235,7 @@ HPDF_BasicEncoder_New (HPDF_MMgr mmgr,
encoder->error = mmgr->error;
encoder->type = HPDF_ENCODER_TYPE_SINGLE_BYTE;
encoder->to_unicode_fn = HPDF_BasicEncoder_ToUnicode;
encoder->encode_text_fn = NULL;
encoder->write_fn = HPDF_BasicEncoder_Write;
encoder->free_fn = HPDF_BasicEncoder_Free;
@ -2478,11 +2482,11 @@ HPDF_BasicEncoder_Write (HPDF_Encoder encoder,
const char* char_name =
HPDF_UnicodeToGryphName (attr->unicode_map[i]);
ptmp = HPDF_IToA (ptmp, i, tmp + HPDF_TMP_BUF_SIZ - 1);
ptmp = HPDF_IToA (ptmp, i, tmp + HPDF_TEXT_DEFAULT_LEN - 1);
*ptmp++ = ' ';
*ptmp++ = '/';
ptmp = HPDF_StrCpy (ptmp, char_name, tmp +
HPDF_TMP_BUF_SIZ - 1);
ptmp = (char *)HPDF_StrCpy (ptmp, char_name, tmp +
HPDF_TEXT_DEFAULT_LEN - 1);
*ptmp++ = ' ';
*ptmp = 0;
@ -2517,7 +2521,7 @@ HPDF_Encoder_Validate (HPDF_Encoder encoder)
HPDF_Encoder
HPDF_CMapEncoder_New (HPDF_MMgr mmgr,
char *name,
char *name,
HPDF_Encoder_Init_Func init_fn)
{
HPDF_Encoder encoder;
@ -2602,8 +2606,8 @@ HPDF_UNICODE
HPDF_CMapEncoder_ToUnicode (HPDF_Encoder encoder,
HPDF_UINT16 code)
{
HPDF_BYTE l = code;
HPDF_BYTE h = code >> 8;
HPDF_BYTE l = (HPDF_BYTE)code;
HPDF_BYTE h = (HPDF_BYTE)(code >> 8);
HPDF_CMapEncoderAttr attr = (HPDF_CMapEncoderAttr)encoder->attr;
return attr->unicode_map[l][h];
@ -2614,15 +2618,14 @@ HPDF_UINT16
HPDF_CMapEncoder_ToCID (HPDF_Encoder encoder,
HPDF_UINT16 code)
{
HPDF_BYTE l = code;
HPDF_BYTE h = code >> 8;
HPDF_BYTE l = (HPDF_BYTE)code;
HPDF_BYTE h = (HPDF_BYTE)(code >> 8);
HPDF_CMapEncoderAttr attr = (HPDF_CMapEncoderAttr)encoder->attr;
return attr->cid_map[l][h];
}
void
HPDF_CMapEncoder_Free (HPDF_Encoder encoder)
{
@ -2674,6 +2677,8 @@ HPDF_CMapEncoder_Write (HPDF_Encoder encoder,
HPDF_Stream out)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_UNUSED (out);
HPDF_UNUSED (encoder);
return ret;
}
@ -2686,6 +2691,7 @@ HPDF_Encoder_SetParseText (HPDF_Encoder encoder,
HPDF_UINT len)
{
HPDF_PTRACE ((" HPDF_CMapEncoder_SetParseText\n"));
HPDF_UNUSED (encoder);
state->text = text;
state->index = 0;
@ -2745,20 +2751,26 @@ HPDF_CMapEncoder_AddCMap (HPDF_Encoder encoder,
HPDF_PTRACE ((" HPDF_CMapEncoder_AddCMap\n"));
/* Copy specified pdf_cid_range array to fRangeArray. */
while (range->from != 0xffff && range->to != 0xffff) {
HPDF_UINT16 code = range->from;
HPDF_UINT16 cid = range->cid;
HPDF_CidRange_Rec *prange;
HPDF_STATUS ret;
while (range->from != 0xffff || range->to != 0xffff) {
HPDF_CidRange_Rec *prange;
HPDF_STATUS ret;
while (code <= range->to) {
HPDF_BYTE l = code;
HPDF_BYTE h = code >> 8;
/*
* Only if we have the default to_unicode_fn
*/
if (encoder->to_unicode_fn == HPDF_CMapEncoder_ToUnicode) {
HPDF_UINT16 code = range->from;
HPDF_UINT16 cid = range->cid;
attr->cid_map[l][h] = cid;
code++;
cid++;
}
while (code <= range->to) {
HPDF_BYTE l = code;
HPDF_BYTE h = code >> 8;
attr->cid_map[l][h] = cid;
code++;
cid++;
}
}
prange = HPDF_GetMem (encoder->mmgr, sizeof(HPDF_CidRange_Rec));
if (!prange)
@ -2840,8 +2852,8 @@ HPDF_CMapEncoder_SetUnicodeArray (HPDF_Encoder encoder,
if (array != NULL)
while (array->unicode != 0xffff) {
HPDF_BYTE l = array->code;
HPDF_BYTE h = array->code >> 8;
HPDF_BYTE l = (HPDF_BYTE)array->code;
HPDF_BYTE h = (HPDF_BYTE)(array->code >> 8);
attr->unicode_map[l][h] = array->unicode;
array++;
}
@ -2943,7 +2955,7 @@ HPDF_Encoder_GetByteType (HPDF_Encoder encoder,
if (encoder->type != HPDF_ENCODER_TYPE_DOUBLE_BYTE)
return HPDF_BYTE_TYPE_SINGLE;
HPDF_Encoder_SetParseText (encoder, &parse_state, text, index + 1);
HPDF_Encoder_SetParseText (encoder, &parse_state, (HPDF_BYTE *)text, index + 1);
for (;;) {
btype = HPDF_CMapEncoder_ByteType (encoder, &parse_state);
@ -2988,4 +3000,3 @@ HPDF_Encoder_GetWritingMode (HPDF_Encoder encoder)
return HPDF_WMODE_HORIZONTAL;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_encoder_cns.c
* << Haru Free PDF Library >> -- hpdf_encoder_cns.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -36074,6 +36077,7 @@ static HPDF_BOOL
GBK_EUC_IsLeadByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return ((b >= 0x81 && b <= 0xfe));
}
@ -36082,6 +36086,7 @@ static HPDF_BOOL
GBK_EUC_IsTrialByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return (b >= 0x40 && b <= 0xfe);
}
@ -36197,6 +36202,7 @@ static HPDF_BOOL
GB_EUC_IsLeadByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return (b >= 0xa1 && b <= 0xfe);
}
@ -36205,6 +36211,7 @@ static HPDF_BOOL
GB_EUC_IsTrialByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return (b >= 0xa1 && b <= 0xfe);
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_encoder_cnt.c
* << Haru Free PDF Library >> -- hpdf_encoder_cnt.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -15155,6 +15158,7 @@ static HPDF_BOOL
ETen_B5_IsLeadByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return ((b >= 0x81 && b <= 0xfe));
}
@ -15163,6 +15167,7 @@ static HPDF_BOOL
ETen_B5_IsTrialByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return (b >= 0x40 && b <= 0xfe);
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_encoder_jp.c
* << Haru Free PDF Library >> -- hpdf_encoder_jp.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -15769,6 +15772,7 @@ static HPDF_BOOL
RKSJ_IsLeadByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return ((b >= 0x81 && b <= 0x9f) || (b >= 0xe0 && b <= 0xfc));
}
@ -15777,6 +15781,7 @@ static HPDF_BOOL
RKSJ_IsTrialByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return (b >= 0x40 && b <= 0xfc && b != 0x7f);
}
@ -15950,6 +15955,7 @@ static HPDF_BOOL
EUC_IsLeadByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return ((b >= 0xa1 && b <= 0xfe) || b == 0x8e);
}
@ -15958,6 +15964,7 @@ static HPDF_BOOL
EUC_IsTrialByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return (b >= 0xa0 && b <= 0xfe);
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_encoder_kr.c
* << Haru Free PDF Library >> -- hpdf_encoder_kr.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -27639,6 +27642,7 @@ static HPDF_BOOL
KSCms_UHC_IsLeadByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return (b >= 0x81 && b <= 0xFE);
}
@ -27647,6 +27651,7 @@ static HPDF_BOOL
KSCms_UHC_IsTrialByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return (b >= 0x41 && b <= 0xfe);
}
@ -27804,6 +27809,7 @@ static HPDF_BOOL
KSC_EUC_IsLeadByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return (b >= 0xa1 && b <= 0xfe);
}
@ -27812,6 +27818,7 @@ static HPDF_BOOL
KSC_EUC_IsTrialByte (HPDF_Encoder encoder,
HPDF_BYTE b)
{
HPDF_UNUSED (encoder);
return (b >= 0xa0 && b <= 0xfe);
}

276
PDF/src/hpdf_encoder_utf.c Normal file
View File

@ -0,0 +1,276 @@
/*
* << Haru Free PDF Library >> -- hpdf_encoder_utf.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2008 Antony Dovgal <tony@daylessday.org>
* Copyright (c) 2010 Sergey Konovalov <webmaster@crynet.ru>
* Copyright (c) 2011 Koen Deforche <koen@emweb.be>
*
* 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.
*
*/
#include "hpdf_conf.h"
#include "hpdf_utils.h"
#include "hpdf_encoder.h"
#include "hpdf.h"
typedef struct _UTF8_EncoderAttr_Rec *UTF8_EncoderAttr;
typedef struct _UTF8_EncoderAttr_Rec {
HPDF_BYTE current_byte;
HPDF_BYTE end_byte;
HPDF_BYTE utf8_bytes[8];
} UTF8_EncoderAttr_Rec;
static const HPDF_CidRange_Rec UTF8_NOTDEF_RANGE = {0x0000, 0x001F, 1};
static const HPDF_CidRange_Rec UTF8_SPACE_RANGE = {0x0000, 0xFFFF, 0};
static const HPDF_CidRange_Rec UTF8_CID_RANGE[] = {
{ 0x0000, 0xFFFF, 0x0 },
{ 0xFFFF, 0xFFFF, 0x0 }
};
static HPDF_ByteType
UTF8_Encoder_ByteType_Func (HPDF_Encoder encoder,
HPDF_ParseText_Rec *state);
static HPDF_UNICODE
UTF8_Encoder_ToUnicode_Func (HPDF_Encoder encoder,
HPDF_UINT16 code);
static char *
UTF8_Encoder_EncodeText_Func (HPDF_Encoder encoder,
const char *text,
HPDF_UINT len,
HPDF_UINT *length);
static HPDF_STATUS
UTF8_Init (HPDF_Encoder encoder);
/*--------------------------------------------------------------------------*/
/*
* This function is taken from hpdf_encoder_utf8.c, originally submitted
* to libharu by 'Mirco'
*/
static HPDF_ByteType
UTF8_Encoder_ByteType_Func (HPDF_Encoder encoder,
HPDF_ParseText_Rec *state)
{
// This function is supposed to increment state->index
// Not logical ! (look at function HPDF_String_Write in hpdf_string.c)
// When HPDF_BYTE_TYPE_SINGLE is returned, the current byte is the
// CODE argument in call ToUnicode_Func
// When HPDF_BYTE_TYPE_LEAD is returned, the current byte (msb) and the
// next byte (lsb) is the CODE arguement in call ToUnicodeFunc
// When HPDF_BYTE_TYPE_TRIAL is returned, the current byte is ignored
HPDF_CMapEncoderAttr encoder_attr;
HPDF_BYTE byte;
UTF8_EncoderAttr utf8_attr;
encoder_attr = (HPDF_CMapEncoderAttr) encoder->attr;
utf8_attr = (UTF8_EncoderAttr) ((void *)encoder_attr->cid_map[0]);
if (state->index == 0) {
//First byte, initialize.
HPDF_PTRACE ((" UTF8_Encoder_ByteType_Func - Initialize: (%u) %s\n",
state->len, state->text));
utf8_attr->current_byte = 0;
}
byte = state->text[state->index];
state->index++;
HPDF_PTRACE ((" UTF8_Encoder_ByteType_Func - Byte: %hx\n", byte));
if (utf8_attr->current_byte == 0) {
utf8_attr->utf8_bytes[0] = byte;
utf8_attr->current_byte = 1;
if (!(byte & 0x80)) {
utf8_attr->current_byte = 0;
utf8_attr->end_byte = 0;
return HPDF_BYTE_TYPE_SINGLE;
}
if ((byte & 0xf8) == 0xf0)
utf8_attr->end_byte = 3;
else if ((byte & 0xf0) == 0xe0)
utf8_attr->end_byte = 2;
else if ((byte & 0xe0) == 0xc0)
utf8_attr->end_byte = 1;
else
utf8_attr->current_byte = 0; //ERROR, skip this byte
} else {
utf8_attr->utf8_bytes[utf8_attr->current_byte] = byte;
if (utf8_attr->current_byte == utf8_attr->end_byte) {
utf8_attr->current_byte = 0;
return HPDF_BYTE_TYPE_SINGLE;
}
utf8_attr->current_byte++;
}
return HPDF_BYTE_TYPE_TRIAL;
}
/*
* This function is taken from hpdf_encoder_utf8.c, originally submitted
* to libharu by 'Mirco'
*/
static HPDF_UNICODE
UTF8_Encoder_ToUnicode_Func (HPDF_Encoder encoder,
HPDF_UINT16 code)
{
// Supposed to convert CODE to unicode.
// This function is allways called after ByteType_Func.
// ByteType_Func recognizes the utf-8 bytes belonging to one character.
HPDF_CMapEncoderAttr encoder_attr;
UTF8_EncoderAttr utf8_attr;
unsigned int val;
encoder_attr = (HPDF_CMapEncoderAttr) encoder->attr;
utf8_attr = (UTF8_EncoderAttr) ((void *)encoder_attr->cid_map[0]);
switch (utf8_attr->end_byte) {
case 3:
val = (unsigned int) ((utf8_attr->utf8_bytes[0] & 0x7) << 18) +
(unsigned int) ((utf8_attr->utf8_bytes[1]) << 12) +
(unsigned int) ((utf8_attr->utf8_bytes[2] & 0x3f) << 6) +
(unsigned int) ((utf8_attr->utf8_bytes[3] & 0x3f));
break;
case 2:
val = (unsigned int) ((utf8_attr->utf8_bytes[0] & 0xf) << 12) +
(unsigned int) ((utf8_attr->utf8_bytes[1] & 0x3f) << 6) +
(unsigned int) ((utf8_attr->utf8_bytes[2] & 0x3f));
break;
case 1:
val = (unsigned int) ((utf8_attr->utf8_bytes[0] & 0x1f) << 6) +
(unsigned int) ((utf8_attr->utf8_bytes[1] & 0x3f));
break;
case 0:
val = (unsigned int) utf8_attr->utf8_bytes[0];
break;
default:
val = 32; // Unknown character
}
if (val > 65535) //Convert everything outside UCS-2 to space
val = 32;
return val;
}
static char *
UTF8_Encoder_EncodeText_Func (HPDF_Encoder encoder,
const char *text,
HPDF_UINT len,
HPDF_UINT *length)
{
char *result = malloc(len * 2);
char *c = result;
HPDF_ParseText_Rec parse_state;
HPDF_UINT i;
HPDF_Encoder_SetParseText (encoder, &parse_state,
(const HPDF_BYTE *)text, len);
for (i = 0; i < len; i++) {
HPDF_UNICODE tmp_unicode;
HPDF_ByteType btype = HPDF_Encoder_ByteType (encoder, &parse_state);
if (btype != HPDF_BYTE_TYPE_TRIAL) {
tmp_unicode = HPDF_Encoder_ToUnicode (encoder, 0);
HPDF_UInt16Swap (&tmp_unicode);
HPDF_MemCpy ((HPDF_BYTE *)c, (const HPDF_BYTE*)&tmp_unicode, 2);
c += 2;
}
}
*length = c - result;
return result;
}
static HPDF_STATUS
UTF8_Init (HPDF_Encoder encoder)
{
HPDF_CMapEncoderAttr attr;
HPDF_STATUS ret;
if ((ret = HPDF_CMapEncoder_InitAttr (encoder)) != HPDF_OK)
return ret;
/*
* We override these two
*/
encoder->byte_type_fn = UTF8_Encoder_ByteType_Func;
encoder->to_unicode_fn = UTF8_Encoder_ToUnicode_Func;
encoder->encode_text_fn = UTF8_Encoder_EncodeText_Func;
attr = (HPDF_CMapEncoderAttr)encoder->attr;
if (HPDF_CMapEncoder_AddCMap (encoder, UTF8_CID_RANGE) != HPDF_OK)
return encoder->error->error_no;
if (HPDF_CMapEncoder_AddCodeSpaceRange (encoder, UTF8_SPACE_RANGE)
!= HPDF_OK)
return encoder->error->error_no;
if (HPDF_CMapEncoder_AddNotDefRange (encoder, UTF8_NOTDEF_RANGE)
!= HPDF_OK)
return encoder->error->error_no;
attr->is_lead_byte_fn = NULL;
attr->is_trial_byte_fn = NULL;
HPDF_StrCpy (attr->registry, "Adobe", attr->registry +
HPDF_LIMIT_MAX_NAME_LEN);
HPDF_StrCpy (attr->ordering, "Identity-H", attr->ordering +
HPDF_LIMIT_MAX_NAME_LEN);
attr->suppliment = 0;
attr->writing_mode = HPDF_WMODE_HORIZONTAL;
/* Not sure about this
attr->uid_offset = 0;
attr->xuid[0] = 0;
attr->xuid[1] = 0;
attr->xuid[2] = 0;
*/
encoder->type = HPDF_ENCODER_TYPE_DOUBLE_BYTE;
return HPDF_OK;
}
/*--------------------------------------------------------------------------*/
HPDF_EXPORT(HPDF_STATUS)
HPDF_UseUTFEncodings (HPDF_Doc pdf)
{
HPDF_Encoder encoder;
HPDF_STATUS ret;
if (!HPDF_HasDoc (pdf))
return HPDF_INVALID_DOCUMENT;
encoder = HPDF_CMapEncoder_New (pdf->mmgr, "UTF-8",
UTF8_Init);
if ((ret = HPDF_Doc_RegisterEncoder (pdf, encoder)) != HPDF_OK)
return ret;
return HPDF_OK;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_encryor.c
* << Haru Free PDF Library >> -- hpdf_encryor.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -314,13 +317,13 @@ HPDF_PadOrTrancatePasswd (const char *pwd,
HPDF_MemSet (new_pwd, 0x00, HPDF_PASSWD_LEN);
if (len >= HPDF_PASSWD_LEN)
HPDF_MemCpy (new_pwd, pwd, HPDF_PASSWD_LEN);
else {
if (len > 0)
HPDF_MemCpy (new_pwd, pwd, len);
HPDF_MemCpy (new_pwd + len, HPDF_PADDING_STRING,
HPDF_PASSWD_LEN - len);
if (len >= HPDF_PASSWD_LEN) {
HPDF_MemCpy (new_pwd, (HPDF_BYTE *)pwd, HPDF_PASSWD_LEN);
} else {
if (len > 0) {
HPDF_MemCpy (new_pwd, (HPDF_BYTE *)pwd, len);
}
HPDF_MemCpy (new_pwd + len, HPDF_PADDING_STRING, HPDF_PASSWD_LEN - len);
}
}
@ -365,7 +368,7 @@ HPDF_Encrypt_CreateOwnerKey (HPDF_Encrypt attr)
for (i = 0; i < 50; i++) {
HPDF_MD5Init(&md5_ctx);
//HPDF_MD5Update (&md5_ctx, digest, HPDF_MD5_KEY_LEN);
/* HPDF_MD5Update (&md5_ctx, digest, HPDF_MD5_KEY_LEN); */
HPDF_MD5Update (&md5_ctx, digest, attr->key_len);
HPDF_MD5Final(digest, &md5_ctx);
@ -395,7 +398,7 @@ HPDF_Encrypt_CreateOwnerKey (HPDF_Encrypt attr)
HPDF_BYTE new_key[HPDF_MD5_KEY_LEN];
for (j = 0; j < attr->key_len; j++)
new_key[j] = digest[j] ^ i;
new_key[j] = (HPDF_BYTE)(digest[j] ^ i);
HPDF_PTRACE(("@ Algorithm 3.3 step 7 loop %u\n", i));
@ -429,10 +432,10 @@ HPDF_Encrypt_CreateEncryptionKey (HPDF_Encrypt attr)
/* Algorithm3.2 step4 */
HPDF_PTRACE(("@@@ permission =%d\n", attr->permission));
tmp_flg[0] = attr->permission;
tmp_flg[1] = (attr->permission >> 8);
tmp_flg[2] = (attr->permission >> 16);
tmp_flg[3] = (attr->permission >> 24);
tmp_flg[0] = (HPDF_BYTE)(attr->permission);
tmp_flg[1] = (HPDF_BYTE)(attr->permission >> 8);
tmp_flg[2] = (HPDF_BYTE)(attr->permission >> 16);
tmp_flg[3] = (HPDF_BYTE)(attr->permission >> 24);
HPDF_MD5Update(&md5_ctx, tmp_flg, 4);
@ -499,7 +502,7 @@ HPDF_Encrypt_CreateUserKey (HPDF_Encrypt attr)
HPDF_PTRACE(("@ Algorithm 3.5 step 5 loop %u\n", i));
for (j = 0; j < attr->key_len; j++)
new_key[j] = attr->encryption_key[j] ^ i;
new_key[j] = (HPDF_BYTE)(attr->encryption_key[j] ^ i);
HPDF_MemCpy (digest, digest2, HPDF_MD5_KEY_LEN);
@ -526,7 +529,7 @@ ARC4Init (HPDF_ARC4_Ctx_Rec *ctx,
HPDF_PTRACE((" ARC4Init\n"));
for (i = 0; i < HPDF_ARC4_BUF_SIZE; i++)
ctx->state[i] = i;
ctx->state[i] = (HPDF_BYTE)i;
for (i = 0; i < HPDF_ARC4_BUF_SIZE; i++)
tmp_array[i] = key[i % key_len];
@ -561,8 +564,8 @@ ARC4CryptBuf (HPDF_ARC4_Ctx_Rec *ctx,
for (i = 0; i < len; i++) {
HPDF_BYTE tmp;
ctx->idx1 = (ctx->idx1 + 1) % 256;
ctx->idx2 = (ctx->idx2 + ctx->state[ctx->idx1]) % 256;
ctx->idx1 = (HPDF_BYTE)((ctx->idx1 + 1) % 256);
ctx->idx2 = (HPDF_BYTE)((ctx->idx2 + ctx->state[ctx->idx1]) % 256);
tmp = ctx->state[ctx->idx1];
ctx->state[ctx->idx1] = ctx->state[ctx->idx2];
@ -571,7 +574,7 @@ ARC4CryptBuf (HPDF_ARC4_Ctx_Rec *ctx,
t = (ctx->state[ctx->idx1] + ctx->state[ctx->idx2]) % 256;
K = ctx->state[t];
out[i] = in[i] ^ K;
out[i] = (HPDF_BYTE)(in[i] ^ K);
}
}
@ -586,11 +589,11 @@ HPDF_Encrypt_InitKey (HPDF_Encrypt attr,
HPDF_PTRACE((" HPDF_Encrypt_Init\n"));
attr->encryption_key[attr->key_len] = object_id;
attr->encryption_key[attr->key_len + 1] = (object_id >> 8);
attr->encryption_key[attr->key_len + 2] = (object_id >> 16);
attr->encryption_key[attr->key_len + 3] = gen_no;
attr->encryption_key[attr->key_len + 4] = (gen_no >> 8);
attr->encryption_key[attr->key_len] = (HPDF_BYTE)object_id;
attr->encryption_key[attr->key_len + 1] = (HPDF_BYTE)(object_id >> 8);
attr->encryption_key[attr->key_len + 2] = (HPDF_BYTE)(object_id >> 16);
attr->encryption_key[attr->key_len + 3] = (HPDF_BYTE)gen_no;
attr->encryption_key[attr->key_len + 4] = (HPDF_BYTE)(gen_no >> 8);
HPDF_PTRACE(("@@@ OID=%u, gen_no=%u\n", (HPDF_INT)object_id, gen_no));

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.5 >> -- hpdf_encryptdict.c
* << Haru Free PDF Library >> -- hpdf_encryptdict.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -10,8 +13,7 @@
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
* 2006.09.04 modified.
*---------------------------------------------------------------------------*/
*/
#include <time.h>
#include "hpdf_conf.h"
@ -19,10 +21,9 @@
#include "hpdf_objects.h"
#include "hpdf_encryptdict.h"
#include "hpdf_info.h"
/*---------------------------------------------------------------------------*/
/*------ HPDF_EncryptDict ---------------------------------------------------*/
#ifndef HPDF_UNUSED
#define HPDF_UNUSED(a) ((void)(a))
#endif
HPDF_EncryptDict
HPDF_EncryptDict_New (HPDF_MMgr mmgr,
@ -67,13 +68,15 @@ HPDF_EncryptDict_CreateID (HPDF_EncryptDict dict,
/* use the result of 'time' function to get random value.
* when debugging, 'time' value is ignored.
*/
#ifndef HPDF_DEBUG
#ifndef LIBHPDF_DEBUG
time_t t = HPDF_TIME (NULL);
#endif /* HPDF_DEBUG */
#endif /* LIBHPDF_DEBUG */
HPDF_MD5Init (&ctx);
HPDF_UNUSED (xref);
HPDF_UNUSED (info);
#ifndef HPDF_DEBUG
#ifndef LIBHPDF_DEBUG
HPDF_MD5Update(&ctx, (HPDF_BYTE *)&t, sizeof(t));
/* create File Identifier from elements of Into dictionary. */

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_error.c
* << Haru Free PDF Library >> -- hpdf_error.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -16,6 +19,7 @@
#include "hpdf_utils.h"
#include "hpdf_error.h"
#include "hpdf_consts.h"
#include "hpdf.h"
#ifndef HPDF_STDCALL
#ifdef HPDF_DLL_MAKE
@ -80,7 +84,7 @@ HPDF_SetError (HPDF_Error error,
}
HPDF_STATUS
HPDF_EXPORT(HPDF_STATUS)
HPDF_CheckError (HPDF_Error error)
{
HPDF_PTRACE((" HPDF_CheckError: error_no=0x%04X detail_no=0x%04X\n",

69
PDF/src/hpdf_exdata.c Normal file
View File

@ -0,0 +1,69 @@
/*
* << Haru Free PDF Library >> -- hpdf_annotation.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* 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.
*
*/
#include "hpdf_conf.h"
#include "hpdf_utils.h"
#include "hpdf_info.h"
#include "hpdf_exdata.h"
#include "hpdf.h"
/*----------------------------------------------------------------------------*/
/*------ HPDF_ExData -----------------------------------------------------*/
HPDF_ExData
HPDF_3DAnnotExData_New(HPDF_MMgr mmgr,
HPDF_Xref xref)
{
HPDF_ExData exdata;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_ExData_New\n"));
exdata = HPDF_Dict_New (mmgr);
if (!exdata)
return NULL;
if (HPDF_Xref_Add (xref, exdata) != HPDF_OK)
return NULL;
ret += HPDF_Dict_AddName (exdata, "Type", "ExData");
ret += HPDF_Dict_AddName (exdata, "Subtype", "3DM");
if (ret != HPDF_OK)
return NULL;
return exdata;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DAnnotExData_Set3DMeasurement(HPDF_ExData exdata,
HPDF_3DMeasure measure)
{
HPDF_STATUS ret = HPDF_OK;
ret = HPDF_Dict_Add (exdata, "M3DREF", measure);
if (ret != HPDF_OK)
return ret;
return ret;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_ext_gstate.c
* << Haru Free PDF Library >> -- hpdf_ext_gstate.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -17,7 +20,7 @@
#include "hpdf_ext_gstate.h"
#include "hpdf.h"
const static char *HPDF_BM_NAMES[] = {
static const char * const HPDF_BM_NAMES[] = {
"Normal",
"Multiply",
"Screen",

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_font.c
* << Haru Free PDF Library >> -- hpdf_font.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -10,7 +13,6 @@
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
* 2006.07.25 modified.
*/
#include "hpdf_conf.h"

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_font_cid.c
* << Haru Free PDF Library >> -- hpdf_font_cid.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -10,7 +13,6 @@
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
* 2006.08.04 modified MeasureText().
*/
#include "hpdf_conf.h"
@ -46,10 +48,16 @@ MeasureText (HPDF_Font font,
static char*
UINT16ToHex (char *s,
HPDF_UINT16 val,
char *eptr);
UINT16ToHex (char *s,
HPDF_UINT16 val,
char *eptr,
HPDF_BYTE width);
static char *
CidRangeToHex (char *s,
HPDF_UINT16 from,
HPDF_UINT16 to,
char *eptr);
static HPDF_Dict
CreateCMap (HPDF_Encoder encoder,
@ -130,12 +138,31 @@ HPDF_Type0Font_New (HPDF_MMgr mmgr,
if (fontdef->type == HPDF_FONTDEF_TYPE_CID) {
ret += HPDF_Dict_AddName (font, "Encoding", encoder->name);
} else {
attr->cmap_stream = CreateCMap (encoder, xref);
/*
* Handle the Unicode encoding, see hpdf_encoding_utf.c For some
* reason, xpdf-based readers cannot deal with our cmap but work
* fine when using the predefined "Identity-H"
* encoding. However, text selection does not work, unless we
* add a ToUnicode cmap. This CMap should also be "Identity",
* but that does not work -- specifying our cmap as a stream however
* does work. Who can understand that ?
*/
if (HPDF_StrCmp(encoder_attr->ordering, "Identity-H") == 0) {
ret += HPDF_Dict_AddName (font, "Encoding", "Identity-H");
attr->cmap_stream = CreateCMap (encoder, xref);
if (attr->cmap_stream) {
ret += HPDF_Dict_Add (font, "Encoding", attr->cmap_stream);
} else
return NULL;
if (attr->cmap_stream) {
ret += HPDF_Dict_Add (font, "ToUnicode", attr->cmap_stream);
} else
return NULL;
} else {
attr->cmap_stream = CreateCMap (encoder, xref);
if (attr->cmap_stream) {
ret += HPDF_Dict_Add (font, "Encoding", attr->cmap_stream);
} else
return NULL;
}
}
if (ret != HPDF_OK)
@ -357,9 +384,9 @@ CIDFontType2_New (HPDF_Font parent, HPDF_Xref xref)
if (HPDF_Dict_Add (font, "DW2", array) != HPDF_OK)
return NULL;
ret += HPDF_Array_AddNumber (array, fontdef->font_bbox.bottom);
ret += HPDF_Array_AddNumber (array, fontdef->font_bbox.bottom -
fontdef->font_bbox.top);
ret += HPDF_Array_AddNumber (array, (HPDF_INT32)(fontdef->font_bbox.bottom));
ret += HPDF_Array_AddNumber (array, (HPDF_INT32)(fontdef->font_bbox.bottom -
fontdef->font_bbox.top));
HPDF_MemSet (tmp_map, 0, sizeof(HPDF_UNICODE) * 65536);
@ -370,15 +397,25 @@ CIDFontType2_New (HPDF_Font parent, HPDF_Xref xref)
HPDF_UINT j;
for (j = 0; j < 256; j++) {
HPDF_UINT16 cid = encoder_attr->cid_map[i][j];
if (cid != 0) {
HPDF_UNICODE unicode = encoder_attr->unicode_map[i][j];
HPDF_UINT16 gid = HPDF_TTFontDef_GetGlyphid (fontdef, unicode);
tmp_map[cid] = gid;
if (max < cid)
max = cid;
}
}
if (encoder->to_unicode_fn == HPDF_CMapEncoder_ToUnicode) {
HPDF_UINT16 cid = encoder_attr->cid_map[i][j];
if (cid != 0) {
HPDF_UNICODE unicode = encoder_attr->unicode_map[i][j];
HPDF_UINT16 gid = HPDF_TTFontDef_GetGlyphid (fontdef,
unicode);
tmp_map[cid] = gid;
if (max < cid)
max = cid;
}
} else {
HPDF_UNICODE unicode = (i << 8) | j;
HPDF_UINT16 gid = HPDF_TTFontDef_GetGlyphid (fontdef,
unicode);
tmp_map[unicode] = gid;
if (max < unicode)
max = unicode;
}
}
}
if (max > 0) {
@ -399,14 +436,14 @@ CIDFontType2_New (HPDF_Font parent, HPDF_Xref xref)
if (w != dw) {
if (!tmp_array) {
if ((ret = HPDF_Array_AddNumber (array, i)) != HPDF_OK)
if (HPDF_Array_AddNumber (array, i) != HPDF_OK)
return NULL;
tmp_array = HPDF_Array_New (font->mmgr);
if (!tmp_array)
return NULL;
if ((ret = HPDF_Array_Add (array, tmp_array)) != HPDF_OK)
if (HPDF_Array_Add (array, tmp_array) != HPDF_OK)
return NULL;
}
@ -422,16 +459,15 @@ CIDFontType2_New (HPDF_Font parent, HPDF_Xref xref)
if (!attr->map_stream)
return NULL;
if ((ret = HPDF_Dict_Add (font, "CIDToGIDMap", attr->map_stream))
!= HPDF_OK)
if (HPDF_Dict_Add (font, "CIDToGIDMap", attr->map_stream) != HPDF_OK)
return NULL;
for (i = 0; i < max; i++) {
HPDF_BYTE u[2];
HPDF_UINT16 gid = tmp_map[i];
u[0] = gid >> 8;
u[1] = gid;
u[0] = (HPDF_BYTE)(gid >> 8);
u[1] = (HPDF_BYTE)gid;
HPDF_MemCpy ((HPDF_BYTE *)(tmp_map + i), u, 2);
}
@ -567,14 +603,14 @@ TextWidth (HPDF_Font font,
(HPDF_CIDFontDefAttr)attr->fontdef->attr;
dw2 = cid_fontdef_attr->DW2[1];
} else {
dw2 = attr->fontdef->font_bbox.bottom -
attr->fontdef->font_bbox.top;
dw2 = (HPDF_INT)(attr->fontdef->font_bbox.bottom -
attr->fontdef->font_bbox.top);
}
HPDF_Encoder_SetParseText (encoder, &parse_state, text, len);
while (i < len) {
HPDF_ByteType btype = HPDF_CMapEncoder_ByteType (encoder, &parse_state);
HPDF_ByteType btype = (encoder->byte_type_fn)(encoder, &parse_state);
HPDF_UINT16 cid;
HPDF_UNICODE unicode;
HPDF_UINT16 code;
@ -585,7 +621,7 @@ TextWidth (HPDF_Font font,
if (btype == HPDF_BYTE_TYPE_LEAD) {
code <<= 8;
code += *text;
code = (HPDF_UINT16)(code + *text);
}
if (btype != HPDF_BYTE_TYPE_TRIAL) {
@ -596,7 +632,7 @@ TextWidth (HPDF_Font font,
w = HPDF_CIDFontDef_GetCIDWidth (attr->fontdef, cid);
} else {
/* unicode-based font */
unicode = HPDF_CMapEncoder_ToUnicode (encoder, code);
unicode = (encoder->to_unicode_fn)(encoder, code);
w = HPDF_TTFontDef_GetCharWidth (attr->fontdef, unicode);
}
} else {
@ -652,8 +688,8 @@ MeasureText (HPDF_Font font,
(HPDF_CIDFontDefAttr)attr->fontdef->attr;
dw2 = cid_fontdef_attr->DW2[1];
} else {
dw2 = attr->fontdef->font_bbox.bottom -
attr->fontdef->font_bbox.top;
dw2 = (HPDF_INT)(attr->fontdef->font_bbox.bottom -
attr->fontdef->font_bbox.top);
}
HPDF_Encoder_SetParseText (encoder, &parse_state, text, len);
@ -668,7 +704,7 @@ MeasureText (HPDF_Font font,
if (btype == HPDF_BYTE_TYPE_LEAD) {
code <<= 8;
code += b2;
code = (HPDF_UINT16)(code + b2);
}
if (!wordwrap) {
@ -687,7 +723,8 @@ MeasureText (HPDF_Font font,
tmp_len = i + 1;
if (real_width)
*real_width = w;
} else
} /* else
//Commenting this out fixes problem with HPDF_Text_Rect() splitting the words
if (last_btype == HPDF_BYTE_TYPE_TRIAL ||
(btype == HPDF_BYTE_TYPE_LEAD &&
last_btype == HPDF_BYTE_TYPE_SINGLE)) {
@ -696,7 +733,7 @@ MeasureText (HPDF_Font font,
if (real_width)
*real_width = w;
}
}
}*/
}
if (HPDF_IS_WHITE_SPACE(b)) {
@ -711,19 +748,19 @@ MeasureText (HPDF_Font font,
tmp_w = HPDF_CIDFontDef_GetCIDWidth (attr->fontdef, cid);
} else {
/* unicode-based font */
unicode = HPDF_CMapEncoder_ToUnicode (encoder, code);
unicode = (encoder->to_unicode_fn)(encoder, code);
tmp_w = HPDF_TTFontDef_GetCharWidth (attr->fontdef,
unicode);
}
} else {
tmp_w = -dw2;
tmp_w = (HPDF_UINT16)(-dw2);
}
if (i > 0)
w += char_space;
}
w += (HPDF_DOUBLE)tmp_w * font_size / 1000;
w += (HPDF_REAL)((HPDF_DOUBLE)tmp_w * font_size / 1000);
/* 2006.08.04 break when it encountered line feed */
if (w > width || b == 0x0A)
@ -743,10 +780,12 @@ MeasureText (HPDF_Font font,
}
static char*
UINT16ToHex (char *s,
HPDF_UINT16 val,
char *eptr)
UINT16ToHex (char *s,
HPDF_UINT16 val,
char *eptr,
HPDF_BYTE width)
{
HPDF_BYTE b[2];
HPDF_UINT16 val2;
@ -763,7 +802,14 @@ UINT16ToHex (char *s,
*s++ = '<';
if (b[0] != 0) {
/*
* In principle a range of <00> - <1F> can now not be
* distinguished from <0000> - <001F>..., this seems something
* that is wrong with CID ranges. For the UCS-2 encoding we need
* to add <0000> - <FFFF> and this cannot be <00> - <FFFF> (or at
* least, that crashes Mac OSX Preview).
*/
if (width == 2) {
c = b[0] >> 4;
if (c <= 9)
c += 0x30;
@ -771,7 +817,7 @@ UINT16ToHex (char *s,
c += 0x41 - 10;
*s++ = c;
c = b[0] & 0x0f;
c = (char)(b[0] & 0x0f);
if (c <= 9)
c += 0x30;
else
@ -779,14 +825,14 @@ UINT16ToHex (char *s,
*s++ = c;
}
c = b[1] >> 4;
c = (char)(b[1] >> 4);
if (c <= 9)
c += 0x30;
else
c += 0x41 - 10;
*s++ = c;
c = b[1] & 0x0f;
c = (char)(b[1] & 0x0f);
if (c <= 9)
c += 0x30;
else
@ -799,6 +845,21 @@ UINT16ToHex (char *s,
return s;
}
static char*
CidRangeToHex (char *s,
HPDF_UINT16 from,
HPDF_UINT16 to,
char *eptr)
{
HPDF_BYTE width = (to > 255) ? 2 : 1;
char *pbuf;
pbuf = UINT16ToHex (s, from, eptr, width);
*pbuf++ = ' ';
pbuf = UINT16ToHex (pbuf, to, eptr, width);
return pbuf;
}
static HPDF_Dict
CreateCMap (HPDF_Encoder encoder,
@ -843,17 +904,17 @@ CreateCMap (HPDF_Encoder encoder,
ret += HPDF_Stream_WriteStr (cmap->stream,
"%%IncludeResource: ProcSet (CIDInit)\r\n");
pbuf = HPDF_StrCpy (buf, "%%BeginResource: CMap (", eptr);
pbuf = HPDF_StrCpy (pbuf, encoder->name, eptr);
pbuf = (char *)HPDF_StrCpy (buf, "%%BeginResource: CMap (", eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, encoder->name, eptr);
HPDF_StrCpy (pbuf, ")\r\n", eptr);
ret += HPDF_Stream_WriteStr (cmap->stream, buf);
pbuf = HPDF_StrCpy (buf, "%%Title: (", eptr);
pbuf = HPDF_StrCpy (pbuf, encoder->name, eptr);
pbuf = (char *)HPDF_StrCpy (buf, "%%Title: (", eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, encoder->name, eptr);
*pbuf++ = ' ';
pbuf = HPDF_StrCpy (pbuf, attr->registry, eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, attr->registry, eptr);
*pbuf++ = ' ';
pbuf = HPDF_StrCpy (pbuf, attr->ordering, eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, attr->ordering, eptr);
*pbuf++ = ' ';
pbuf = HPDF_IToA (pbuf, attr->suppliment, eptr);
HPDF_StrCpy (pbuf, ")\r\n", eptr);
@ -874,24 +935,24 @@ CreateCMap (HPDF_Encoder encoder,
ret += HPDF_Stream_WriteStr (cmap->stream,
"/CIDSystemInfo 3 dict dup begin\r\n");
pbuf = HPDF_StrCpy (buf, " /Registry (", eptr);
pbuf = HPDF_StrCpy (pbuf, attr->registry, eptr);
pbuf = (char *)HPDF_StrCpy (buf, " /Registry (", eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, attr->registry, eptr);
HPDF_StrCpy (pbuf, ") def\r\n", eptr);
ret += HPDF_Stream_WriteStr (cmap->stream, buf);
pbuf = HPDF_StrCpy (buf, " /Ordering (", eptr);
pbuf = HPDF_StrCpy (pbuf, attr->ordering, eptr);
pbuf = (char *)HPDF_StrCpy (buf, " /Ordering (", eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, attr->ordering, eptr);
HPDF_StrCpy (pbuf, ") def\r\n", eptr);
ret += HPDF_Stream_WriteStr (cmap->stream, buf);
pbuf = HPDF_StrCpy (buf, " /Supplement ", eptr);
pbuf = (char *)HPDF_StrCpy (buf, " /Supplement ", eptr);
pbuf = HPDF_IToA (pbuf, attr->suppliment, eptr);
pbuf = HPDF_StrCpy (pbuf, " def\r\n", eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, " def\r\n", eptr);
HPDF_StrCpy (pbuf, "end def\r\n\r\n", eptr);
ret += HPDF_Stream_WriteStr (cmap->stream, buf);
pbuf = HPDF_StrCpy (buf, "/CMapName /", eptr);
pbuf = HPDF_StrCpy (pbuf, encoder->name, eptr);
pbuf = (char *)HPDF_StrCpy (buf, "/CMapName /", eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, encoder->name, eptr);
HPDF_StrCpy (pbuf, " def\r\n", eptr);
ret += HPDF_Stream_WriteStr (cmap->stream, buf);
@ -899,13 +960,13 @@ CreateCMap (HPDF_Encoder encoder,
ret += HPDF_Stream_WriteStr (cmap->stream, "/CMapType 1 def\r\n\r\n");
if (attr->uid_offset >= 0) {
pbuf = HPDF_StrCpy (buf, "/UIDOffset ", eptr);
pbuf = (char *)HPDF_StrCpy (buf, "/UIDOffset ", eptr);
pbuf = HPDF_IToA (pbuf, attr->uid_offset, eptr);
HPDF_StrCpy (pbuf, " def\r\n\r\n", eptr);
ret += HPDF_Stream_WriteStr (cmap->stream, buf);
}
pbuf = HPDF_StrCpy (buf, "/XUID [", eptr);
pbuf = (char *)HPDF_StrCpy (buf, "/XUID [", eptr);
pbuf = HPDF_IToA (pbuf, attr->xuid[0], eptr);
*pbuf++ = ' ';
pbuf = HPDF_IToA (pbuf, attr->xuid[1], eptr);
@ -914,7 +975,7 @@ CreateCMap (HPDF_Encoder encoder,
HPDF_StrCpy (pbuf, "] def\r\n\r\n", eptr);
ret += HPDF_Stream_WriteStr (cmap->stream, buf);
pbuf = HPDF_StrCpy (buf, "/WMode ", eptr);
pbuf = (char *)HPDF_StrCpy (buf, "/WMode ", eptr);
pbuf = HPDF_IToA (pbuf, (HPDF_UINT32)attr->writing_mode, eptr);
HPDF_StrCpy (pbuf, " def\r\n\r\n", eptr);
ret += HPDF_Stream_WriteStr (cmap->stream, buf);
@ -928,9 +989,8 @@ CreateCMap (HPDF_Encoder encoder,
HPDF_CidRange_Rec *range = HPDF_List_ItemAt (attr->code_space_range,
i);
pbuf = UINT16ToHex (buf, range->from, eptr);
*pbuf++ = ' ';
pbuf = UINT16ToHex (pbuf, range->to, eptr);
pbuf = CidRangeToHex(buf, range->from, range->to, eptr);
HPDF_StrCpy (pbuf, "\r\n", eptr);
ret += HPDF_Stream_WriteStr (cmap->stream, buf);
@ -952,9 +1012,7 @@ CreateCMap (HPDF_Encoder encoder,
for (i = 0; i < attr->notdef_range->count; i++) {
HPDF_CidRange_Rec *range = HPDF_List_ItemAt (attr->notdef_range, i);
pbuf = UINT16ToHex (buf, range->from, eptr);
*pbuf++ = ' ';
pbuf = UINT16ToHex (pbuf, range->to, eptr);
pbuf = CidRangeToHex(buf, range->from, range->to, eptr);
*pbuf++ = ' ';
pbuf = HPDF_IToA (pbuf, range->cid, eptr);
HPDF_StrCpy (pbuf, "\r\n", eptr);
@ -983,9 +1041,7 @@ CreateCMap (HPDF_Encoder encoder,
for (i = 0; i < attr->cmap_range->count; i++) {
HPDF_CidRange_Rec *range = HPDF_List_ItemAt (attr->cmap_range, i);
pbuf = UINT16ToHex (buf, range->from, eptr);
*pbuf++ = ' ';
pbuf = UINT16ToHex (pbuf, range->to, eptr);
pbuf = CidRangeToHex(buf, range->from, range->to, eptr);
*pbuf++ = ' ';
pbuf = HPDF_IToA (pbuf, range->cid, eptr);
HPDF_StrCpy (pbuf, "\r\n", eptr);
@ -994,7 +1050,7 @@ CreateCMap (HPDF_Encoder encoder,
if ((i + 1) %100 == 0) {
phase--;
pbuf = HPDF_StrCpy (buf, "endcidrange\r\n\r\n", eptr);
pbuf = (char *)HPDF_StrCpy (buf, "endcidrange\r\n\r\n", eptr);
if (phase > 0)
pbuf = HPDF_IToA (pbuf, 100, eptr);
@ -1011,14 +1067,14 @@ CreateCMap (HPDF_Encoder encoder,
}
if (odd > 0)
pbuf = HPDF_StrCpy (buf, "endcidrange\r\n", eptr);
pbuf = (char *)HPDF_StrCpy (buf, "endcidrange\r\n", eptr);
pbuf = HPDF_StrCpy (pbuf, "endcmap\r\n", eptr);
pbuf = HPDF_StrCpy (pbuf, "CMapName currentdict /CMap "
pbuf = (char *)HPDF_StrCpy (pbuf, "endcmap\r\n", eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, "CMapName currentdict /CMap "
"defineresource pop\r\n", eptr);
pbuf = HPDF_StrCpy (pbuf, "end\r\n", eptr);
pbuf = HPDF_StrCpy (pbuf, "end\r\n\r\n", eptr);
pbuf = HPDF_StrCpy (pbuf, "%%EndResource\r\n", eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, "end\r\n", eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, "end\r\n\r\n", eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, "%%EndResource\r\n", eptr);
HPDF_StrCpy (pbuf, "%%EOF\r\n", eptr);
ret += HPDF_Stream_WriteStr (cmap->stream, buf);

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_font_tt.c
* << Haru Free PDF Library >> -- hpdf_font_tt.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -177,6 +180,7 @@ CreateDescriptor (HPDF_Font font)
ret += HPDF_Dict_AddName (descriptor, "Type", "FontDescriptor");
ret += HPDF_Dict_AddNumber (descriptor, "Ascent", def->ascent);
ret += HPDF_Dict_AddNumber (descriptor, "Descent", def->descent);
ret += HPDF_Dict_AddNumber (descriptor, "CapHeight", def->cap_height);
ret += HPDF_Dict_AddNumber (descriptor, "Flags", def->flags);
array = HPDF_Box_Array_New (font->mmgr, def->font_bbox);
@ -244,7 +248,7 @@ CharWidth (HPDF_Font font,
}
HPDF_TextWidth
static HPDF_TextWidth
TextWidth (HPDF_Font font,
const HPDF_BYTE *text,
HPDF_UINT len)
@ -280,7 +284,7 @@ TextWidth (HPDF_Font font,
}
HPDF_UINT
static HPDF_UINT
MeasureText (HPDF_Font font,
const HPDF_BYTE *text,
HPDF_UINT len,
@ -304,14 +308,14 @@ MeasureText (HPDF_Font font,
tmp_len = i + 1;
if (real_width)
*real_width = w;
*real_width = (HPDF_REAL)w;
w += word_space;
} else if (!wordwrap) {
tmp_len = i;
if (real_width)
*real_width = w;
*real_width = (HPDF_REAL)w;
}
w += (HPDF_DOUBLE)CharWidth (font, b) * font_size / 1000;
@ -326,7 +330,7 @@ MeasureText (HPDF_Font font,
/* all of text can be put in the specified width */
if (real_width)
*real_width = w;
*real_width = (HPDF_REAL)w;
return len;
}
@ -402,5 +406,3 @@ OnFree (HPDF_Dict obj)
HPDF_FreeMem (obj->mmgr, attr);
}
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_font_type1.c
* << Haru Free PDF Library >> -- hpdf_font_type1.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -330,13 +333,13 @@ Type1Font_OnWrite (HPDF_Dict obj,
if (!fontdef_attr->is_base14font || encoder_attr->has_differences) {
char *pbuf;
pbuf = HPDF_StrCpy (buf, "/FirstChar ", eptr);
pbuf = (char *)HPDF_StrCpy (buf, "/FirstChar ", eptr);
pbuf = HPDF_IToA (pbuf, encoder_attr->first_char, eptr);
HPDF_StrCpy (pbuf, "\012", eptr);
if ((ret = HPDF_Stream_WriteStr (stream, buf)) != HPDF_OK)
return ret;
pbuf = HPDF_StrCpy (buf, "/LastChar ", eptr);
pbuf = (char *)HPDF_StrCpy (buf, "/LastChar ", eptr);
pbuf = HPDF_IToA (pbuf, encoder_attr->last_char, eptr);
HPDF_StrCpy (pbuf, "\012", eptr);
if ((ret = HPDF_Stream_WriteStr (stream, buf)) != HPDF_OK)

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef.c
* << Haru Free PDF Library >> -- hpdf_fontdef.c
*
* Copyright (c) 1999-2004 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.1 >> -- HPDF_FontDef_base14.c
* << Haru Free PDF Library >> -- hpdf_fontdef_base14.c
*
* Copyright (c) 1999-2004 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -10,7 +13,6 @@
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
* 2006.07.25 modified.
*/
#include "hpdf_conf.h"

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_cid.c
* << Haru Free PDF Library >> -- hpdf_fontdef_cid.c
*
* Copyright (c) 1999-2004 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_cns.c
* << Haru Free PDF Library >> -- hpdf_fontdef_cns.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_cnt.c
* << Haru Free PDF Library >> -- hpdf_fontdef_cnt.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_jp.c
* << Haru Free PDF Library >> -- hpdf_fontdef_jp.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -777,7 +780,7 @@ static const HPDF_CID_Width MS_PGothic_W_ARRAY[] = {
};
static const HPDF_CID_Width MS_Mincyo_W_ARRAY[] = {
static const HPDF_CID_Width MS_Mincho_W_ARRAY[] = {
{1, 500},
{2, 500},
{3, 500},
@ -1036,7 +1039,7 @@ static const HPDF_CID_Width MS_Mincyo_W_ARRAY[] = {
static const HPDF_CID_Width MS_PMincyo_W_ARRAY[] = {
static const HPDF_CID_Width MS_PMincho_W_ARRAY[] = {
{1, 304},
{2, 304},
{3, 460},
@ -1542,7 +1545,7 @@ static const HPDF_CID_Width MS_PMincyo_W_ARRAY[] = {
/*---------------------------------------------------------------------------*/
/*----- Mincyo Font ---------------------------------------------------------*/
/*----- Mincho Font ---------------------------------------------------------*/
static HPDF_STATUS
@ -1668,11 +1671,11 @@ MS_PGothic_BoldItalic_Init (HPDF_FontDef fontdef)
static HPDF_STATUS
MS_Mincyo_Init (HPDF_FontDef fontdef)
MS_Mincho_Init (HPDF_FontDef fontdef)
{
HPDF_STATUS ret;
HPDF_PTRACE ((" HPDF_FontDef_MS_Mincyo_Init\n"));
HPDF_PTRACE ((" HPDF_FontDef_MS_Mincho_Init\n"));
fontdef->ascent = 859;
fontdef->descent = -140;
@ -1695,9 +1698,9 @@ MS_Mincyo_Init (HPDF_FontDef fontdef)
static HPDF_STATUS
MS_Mincyo_Bold_Init (HPDF_FontDef fontdef)
MS_Mincho_Bold_Init (HPDF_FontDef fontdef)
{
HPDF_STATUS ret = MS_Mincyo_Init (fontdef);
HPDF_STATUS ret = MS_Mincho_Init (fontdef);
if (ret != HPDF_OK)
return ret;
@ -1707,9 +1710,9 @@ MS_Mincyo_Bold_Init (HPDF_FontDef fontdef)
static HPDF_STATUS
MS_Mincyo_Italic_Init (HPDF_FontDef fontdef)
MS_Mincho_Italic_Init (HPDF_FontDef fontdef)
{
HPDF_STATUS ret = MS_Mincyo_Init (fontdef);
HPDF_STATUS ret = MS_Mincho_Init (fontdef);
if (ret != HPDF_OK)
return ret;
@ -1718,9 +1721,9 @@ MS_Mincyo_Italic_Init (HPDF_FontDef fontdef)
}
static HPDF_STATUS
MS_Mincyo_BoldItalic_Init (HPDF_FontDef fontdef)
MS_Mincho_BoldItalic_Init (HPDF_FontDef fontdef)
{
HPDF_STATUS ret = MS_Mincyo_Init (fontdef);
HPDF_STATUS ret = MS_Mincho_Init (fontdef);
if (ret != HPDF_OK)
return ret;
@ -1730,11 +1733,11 @@ MS_Mincyo_BoldItalic_Init (HPDF_FontDef fontdef)
static HPDF_STATUS
MS_PMincyo_Init (HPDF_FontDef fontdef)
MS_PMincho_Init (HPDF_FontDef fontdef)
{
HPDF_STATUS ret;
HPDF_PTRACE ((" HPDF_FontDef_MS_PMincyo_Init\n"));
HPDF_PTRACE ((" HPDF_FontDef_MS_PMincho_Init\n"));
fontdef->ascent = 859;
fontdef->descent = -140;
@ -1756,9 +1759,9 @@ MS_PMincyo_Init (HPDF_FontDef fontdef)
static HPDF_STATUS
MS_PMincyo_Bold_Init (HPDF_FontDef fontdef)
MS_PMincho_Bold_Init (HPDF_FontDef fontdef)
{
HPDF_STATUS ret = MS_PMincyo_Init (fontdef);
HPDF_STATUS ret = MS_PMincho_Init (fontdef);
if (ret != HPDF_OK)
return ret;
@ -1768,9 +1771,9 @@ MS_PMincyo_Bold_Init (HPDF_FontDef fontdef)
static HPDF_STATUS
MS_PMincyo_Italic_Init (HPDF_FontDef fontdef)
MS_PMincho_Italic_Init (HPDF_FontDef fontdef)
{
HPDF_STATUS ret = MS_PMincyo_Init (fontdef);
HPDF_STATUS ret = MS_PMincho_Init (fontdef);
if (ret != HPDF_OK)
return ret;
@ -1779,9 +1782,9 @@ MS_PMincyo_Italic_Init (HPDF_FontDef fontdef)
}
static HPDF_STATUS
MS_PMincyo_BoldItalic_Init (HPDF_FontDef fontdef)
MS_PMincho_BoldItalic_Init (HPDF_FontDef fontdef)
{
HPDF_STATUS ret = MS_PMincyo_Init (fontdef);
HPDF_STATUS ret = MS_PMincho_Init (fontdef);
if (ret != HPDF_OK)
return ret;
@ -1849,52 +1852,52 @@ HPDF_UseJPFonts (HPDF_Doc pdf)
if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK)
return ret;
/* MS-Mincyo */
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincyo",
MS_Mincyo_Init);
/* MS-Mincho */
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho",
MS_Mincho_Init);
if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK)
return ret;
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincyo,Bold",
MS_Mincyo_Bold_Init);
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho,Bold",
MS_Mincho_Bold_Init);
if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK)
return ret;
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincyo,Italic",
MS_Mincyo_Italic_Init);
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho,Italic",
MS_Mincho_Italic_Init);
if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK)
return ret;
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincyo,BoldItalic",
MS_Mincyo_BoldItalic_Init);
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-Mincho,BoldItalic",
MS_Mincho_BoldItalic_Init);
if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK)
return ret;
/* MS-PMincyo */
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincyo",
MS_PMincyo_Init);
/* MS-PMincho */
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho",
MS_PMincho_Init);
if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK)
return ret;
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincyo,Bold",
MS_PMincyo_Bold_Init);
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho,Bold",
MS_PMincho_Bold_Init);
if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK)
return ret;
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincyo,Italic",
MS_PMincyo_Italic_Init);
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho,Italic",
MS_PMincho_Italic_Init);
if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK)
return ret;
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincyo,BoldItalic",
MS_PMincyo_BoldItalic_Init);
fontdef = HPDF_CIDFontDef_New (pdf->mmgr, "MS-PMincho,BoldItalic",
MS_PMincho_BoldItalic_Init);
if ((ret = HPDF_Doc_RegisterFontDef (pdf, fontdef)) != HPDF_OK)
return ret;

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_kr.c
* << Haru Free PDF Library >> -- hpdf_fontdef_kr.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.4 >> -- hpdf_fontdef_tt.c
* << Haru Free PDF Library >> -- hpdf_fontdef_tt.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -22,7 +25,7 @@
#define HPDF_REQUIRED_TAGS_COUNT 13
static const char *REQUIRED_TAGS[HPDF_REQUIRED_TAGS_COUNT] = {
static const char * const REQUIRED_TAGS[HPDF_REQUIRED_TAGS_COUNT] = {
"OS/2",
"cmap",
"cvt ",
@ -457,11 +460,11 @@ LoadFontData (HPDF_FontDef fontdef,
attr->glyph_tbl.base_offset = tbl->offset;
fontdef->cap_height =
HPDF_TTFontDef_GetCharBBox (fontdef, (HPDF_UINT16)'H').top;
(HPDF_UINT16)HPDF_TTFontDef_GetCharBBox (fontdef, (HPDF_UINT16)'H').top;
fontdef->x_height =
HPDF_TTFontDef_GetCharBBox (fontdef, (HPDF_UINT16)'x').top;
fontdef->missing_width = (HPDF_UINT32)attr->h_metric[0].advance_width * 1000 /
attr->header.units_per_em;
(HPDF_UINT16)HPDF_TTFontDef_GetCharBBox (fontdef, (HPDF_UINT16)'x').top;
fontdef->missing_width = (HPDF_INT16)((HPDF_UINT32)attr->h_metric[0].advance_width * 1000 /
attr->header.units_per_em);
HPDF_PTRACE ((" fontdef->cap_height=%d\n", fontdef->cap_height));
HPDF_PTRACE ((" fontdef->x_height=%d\n", fontdef->x_height));
@ -501,7 +504,7 @@ LoadFontData2 (HPDF_FontDef fontdef,
if ((ret = HPDF_Stream_Read (stream, tag, &size)) != HPDF_OK)
return ret;
if (HPDF_MemCmp (tag, "ttcf", 4) != 0)
if (HPDF_MemCmp (tag, (HPDF_BYTE *)"ttcf", 4) != 0)
return HPDF_SetError (fontdef->error, HPDF_INVALID_TTC_FILE, 0);
if ((ret = HPDF_Stream_Seek (stream, 8, HPDF_SEEK_SET)) != HPDF_OK)
@ -557,16 +560,16 @@ HPDF_TTFontDef_GetCharBBox (HPDF_FontDef fontdef,
return bbox;
ret += GetINT16 (attr->stream, &i);
bbox.left = (HPDF_INT32)i * 1000 / attr->header.units_per_em;
bbox.left = (HPDF_REAL)((HPDF_INT32)i * 1000 / attr->header.units_per_em);
ret += GetINT16 (attr->stream, &i);
bbox.bottom = (HPDF_INT32)i * 1000 / attr->header.units_per_em;
bbox.bottom = (HPDF_REAL)((HPDF_INT32)i * 1000 / attr->header.units_per_em);
ret += GetINT16 (attr->stream, &i);
bbox.right = (HPDF_INT32)i * 1000 / attr->header.units_per_em;
bbox.right = (HPDF_REAL)((HPDF_INT32)i * 1000 / attr->header.units_per_em);
ret += GetINT16 (attr->stream, &i);
bbox.top = (HPDF_INT32)i * 1000 / attr->header.units_per_em;
bbox.top = (HPDF_REAL)((HPDF_INT32)i * 1000 / attr->header.units_per_em);
if (ret != HPDF_OK)
return HPDF_ToBox(0, 0, 0, 0);
@ -718,7 +721,7 @@ LoadTTFTable (HPDF_FontDef fontdef)
for (i = 0; i < attr->offset_tbl.num_tables; i++) {
HPDF_UINT siz = 4;
ret += HPDF_Stream_Read (attr->stream, tbl->tag, &siz);
ret += HPDF_Stream_Read (attr->stream, (HPDF_BYTE *)tbl->tag, &siz);
ret += GetUINT32 (attr->stream, &tbl->check_sum);
ret += GetUINT32 (attr->stream, &tbl->offset);
ret += GetUINT32 (attr->stream, &tbl->length);
@ -782,14 +785,14 @@ ParseHead (HPDF_FontDef fontdef)
if (ret != HPDF_OK)
return HPDF_Error_GetCode (fontdef->error);
fontdef->font_bbox. left = (HPDF_INT32)attr->header.x_min * 1000 /
attr->header.units_per_em;
fontdef->font_bbox. bottom = (HPDF_INT32)attr->header.y_min * 1000 /
attr->header.units_per_em;
fontdef->font_bbox. right = (HPDF_INT32)attr->header.x_max * 1000 /
attr->header.units_per_em;
fontdef->font_bbox. top = (HPDF_INT32)attr->header.y_max * 1000 /
attr->header.units_per_em;
fontdef->font_bbox. left = (HPDF_REAL)((HPDF_INT32)attr->header.x_min * 1000 /
attr->header.units_per_em);
fontdef->font_bbox. bottom = (HPDF_REAL)((HPDF_INT32)attr->header.y_min * 1000 /
attr->header.units_per_em);
fontdef->font_bbox. right = (HPDF_REAL)((HPDF_INT32)attr->header.x_max * 1000 /
attr->header.units_per_em);
fontdef->font_bbox. top = (HPDF_REAL)((HPDF_INT32)attr->header.y_max * 1000 /
attr->header.units_per_em);
return HPDF_OK;
}
@ -837,11 +840,11 @@ ParseHhea (HPDF_FontDef fontdef)
return ret;
ret += GetINT16 (attr->stream, &fontdef->ascent);
fontdef->ascent = (HPDF_INT32)fontdef->ascent * 1000 /
attr->header.units_per_em;
fontdef->ascent = (HPDF_INT16)((HPDF_INT32)fontdef->ascent * 1000 /
attr->header.units_per_em);
ret += GetINT16 (attr->stream, &fontdef->descent);
fontdef->descent = (HPDF_INT32)fontdef->descent * 1000 /
attr->header.units_per_em;
fontdef->descent = (HPDF_INT16)((HPDF_INT32)fontdef->descent * 1000 /
attr->header.units_per_em);
if (ret != HPDF_OK)
return HPDF_Error_GetCode (fontdef->error);
@ -1049,7 +1052,7 @@ ParseCMAP_format4 (HPDF_FontDef fontdef,
return HPDF_Error_GetCode (fontdef->error);
pend_count = attr->cmap.end_count;
for (i = 0; i < attr->cmap.seg_count_x2 / 2; i++)
for (i = 0; i < (HPDF_UINT)attr->cmap.seg_count_x2 / 2; i++)
if ((ret = GetUINT16 (attr->stream, pend_count++)) != HPDF_OK)
return ret;
@ -1063,7 +1066,7 @@ ParseCMAP_format4 (HPDF_FontDef fontdef,
return HPDF_Error_GetCode (fontdef->error);
pstart_count = attr->cmap.start_count;
for (i = 0; i < attr->cmap.seg_count_x2 / 2; i++)
for (i = 0; i < (HPDF_UINT)attr->cmap.seg_count_x2 / 2; i++)
if ((ret = GetUINT16 (attr->stream, pstart_count++)) != HPDF_OK)
return ret;
@ -1074,7 +1077,7 @@ ParseCMAP_format4 (HPDF_FontDef fontdef,
return HPDF_Error_GetCode (fontdef->error);
pid_delta = attr->cmap.id_delta;
for (i = 0; i < attr->cmap.seg_count_x2 / 2; i++)
for (i = 0; i < (HPDF_UINT)attr->cmap.seg_count_x2 / 2; i++)
if ((ret = GetINT16 (attr->stream, pid_delta++)) != HPDF_OK)
return ret;
@ -1085,7 +1088,7 @@ ParseCMAP_format4 (HPDF_FontDef fontdef,
return HPDF_Error_GetCode (fontdef->error);
pid_range_offset = attr->cmap.id_range_offset;
for (i = 0; i < attr->cmap.seg_count_x2 / 2; i++)
for (i = 0; i < (HPDF_UINT)attr->cmap.seg_count_x2 / 2; i++)
if ((ret = GetUINT16 (attr->stream, pid_range_offset++)) != HPDF_OK)
return ret;
@ -1109,9 +1112,9 @@ ParseCMAP_format4 (HPDF_FontDef fontdef,
} else
attr->cmap.glyph_id_array = NULL;
#ifdef HPDF_DEBUG
#ifdef LIBHPDF_DEBUG
/* print all elements of cmap table */
for (i = 0; i < attr->cmap.seg_count_x2 / 2; i++) {
for (i = 0; i < (HPDF_UINT)attr->cmap.seg_count_x2 / 2; i++) {
HPDF_PTRACE((" ParseCMAP_format4[%d] start_count=0x%04X, "
"end_count=0x%04X, id_delta=%d, id_range_offset=%u\n", i,
attr->cmap.start_count[i], attr->cmap.end_count[i],
@ -1163,7 +1166,7 @@ HPDF_TTFontDef_GetGlyphid (HPDF_FontDef fontdef,
" ret=%u\n", i, unicode,
unicode + attr->cmap.id_delta[i]));
return unicode + attr->cmap.id_delta[i];
return (HPDF_UINT16)(unicode + attr->cmap.id_delta[i]);
} else {
HPDF_UINT idx = attr->cmap.id_range_offset[i] / 2 +
(unicode - attr->cmap.start_count[i]) - (seg_count - i);
@ -1173,8 +1176,8 @@ HPDF_TTFontDef_GetGlyphid (HPDF_FontDef fontdef,
i, idx, (HPDF_UINT)attr->cmap.glyph_id_array_count));
return 0;
} else {
HPDF_UINT16 gid = attr->cmap.glyph_id_array[idx] +
attr->cmap.id_delta[i];
HPDF_UINT16 gid = (HPDF_UINT16)(attr->cmap.glyph_id_array[idx] +
attr->cmap.id_delta[i]);
HPDF_PTRACE((" HPDF_TTFontDef_GetGlyphid idx=%u unicode=0x%04X "
"id=%u\n", idx, unicode, gid));
return gid;
@ -1209,8 +1212,8 @@ HPDF_TTFontDef_GetCharWidth (HPDF_FontDef fontdef,
CheckCompositGryph (fontdef, gid);
}
advance_width = (HPDF_UINT)hmetrics.advance_width * 1000 /
attr->header.units_per_em;
advance_width = (HPDF_UINT16)((HPDF_UINT)hmetrics.advance_width * 1000 /
attr->header.units_per_em);
return (HPDF_INT16)advance_width;
}
@ -1222,7 +1225,7 @@ CheckCompositGryph (HPDF_FontDef fontdef,
{
HPDF_TTFontDefAttr attr = (HPDF_TTFontDefAttr)fontdef->attr;
HPDF_UINT offset = attr->glyph_tbl.offsets[gid];
// HPDF_UINT len = attr->glyph_tbl.offsets[gid + 1] - offset;
/* HPDF_UINT len = attr->glyph_tbl.offsets[gid + 1] - offset; */
HPDF_STATUS ret;
HPDF_PTRACE ((" CheckCompositGryph\n"));
@ -1320,8 +1323,8 @@ HPDF_TTFontDef_GetGidWidth (HPDF_FontDef fontdef,
hmetrics = attr->h_metric[gid];
advance_width = (HPDF_UINT)hmetrics.advance_width * 1000 /
attr->header.units_per_em;
advance_width = (HPDF_UINT16)((HPDF_UINT)hmetrics.advance_width * 1000 /
attr->header.units_per_em);
HPDF_PTRACE((" HPDF_TTFontDef_GetGidWidth gid=%u, width=%u\n",
gid, advance_width));
@ -1453,7 +1456,7 @@ ParseLoca (HPDF_FontDef fontdef)
}
#ifdef HPDF_DEBUG
#ifdef LIBHPDF_DEBUG
poffset = attr->glyph_tbl.offsets;
for (i = 0; i <= attr->num_glyphs; i++) {
HPDF_PTRACE((" ParseLOCA offset[%u]=%u\n", i, (HPDF_UINT)*poffset));
@ -1608,7 +1611,7 @@ ParseName (HPDF_FontDef fontdef)
HPDF_SEEK_SET)) != HPDF_OK)
return ret;
if ((ret = HPDF_Stream_Read (attr->stream, attr->base_font, &len_id1))
if ((ret = HPDF_Stream_Read (attr->stream, (HPDF_BYTE *)attr->base_font, &len_id1))
!= HPDF_OK)
return ret;
} else {
@ -1624,7 +1627,7 @@ ParseName (HPDF_FontDef fontdef)
!= HPDF_OK)
return ret;
if ((ret = HPDF_Stream_Read (attr->stream, tmp, &len_id2)) != HPDF_OK)
if ((ret = HPDF_Stream_Read (attr->stream, (HPDF_BYTE *)tmp, &len_id2)) != HPDF_OK)
return ret;
} else {
if ((ret = LoadUnicodeName (attr->stream, offset_id2u, len_id2u,
@ -1639,7 +1642,7 @@ ParseName (HPDF_FontDef fontdef)
* if subfamily name is "Bold" or "Italic" or "BoldItalic", set flags
* attribute.
*/
if (HPDF_MemCmp (tmp, "Regular", 7) != 0) {
if (HPDF_MemCmp ((HPDF_BYTE *)tmp, (HPDF_BYTE *)"Regular", 7) != 0) {
char *dst = attr->base_font + len_id1;
char *src = tmp;
HPDF_UINT j;
@ -1662,8 +1665,7 @@ ParseName (HPDF_FontDef fontdef)
fontdef->flags |= HPDF_FONT_ITALIC;
}
HPDF_MemCpy (fontdef->base_font, attr->base_font,
HPDF_LIMIT_MAX_NAME_LEN + 1);
HPDF_MemCpy ((HPDF_BYTE *)fontdef->base_font, (HPDF_BYTE *)attr->base_font, HPDF_LIMIT_MAX_NAME_LEN + 1);
HPDF_PTRACE((" ParseName() base_font=%s\n", attr->base_font));
@ -1676,6 +1678,7 @@ ParseOS2 (HPDF_FontDef fontdef)
HPDF_TTFontDefAttr attr = (HPDF_TTFontDefAttr)fontdef->attr;
HPDF_TTFTable *tbl = FindTable (fontdef, "OS/2");
HPDF_STATUS ret;
HPDF_UINT16 version;
HPDF_UINT len;
HPDF_PTRACE ((" ParseOS2\n"));
@ -1683,11 +1686,19 @@ ParseOS2 (HPDF_FontDef fontdef)
if (!tbl)
return HPDF_SetError (fontdef->error, HPDF_TTF_MISSING_TABLE, 0);
/* get the number version. */
ret = HPDF_Stream_Seek (attr->stream, tbl->offset, HPDF_SEEK_SET);
if (ret != HPDF_OK)
return ret;
if ((ret = GetUINT16 (attr->stream, &version)) != HPDF_OK)
return ret;
/* check whether the font is allowed to be embedded. */
ret = HPDF_Stream_Seek (attr->stream, tbl->offset + 8, HPDF_SEEK_SET);
if (ret != HPDF_OK)
return ret;
/* check whether the font is allowed to be embedded. */
if ((ret = GetUINT16 (attr->stream, &attr->fs_type)) != HPDF_OK)
return ret;
@ -1695,32 +1706,59 @@ ParseOS2 (HPDF_FontDef fontdef)
return HPDF_SetError (fontdef->error, HPDF_TTF_CANNOT_EMBEDDING_FONT,
0);
if ((ret = HPDF_Stream_Seek (attr->stream, tbl->offset + 20, HPDF_SEEK_SET))
/* get fields sfamilyclass and panose. */
if ((ret = HPDF_Stream_Seek (attr->stream, tbl->offset + 30, HPDF_SEEK_SET))
!= HPDF_OK)
return ret;
len = 12;
len = 2;
if ((ret = HPDF_Stream_Read (attr->stream, attr->sfamilyclass, &len)) != HPDF_OK)
return ret;
len = 10;
if ((ret = HPDF_Stream_Read (attr->stream, attr->panose, &len)) != HPDF_OK)
return ret;
HPDF_PTRACE((" ParseOS2 PANOSE=%u-%u "
"%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
HPDF_PTRACE((" ParseOS2 sFamilyClass=%d-%d "
"Panose=%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X-%02X\n",
attr->sfamilyclass[0], attr->sfamilyclass[1],
attr->panose[0], attr->panose[1], attr->panose[2], attr->panose[3],
attr->panose[4], attr->panose[5], attr->panose[6], attr->panose[7],
attr->panose[8], attr->panose[9], attr->panose[10], attr->panose[11]));
attr->panose[8], attr->panose[9]));
if (attr->panose[0] == 1 || attr->panose[0] == 4)
/* Class ID = 1 Oldstyle Serifs
Class ID = 2 Transitional Serifs
Class ID = 3 Modern Serifs
Class ID = 4 Clarendon Serifs
Class ID = 5 Slab Serifs
Class ID = 6 (reserved for future use)
Class ID = 7 Freeform Serifs
Class ID = 8 Sans Serif
Class ID = 9 Ornamentals
Class ID = 10 Scripts
Class ID = 11 (reserved for future use)
Class ID = 12 Symbolic */
if ((attr->sfamilyclass[0] > 0 && attr->sfamilyclass[0] < 6)
|| (attr->sfamilyclass[0] == 7))
fontdef->flags = fontdef->flags | HPDF_FONT_SERIF;
/* get ulCodePageRange1 */
if ((ret = HPDF_Stream_Seek (attr->stream, 78, HPDF_SEEK_CUR)) != HPDF_OK)
return ret;
if (attr->sfamilyclass[0] == 10)
fontdef->flags = fontdef->flags | HPDF_FONT_SCRIPT;
if ((ret = GetUINT32 (attr->stream, &attr->code_page_range1)) != HPDF_OK)
return ret;
if (attr->sfamilyclass[0] == 12)
fontdef->flags = fontdef->flags | HPDF_FONT_SYMBOLIC;
if ((ret = GetUINT32 (attr->stream, &attr->code_page_range2)) != HPDF_OK)
return ret;
/* get fields ulCodePageRange1 and ulCodePageRange2 */
if(version > 0) {
if ((ret = HPDF_Stream_Seek (attr->stream, 36, HPDF_SEEK_CUR)) != HPDF_OK)
return ret;
if ((ret = GetUINT32 (attr->stream, &attr->code_page_range1)) != HPDF_OK)
return ret;
if ((ret = GetUINT32 (attr->stream, &attr->code_page_range2)) != HPDF_OK)
return ret;
}
HPDF_PTRACE((" ParseOS2 CodePageRange1=%08X CodePageRange2=%08X\n",
(HPDF_UINT)attr->code_page_range1,
@ -1843,11 +1881,11 @@ RecreateName (HPDF_FontDef fontdef,
/* add suffix to font-name. */
if (name_rec->name_id == 1 || name_rec->name_id == 4) {
if (name_rec->platform_id == 0 || name_rec->platform_id == 3) {
ret += HPDF_Stream_Write (tmp_stream, attr->tag_name2,
ret += HPDF_Stream_Write (tmp_stream, (HPDF_BYTE *)attr->tag_name2,
sizeof(attr->tag_name2));
name_len += sizeof(attr->tag_name2);
} else {
ret += HPDF_Stream_Write (tmp_stream, attr->tag_name,
ret += HPDF_Stream_Write (tmp_stream, (HPDF_BYTE *)attr->tag_name,
sizeof(attr->tag_name));
name_len += sizeof(attr->tag_name);
}
@ -1953,10 +1991,13 @@ HPDF_TTFontDef_SaveFontData (HPDF_FontDef fontdef,
HPDF_Stream tmp_stream;
HPDF_UINT32 *new_offsets;
HPDF_UINT i;
HPDF_UINT32 check_sum_ptr;
HPDF_UINT32 check_sum_ptr = 0;
HPDF_STATUS ret;
HPDF_UINT32 offset_base;
HPDF_UINT32 tmp_check_sum = 0xB1B0AFBA;
HPDF_TTFTable emptyTable;
emptyTable.length = 0;
emptyTable.offset = 0;
HPDF_PTRACE ((" SaveFontData\n"));
@ -1989,6 +2030,12 @@ HPDF_TTFontDef_SaveFontData (HPDF_FontDef fontdef,
HPDF_UINT32 *poffset;
HPDF_UINT32 value;
if (!tbl) {
tbl = &emptyTable;
HPDF_MemCpy((HPDF_BYTE *)tbl->tag,
(const HPDF_BYTE *)REQUIRED_TAGS[i], 4);
}
if (!tbl) {
ret = HPDF_SetError (fontdef->error, HPDF_TTF_MISSING_TABLE, i);
goto Exit;
@ -2001,11 +2048,11 @@ HPDF_TTFontDef_SaveFontData (HPDF_FontDef fontdef,
length = tbl->length;
new_offset = tmp_stream->size;
if (HPDF_MemCmp (tbl->tag, "head", 4) == 0) {
if (HPDF_MemCmp ((HPDF_BYTE *)tbl->tag, (HPDF_BYTE *)"head", 4) == 0) {
ret = WriteHeader (fontdef, tmp_stream, &check_sum_ptr);
} else if (HPDF_MemCmp (tbl->tag, "glyf", 4) == 0) {
} else if (HPDF_MemCmp ((HPDF_BYTE *)tbl->tag, (HPDF_BYTE *)"glyf", 4) == 0) {
ret = RecreateGLYF (fontdef, new_offsets, tmp_stream);
} else if (HPDF_MemCmp (tbl->tag, "loca", 4) == 0) {
} else if (HPDF_MemCmp ((HPDF_BYTE *)tbl->tag, (HPDF_BYTE *)"loca", 4) == 0) {
HPDF_UINT j;
HPDF_MemSet (&value, 0, 4);
@ -2022,7 +2069,7 @@ HPDF_TTFontDef_SaveFontData (HPDF_FontDef fontdef,
poffset++;
}
}
} else if (HPDF_MemCmp (tbl->tag, "name", 4) == 0) {
} else if (HPDF_MemCmp ((HPDF_BYTE *)tbl->tag, (HPDF_BYTE *)"name", 4) == 0) {
ret = RecreateName (fontdef, tmp_stream);
} else {
HPDF_UINT size = 4;
@ -2081,7 +2128,7 @@ HPDF_TTFontDef_SaveFontData (HPDF_FontDef fontdef,
REQUIRED_TAGS[i], (HPDF_UINT)tbl.check_sum,
(HPDF_UINT)tbl.offset));
ret += HPDF_Stream_Write (stream, REQUIRED_TAGS[i], 4);
ret += HPDF_Stream_Write (stream, (HPDF_BYTE *)REQUIRED_TAGS[i], 4);
ret += WriteUINT32 (stream, tbl.check_sum);
tbl.offset += offset_base;
ret += WriteUINT32 (stream, tbl.offset);
@ -2155,7 +2202,7 @@ HPDF_TTFontDef_SetTagName (HPDF_FontDef fontdef,
if (HPDF_StrLen (tag, HPDF_LIMIT_MAX_NAME_LEN) != HPDF_TTF_FONT_TAG_LEN)
return;
HPDF_MemCpy (attr->tag_name, tag, HPDF_TTF_FONT_TAG_LEN);
HPDF_MemCpy ((HPDF_BYTE *)attr->tag_name, (HPDF_BYTE *)tag, HPDF_TTF_FONT_TAG_LEN);
attr->tag_name[HPDF_TTF_FONT_TAG_LEN] = '+';
for (i = 0; i < HPDF_TTF_FONT_TAG_LEN + 1; i++) {
@ -2164,11 +2211,10 @@ HPDF_TTFontDef_SetTagName (HPDF_FontDef fontdef,
}
HPDF_MemSet (buf, 0, HPDF_LIMIT_MAX_NAME_LEN + 1);
HPDF_MemCpy (buf, attr->tag_name, HPDF_TTF_FONT_TAG_LEN + 1);
HPDF_MemCpy (buf + HPDF_TTF_FONT_TAG_LEN + 1, fontdef->base_font,
HPDF_LIMIT_MAX_NAME_LEN - HPDF_TTF_FONT_TAG_LEN - 1);
HPDF_MemCpy ((HPDF_BYTE *)buf, (HPDF_BYTE *)attr->tag_name, HPDF_TTF_FONT_TAG_LEN + 1);
HPDF_MemCpy ((HPDF_BYTE *)buf + HPDF_TTF_FONT_TAG_LEN + 1, (HPDF_BYTE *)fontdef->base_font, HPDF_LIMIT_MAX_NAME_LEN - HPDF_TTF_FONT_TAG_LEN - 1);
HPDF_MemCpy (attr->base_font, buf, HPDF_LIMIT_MAX_NAME_LEN + 1);
HPDF_MemCpy ((HPDF_BYTE *)attr->base_font, (HPDF_BYTE *)buf, HPDF_LIMIT_MAX_NAME_LEN + 1);
}
/*
@ -2188,7 +2234,7 @@ FindTable (HPDF_FontDef fontdef,
HPDF_UINT i;
for (i = 0; i < attr->offset_tbl.num_tables; i++, tbl++) {
if (HPDF_MemCmp (tbl->tag, tag, 4) == 0) {
if (HPDF_MemCmp ((HPDF_BYTE *)tbl->tag, (HPDF_BYTE *)tag, 4) == 0) {
HPDF_PTRACE((" FindTable find table[%c%c%c%c]\n",
tbl->tag[0], tbl->tag[1], tbl->tag[2], tbl->tag[3]));
return tbl;
@ -2227,4 +2273,3 @@ INT16Swap (HPDF_INT16 *value)
HPDF_MemCpy (b, (HPDF_BYTE *)value, 2);
*value = (HPDF_INT16)((HPDF_INT16)b[0] << 8 | (HPDF_INT16)b[1]);
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_fontdef_type1.c
* << Haru Free PDF Library >> -- hpdf_fontdef_type1.c
*
* Copyright (c) 1999-2004 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -69,15 +72,12 @@ HPDF_Type1FontDef_New (HPDF_MMgr mmgr)
if (!fontdef)
return NULL;
HPDF_MemSet (fontdef, 0, sizeof (HPDF_FontDef_Rec));
fontdef->sig_bytes = HPDF_FONTDEF_SIG_BYTES;
fontdef->base_font[0] = 0;
fontdef->mmgr = mmgr;
fontdef->error = mmgr->error;
fontdef->type = HPDF_FONTDEF_TYPE_TYPE1;
fontdef->clean_fn = NULL;
fontdef->free_fn = FreeFunc;
fontdef->descriptor = NULL;
fontdef->valid = HPDF_FALSE;
fontdef_attr = HPDF_GetMem (mmgr, sizeof(HPDF_Type1FontDefAttr_Rec));
if (!fontdef_attr) {
@ -106,7 +106,7 @@ GetKeyword (const char *src,
*keyword = 0;
while (len > 0) {
while (len > 1) {
if (HPDF_IS_WHITE_SPACE(*src)) {
*keyword = 0;
@ -175,7 +175,7 @@ LoadAfm (HPDF_FontDef fontdef,
} else
if (HPDF_StrCmp (keyword, "ItalicAngle") == 0) {
fontdef->italic_angle = HPDF_AToI (s);
fontdef->italic_angle = (HPDF_INT16)HPDF_AToI (s);
if (fontdef->italic_angle != 0)
fontdef->flags |= HPDF_FONT_ITALIC;
} else
@ -195,35 +195,35 @@ LoadAfm (HPDF_FontDef fontdef,
char buf[HPDF_INT_LEN + 1];
s = GetKeyword (s, buf, HPDF_INT_LEN + 1);
fontdef->font_bbox.left = HPDF_AToI (buf);
fontdef->font_bbox.left = (HPDF_REAL)HPDF_AToI (buf);
s = GetKeyword (s, buf, HPDF_INT_LEN + 1);
fontdef->font_bbox.bottom = HPDF_AToI (buf);
fontdef->font_bbox.bottom = (HPDF_REAL)HPDF_AToI (buf);
s = GetKeyword (s, buf, HPDF_INT_LEN + 1);
fontdef->font_bbox.right = HPDF_AToI (buf);
fontdef->font_bbox.right = (HPDF_REAL)HPDF_AToI (buf);
GetKeyword (s, buf, HPDF_INT_LEN + 1);
fontdef->font_bbox.top = HPDF_AToI (buf);
fontdef->font_bbox.top = (HPDF_REAL)HPDF_AToI (buf);
} else
if (HPDF_StrCmp (keyword, "EncodingScheme") == 0) {
HPDF_StrCpy (attr->encoding_scheme, s,
attr->encoding_scheme + HPDF_LIMIT_MAX_NAME_LEN);
} else
if (HPDF_StrCmp (keyword, "CapHeight") == 0) {
fontdef->cap_height = HPDF_AToI (s);
fontdef->cap_height = (HPDF_UINT16)HPDF_AToI (s);
} else
if (HPDF_StrCmp (keyword, "Ascender") == 0) {
fontdef->ascent = HPDF_AToI (s);
fontdef->ascent = (HPDF_INT16)HPDF_AToI (s);
} else
if (HPDF_StrCmp (keyword, "Descender") == 0) {
fontdef->descent = HPDF_AToI (s);
fontdef->descent = (HPDF_INT16)HPDF_AToI (s);
} else
if (HPDF_StrCmp (keyword, "STDHW") == 0) {
fontdef->stemh = HPDF_AToI (s);
fontdef->stemh = (HPDF_UINT16)HPDF_AToI (s);
} else
if (HPDF_StrCmp (keyword, "STDHV") == 0) {
fontdef->stemv = HPDF_AToI (s);
fontdef->stemv = (HPDF_UINT16)HPDF_AToI (s);
} else
if (HPDF_StrCmp (keyword, "StartCharMetrics") == 0) {
attr->widths_count = HPDF_AToI (s);
@ -261,7 +261,7 @@ LoadAfm (HPDF_FontDef fontdef,
s = GetKeyword (s, buf2, HPDF_LIMIT_MAX_NAME_LEN + 1);
HPDF_AToI (buf2);
cdata->char_cd = HPDF_AToI (buf2);
cdata->char_cd = (HPDF_INT16)HPDF_AToI (buf2);
} else
return HPDF_SetError (fontdef->error,
@ -278,7 +278,7 @@ LoadAfm (HPDF_FontDef fontdef,
if (buf2[0] == 0)
return HPDF_SetError (fontdef->error, HPDF_INVALID_WX_DATA, 0);
cdata->width = HPDF_AToI (buf2);
cdata->width = (HPDF_INT16)HPDF_AToI (buf2);
/* N PostScript language character name */
s = HPDF_StrStr (s, "N ", 0);
@ -316,14 +316,14 @@ LoadFontData (HPDF_FontDef fontdef,
return HPDF_Error_GetCode (fontdef->error);
len = 11;
ret = HPDF_Stream_Read (stream, pbuf, &len);
ret = HPDF_Stream_Read (stream, (HPDF_BYTE *)pbuf, &len);
if (ret != HPDF_OK)
return ret;
pbuf += 11;
for (;;) {
len = HPDF_STREAM_BUF_SIZ - 11;
ret = HPDF_Stream_Read (stream, pbuf, &len);
ret = HPDF_Stream_Read (stream, (HPDF_BYTE *)pbuf, &len);
if (ret == HPDF_STREAM_EOF) {
end_flg = HPDF_TRUE;
} else if (ret != HPDF_OK)
@ -354,16 +354,16 @@ LoadFontData (HPDF_FontDef fontdef,
}
if (end_flg) {
if ((ret = HPDF_Stream_Write (attr->font_data, buf, len + 11)) !=
if ((ret = HPDF_Stream_Write (attr->font_data, (HPDF_BYTE *)buf, len + 11)) !=
HPDF_OK)
return ret;
break;
} else {
if ((ret = HPDF_Stream_Write (attr->font_data, buf, len)) !=
if ((ret = HPDF_Stream_Write (attr->font_data, (HPDF_BYTE *)buf, len)) !=
HPDF_OK)
return ret;
HPDF_MemCpy (buf, buf + len, 11);
HPDF_MemCpy ((HPDF_BYTE *)buf, (HPDF_BYTE *)buf + len, 11);
pbuf = buf + 11;
}
}
@ -424,8 +424,8 @@ HPDF_Type1FontDef_Duplicate (HPDF_MMgr mmgr,
fontdef->type = src->type;
fontdef->valid = src->valid;
// copy data of attr,widths
// attention to charset
/* copy data of attr,widths
attention to charset */
return NULL;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_gstate.c
* << Haru Free PDF Library >> -- hpdf_gstate.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -59,6 +62,7 @@ HPDF_GState_New (HPDF_MMgr mmgr,
gstate->font = current->font;
gstate->font_size = current->font_size;
gstate->writing_mode = current->writing_mode;
gstate->prev = current;
gstate->depth = current->depth + 1;

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_image.c
* << Haru Free PDF Library >> -- hpdf_image.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -10,7 +13,6 @@
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
* 2006.08.12 modified.
*/
#include "hpdf_conf.h"
@ -219,6 +221,36 @@ HPDF_Image_LoadJpegImage (HPDF_MMgr mmgr,
return image;
}
HPDF_Image
HPDF_Image_LoadJpegImageFromMem (HPDF_MMgr mmgr,
const HPDF_BYTE *buf,
HPDF_UINT size,
HPDF_Xref xref)
{
HPDF_Stream jpeg_data;
HPDF_Image image;
HPDF_PTRACE ((" HPDF_Image_LoadJpegImageFromMem\n"));
jpeg_data = HPDF_MemStream_New(mmgr,size);
if (!HPDF_Stream_Validate (jpeg_data)) {
HPDF_RaiseError (mmgr->error, HPDF_INVALID_STREAM, 0);
return NULL;
}
if (HPDF_Stream_Write (jpeg_data, buf, size) != HPDF_OK) {
HPDF_Stream_Free (jpeg_data);
return NULL;
}
image = HPDF_Image_LoadJpegImage(mmgr,jpeg_data,xref);
/* destroy file stream */
HPDF_Stream_Free (jpeg_data);
return image;
}
HPDF_Image
HPDF_Image_LoadRawImage (HPDF_MMgr mmgr,
@ -297,12 +329,13 @@ HPDF_Image_LoadRawImageFromMem (HPDF_MMgr mmgr,
{
HPDF_Dict image;
HPDF_STATUS ret = HPDF_OK;
HPDF_UINT size;
HPDF_UINT size=0;
HPDF_PTRACE ((" HPDF_Image_LoadRawImageFromMem\n"));
if (color_space != HPDF_CS_DEVICE_GRAY &&
color_space != HPDF_CS_DEVICE_RGB) {
color_space != HPDF_CS_DEVICE_RGB &&
color_space != HPDF_CS_DEVICE_CMYK) {
HPDF_SetError (mmgr->error, HPDF_INVALID_COLOR_SPACE, 0);
return NULL;
}
@ -323,13 +356,22 @@ HPDF_Image_LoadRawImageFromMem (HPDF_MMgr mmgr,
if (ret != HPDF_OK)
return NULL;
if (color_space == HPDF_CS_DEVICE_GRAY) {
size = (HPDF_DOUBLE)width * height / (8 / bits_per_component) + 0.876;
ret = HPDF_Dict_AddName (image, "ColorSpace", COL_GRAY);
} else {
size = (HPDF_DOUBLE)width * height / (8 / bits_per_component) + 0.876;
size *= 3;
ret = HPDF_Dict_AddName (image, "ColorSpace", COL_RGB);
switch (color_space) {
case HPDF_CS_DEVICE_GRAY:
size = (HPDF_UINT)((HPDF_DOUBLE)width * height / (8 / bits_per_component) + 0.876);
ret = HPDF_Dict_AddName (image, "ColorSpace", COL_GRAY);
break;
case HPDF_CS_DEVICE_RGB:
size = (HPDF_UINT)((HPDF_DOUBLE)width * height / (8 / bits_per_component) + 0.876);
size *= 3;
ret = HPDF_Dict_AddName (image, "ColorSpace", COL_RGB);
break;
case HPDF_CS_DEVICE_CMYK:
size = (HPDF_UINT)((HPDF_DOUBLE)width * height / (8 / bits_per_component) + 0.876);
size *= 4;
ret = HPDF_Dict_AddName (image, "ColorSpace", COL_CMYK);
break;
default:;
}
if (ret != HPDF_OK)
@ -394,8 +436,8 @@ HPDF_Image_GetSize (HPDF_Image image)
height = HPDF_Dict_GetItem (image, "Height", HPDF_OCLASS_NUMBER);
if (width && height) {
ret.x = width->value;
ret.y = height->value;
ret.x = (HPDF_REAL)width->value;
ret.y = (HPDF_REAL)height->value;
}
return ret;
@ -418,8 +460,8 @@ HPDF_Image_GetSize2 (HPDF_Image image, HPDF_Point *size)
height = HPDF_Dict_GetItem (image, "Height", HPDF_OCLASS_NUMBER);
if (width && height) {
size->x = width->value;
size->y = height->value;
size->x = (HPDF_REAL)width->value;
size->y = (HPDF_REAL)height->value;
}
return HPDF_OK;
@ -446,30 +488,42 @@ HPDF_Image_GetBitsPerComponent (HPDF_Image image)
HPDF_EXPORT(const char*)
HPDF_Image_GetColorSpace (HPDF_Image image)
{
HPDF_Name n;
HPDF_Name n;
HPDF_PTRACE ((" HPDF_Image_GetColorSpace\n"));
HPDF_PTRACE ((" HPDF_Image_GetColorSpace\n"));
n = HPDF_Dict_GetItem (image, "ColorSpace", HPDF_OCLASS_NAME);
n = HPDF_Dict_GetItem (image, "ColorSpace", HPDF_OCLASS_NAME);
if (!n) {
HPDF_CheckError (image->error);
return NULL;
}
if (!n) {
HPDF_Array a;
return n->value;
HPDF_Error_Reset(image->error);
a = HPDF_Dict_GetItem (image, "ColorSpace", HPDF_OCLASS_ARRAY);
if (a) {
n = HPDF_Array_GetItem (a, 0, HPDF_OCLASS_NAME);
}
}
if (!n) {
HPDF_CheckError (image->error);
return NULL;
}
return n->value;
}
HPDF_EXPORT(HPDF_UINT)
HPDF_Image_GetWidth (HPDF_Image image)
{
return HPDF_Image_GetSize (image).x;
return (HPDF_UINT)HPDF_Image_GetSize (image).x;
}
HPDF_EXPORT(HPDF_UINT)
HPDF_Image_GetHeight (HPDF_Image image)
{
return HPDF_Image_GetSize (image).y;
return (HPDF_UINT)HPDF_Image_GetSize (image).y;
}
HPDF_STATUS
@ -565,4 +619,46 @@ HPDF_Image_SetColorMask (HPDF_Image image,
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_Image_AddSMask (HPDF_Image image,
HPDF_Image smask)
{
const char *name;
if (!HPDF_Image_Validate (image))
return HPDF_INVALID_IMAGE;
if (!HPDF_Image_Validate (smask))
return HPDF_INVALID_IMAGE;
if (HPDF_Dict_GetItem (image, "SMask", HPDF_OCLASS_BOOLEAN))
return HPDF_RaiseError (image->error, HPDF_INVALID_OPERATION, 0);
name = HPDF_Image_GetColorSpace (smask);
if (!name || HPDF_StrCmp (COL_GRAY, name) != 0)
return HPDF_RaiseError (smask->error, HPDF_INVALID_COLOR_SPACE, 0);
return HPDF_Dict_Add (image, "SMask", smask);
}
HPDF_STATUS
HPDF_Image_SetColorSpace (HPDF_Image image,
HPDF_Array colorspace)
{
if (!HPDF_Image_Validate (image))
return HPDF_INVALID_IMAGE;
return HPDF_Dict_Add (image, "ColorSpace", colorspace);
}
HPDF_STATUS
HPDF_Image_SetRenderingIntent (HPDF_Image image,
const char* intent)
{
if (!HPDF_Image_Validate (image))
return HPDF_INVALID_IMAGE;
return HPDF_Dict_AddName (image, "Intent", intent);
}

797
PDF/src/hpdf_image_ccitt.c Normal file
View File

@ -0,0 +1,797 @@
/*
* << Haru Free PDF Library >> -- hpdf_image.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* 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.
*
*/
#include "hpdf_conf.h"
#include "hpdf_utils.h"
#include "hpdf.h"
#include <memory.h>
#include <assert.h>
#define G3CODES
#include "t4.h"
typedef unsigned int uint32;
typedef int int32;
typedef unsigned short uint16;
typedef int32 tsize_t; /* i/o size in bytes */
/*
* Typedefs for ``method pointers'' used internally.
*/
typedef unsigned char tidataval_t; /* internal image data value type */
typedef tidataval_t* tidata_t; /* reference to internal image data */
/*
* Compression+decompression state blocks are
* derived from this ``base state'' block.
*/
typedef struct {
/* int rw_mode; */ /* O_RDONLY for decode, else encode */
int mode; /* operating mode */
uint32 rowbytes; /* bytes in a decoded scanline */
uint32 rowpixels; /* pixels in a scanline */
uint16 cleanfaxdata; /* CleanFaxData tag */
uint32 badfaxrun; /* BadFaxRun tag */
uint32 badfaxlines; /* BadFaxLines tag */
uint32 groupoptions; /* Group 3/4 options tag */
uint32 recvparams; /* encoded Class 2 session params */
char* subaddress; /* subaddress string */
uint32 recvtime; /* time spent receiving (secs) */
char* faxdcs; /* Table 2/T.30 encoded session params */
} HPDF_Fax3BaseState;
typedef struct {
HPDF_Fax3BaseState b;
/* Decoder state info */
const unsigned char* bitmap; /* bit reversal table */
uint32 data; /* current i/o byte/word */
int bit; /* current i/o bit in byte */
int EOLcnt; /* count of EOL codes recognized */
/* TIFFFaxFillFunc fill;*/ /* fill routine */
uint32* runs; /* b&w runs for current/previous row */
uint32* refruns; /* runs for reference line */
uint32* curruns; /* runs for current line */
/* Encoder state info */
/* Ttag tag; */ /* encoding state */
unsigned char* refline; /* reference line for 2d decoding */
int k; /* #rows left that can be 2d encoded */
int maxk; /* max #rows that can be 2d encoded */
int line;
} HPDF_Fax3CodecState;
#define Fax3State(tif) (&(tif)->tif_data->b)
#define EncoderState(tif) ((tif)->tif_data)
#define isAligned(p,t) ((((unsigned long)(p)) & (sizeof (t)-1)) == 0)
/* NB: the uint32 casts are to silence certain ANSI-C compilers */
#define TIFFhowmany(x, y) ((((uint32)(x))+(((uint32)(y))-1))/((uint32)(y)))
#define TIFFhowmany8(x) (((x)&0x07)?((uint32)(x)>>3)+1:(uint32)(x)>>3)
#define TIFFroundup(x, y) (TIFFhowmany(x,y)*(y))
/*
struct _HPDF_CCITT_Encoder {
} HPDF_CCITT_Encoder;
*/
struct _HPDF_CCITT_Data {
HPDF_Fax3CodecState *tif_data;
HPDF_Stream dst;
tsize_t tif_rawdatasize;/* # of bytes in raw data buffer */
tsize_t tif_rawcc; /* bytes unread from raw buffer */
tidata_t tif_rawcp; /* current spot in raw buffer */
tidata_t tif_rawdata; /* raw data buffer */
} HPDF_CCITT_Data;
static HPDF_STATUS HPDF_InitCCITTFax3(struct _HPDF_CCITT_Data *pData)
{
HPDF_Fax3BaseState* sp;
HPDF_Fax3CodecState* esp;
/*
* Allocate state block so tag methods have storage to record values.
*/
pData->tif_data = (HPDF_Fax3CodecState *)
malloc(sizeof (HPDF_Fax3CodecState));
if (pData->tif_data == NULL) {
return 1;
}
sp = Fax3State(pData);
/* sp->rw_mode = pData->tif_mode; */
/*
* Override parent get/set field methods.
*/
sp->groupoptions = 0;
sp->recvparams = 0;
sp->subaddress = NULL;
sp->faxdcs = NULL;
esp = EncoderState(pData);
esp->refline = NULL;
esp->runs = NULL;
return HPDF_OK;
}
static HPDF_STATUS HPDF_FreeCCITTFax3(struct _HPDF_CCITT_Data *pData)
{
if(pData->tif_data!=NULL) {
HPDF_Fax3CodecState* esp=pData->tif_data;
if(esp->refline!=NULL) {
free(esp->refline);
esp->refline=NULL;
}
if(esp->runs!=NULL) {
free(esp->runs);
esp->runs=NULL;
}
free(pData->tif_data);
pData->tif_data=NULL;
}
if(pData->tif_rawdata!=NULL) {
free(pData->tif_rawdata);
pData->tif_rawdata=NULL;
}
return HPDF_OK;
}
/*
* Setup G3/G4-related compression/decompression state
* before data is processed. This routine is called once
* per image -- it sets up different state based on whether
* or not decoding or encoding is being done and whether
* 1D- or 2D-encoded data is involved.
*/
static int
HPDF_Fax3SetupState(struct _HPDF_CCITT_Data *pData, HPDF_UINT width,
HPDF_UINT height,
HPDF_UINT line_width)
{
HPDF_Fax3BaseState* sp = Fax3State(pData);
HPDF_Fax3CodecState* esp = EncoderState(pData);
uint32 rowbytes, rowpixels, nruns;
HPDF_UNUSED (height);
rowbytes = line_width;
rowpixels = width;
sp->rowbytes = (uint32) rowbytes;
sp->rowpixels = (uint32) rowpixels;
nruns = 2*TIFFroundup(rowpixels,32);
nruns += 3;
esp->runs = (uint32*) malloc(2*nruns * sizeof (uint32));
if (esp->runs == NULL)
return 1;
esp->curruns = esp->runs;
esp->refruns = esp->runs + nruns;
/*
* 2d encoding requires a scanline
* buffer for the ``reference line''; the
* scanline against which delta encoding
* is referenced. The reference line must
* be initialized to be ``white'' (done elsewhere).
*/
esp->refline = (unsigned char*) malloc(rowbytes);
if (esp->refline == NULL) {
return 1;
}
return HPDF_OK;
}
/*
* Reset encoding state at the start of a strip.
*/
static HPDF_STATUS
HPDF_Fax3PreEncode(struct _HPDF_CCITT_Data *pData/*, tsample_t s*/)
{
HPDF_Fax3CodecState* sp = EncoderState(pData);
/* assert(sp != NULL); */
sp->bit = 8;
sp->data = 0;
/* sp->tag = G3_1D; */
/*
* This is necessary for Group 4; otherwise it isn't
* needed because the first scanline of each strip ends
* up being copied into the refline.
*/
if (sp->refline)
memset(sp->refline, 0x00, sp->b.rowbytes);
sp->k = sp->maxk = 0;
sp->line = 0;
return HPDF_OK;
}
static HPDF_STATUS
HPDF_CCITT_AppendToStream(HPDF_Stream dst,
tidata_t tif_rawdata,
tsize_t tif_rawcc)
{
if(HPDF_Stream_Write(dst, tif_rawdata, tif_rawcc)!=HPDF_OK)
return 1;
return HPDF_OK;
}
/*
* Internal version of TIFFFlushData that can be
* called by ``encodestrip routines'' w/o concern
* for infinite recursion.
*/
static HPDF_STATUS
HPDF_CCITT_FlushData(struct _HPDF_CCITT_Data *pData)
{
if (pData->tif_rawcc > 0) {
/*if (!isFillOrder(tif, tif->tif_dir.td_fillorder) &&
(tif->tif_flags & TIFF_NOBITREV) == 0)
TIFFReverseBits((unsigned char *pData->tif_rawdata,
pData->tif_rawcc);*/
if (HPDF_CCITT_AppendToStream(pData->dst,
pData->tif_rawdata, pData->tif_rawcc)!=HPDF_OK)
return 1;
pData->tif_rawcc = 0;
pData->tif_rawcp = pData->tif_rawdata;
}
return HPDF_OK;
}
#define HPDF_Fax3FlushBits(tif, sp) { \
if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \
(void) HPDF_CCITT_FlushData(tif); \
*(tif)->tif_rawcp++ = (tidataval_t) (sp)->data; \
(tif)->tif_rawcc++; \
(sp)->data = 0, (sp)->bit = 8; \
}
#define _FlushBits(tif) { \
if ((tif)->tif_rawcc >= (tif)->tif_rawdatasize) \
(void) HPDF_CCITT_FlushData(tif); \
*(tif)->tif_rawcp++ = (tidataval_t) data; \
(tif)->tif_rawcc++; \
data = 0, bit = 8; \
}
static const int _msbmask[9] =
{ 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
#define _PutBits(tif, bits, length) { \
while (length > bit) { \
data |= bits >> (length - bit); \
length -= bit; \
_FlushBits(tif); \
} \
data |= (bits & _msbmask[length]) << (bit - length); \
bit -= length; \
if (bit == 0) \
_FlushBits(tif); \
}
/*
* Write a variable-length bit-value to
* the output stream. Values are
* assumed to be at most 16 bits.
*/
static void
HPDF_Fax3PutBits(struct _HPDF_CCITT_Data *pData, unsigned int bits, unsigned int length)
{
HPDF_Fax3CodecState* sp = EncoderState(pData);
unsigned int bit = sp->bit;
int data = sp->data;
_PutBits(pData, bits, length);
sp->data = data;
sp->bit = bit;
}
/*
* Write a code to the output stream.
*/
#define putcode(tif, te) HPDF_Fax3PutBits(tif, (te)->code, (te)->length)
/*
* Write the sequence of codes that describes
* the specified span of zero's or one's. The
* appropriate table that holds the make-up and
* terminating codes is supplied.
*/
static void
putspan(struct _HPDF_CCITT_Data *pData, int32 span, const tableentry* tab)
{
HPDF_Fax3CodecState* sp = EncoderState(pData);
unsigned int bit = sp->bit;
int data = sp->data;
unsigned int code, length;
while (span >= 2624) {
const tableentry* te = &tab[63 + (2560>>6)];
code = te->code, length = te->length;
#ifdef FAX3_DEBUG
DEBUG_PRINT("MakeUp", te->runlen);
#endif
_PutBits(pData, code, length);
span -= te->runlen;
}
if (span >= 64) {
const tableentry* te = &tab[63 + (span>>6)];
assert(te->runlen == 64*(span>>6));
code = te->code, length = te->length;
#ifdef FAX3_DEBUG
DEBUG_PRINT("MakeUp", te->runlen);
#endif
_PutBits(pData, code, length);
span -= te->runlen;
}
code = tab[span].code, length = tab[span].length;
#ifdef FAX3_DEBUG
DEBUG_PRINT(" Term", tab[span].runlen);
#endif
_PutBits(pData, code, length);
sp->data = data;
sp->bit = bit;
}
static const unsigned char zeroruns[256] = {
8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4, /* 0x00 - 0x0f */
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0x10 - 0x1f */
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x20 - 0x2f */
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0x30 - 0x3f */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x40 - 0x4f */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x50 - 0x5f */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x60 - 0x6f */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x70 - 0x7f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x80 - 0x8f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x90 - 0x9f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xa0 - 0xaf */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xb0 - 0xbf */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xc0 - 0xcf */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xd0 - 0xdf */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xe0 - 0xef */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0xf0 - 0xff */
};
static const unsigned char oneruns[256] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00 - 0x0f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20 - 0x2f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x30 - 0x3f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x40 - 0x4f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x50 - 0x5f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60 - 0x6f */
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70 - 0x7f */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x80 - 0x8f */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0x90 - 0x9f */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xa0 - 0xaf */
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, /* 0xb0 - 0xbf */
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xc0 - 0xcf */
2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, /* 0xd0 - 0xdf */
3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, /* 0xe0 - 0xef */
4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 7, 8, /* 0xf0 - 0xff */
};
/*
* Find a span of ones or zeros using the supplied
* table. The ``base'' of the bit string is supplied
* along with the start+end bit indices.
*/
static /*inline*/ int32 find0span(unsigned char* bp, int32 bs, int32 be)
{
int32 bits = be - bs;
int32 n, span;
bp += bs>>3;
/*
* Check partial byte on lhs.
*/
if (bits > 0 && (n = (bs & 7))) {
span = zeroruns[(*bp << n) & 0xff];
if (span > 8-n) /* table value too generous */
span = 8-n;
if (span > bits) /* constrain span to bit range */
span = bits;
if (n+span < 8) /* doesn't extend to edge of byte */
return (span);
bits -= span;
bp++;
} else
span = 0;
if (bits >= (int32)(2 * 8 * sizeof(long))) {
long* lp;
/*
* Align to longword boundary and check longwords.
*/
while (!isAligned(bp, long)) {
if (*bp != 0x00)
return (span + zeroruns[*bp]);
span += 8, bits -= 8;
bp++;
}
lp = (long*) bp;
while ((bits >= (int32)(8 * sizeof(long))) && (0 == *lp)) {
span += 8*sizeof (long), bits -= 8*sizeof (long);
lp++;
}
bp = (unsigned char*) lp;
}
/*
* Scan full bytes for all 0's.
*/
while (bits >= 8) {
if (*bp != 0x00) /* end of run */
return (span + zeroruns[*bp]);
span += 8, bits -= 8;
bp++;
}
/*
* Check partial byte on rhs.
*/
if (bits > 0) {
n = zeroruns[*bp];
span += (n > bits ? bits : n);
}
return (span);
}
static /*inline*/ int32
find1span(unsigned char* bp, int32 bs, int32 be)
{
int32 bits = be - bs;
int32 n, span;
bp += bs>>3;
/*
* Check partial byte on lhs.
*/
if (bits > 0 && (n = (bs & 7))) {
span = oneruns[(*bp << n) & 0xff];
if (span > 8-n) /* table value too generous */
span = 8-n;
if (span > bits) /* constrain span to bit range */
span = bits;
if (n+span < 8) /* doesn't extend to edge of byte */
return (span);
bits -= span;
bp++;
} else
span = 0;
if (bits >= (int32)(2 * 8 * sizeof(long))) {
long* lp;
/*
* Align to longword boundary and check longwords.
*/
while (!isAligned(bp, long)) {
if (*bp != 0xff)
return (span + oneruns[*bp]);
span += 8, bits -= 8;
bp++;
}
lp = (long*) bp;
while ((bits >= (int32)(8 * sizeof(long))) && (~0 == *lp)) {
span += 8*sizeof (long), bits -= 8*sizeof (long);
lp++;
}
bp = (unsigned char*) lp;
}
/*
* Scan full bytes for all 1's.
*/
while (bits >= 8) {
if (*bp != 0xff) /* end of run */
return (span + oneruns[*bp]);
span += 8, bits -= 8;
bp++;
}
/*
* Check partial byte on rhs.
*/
if (bits > 0) {
n = oneruns[*bp];
span += (n > bits ? bits : n);
}
return (span);
}
/*
* Return the offset of the next bit in the range
* [bs..be] that is different from the specified
* color. The end, be, is returned if no such bit
* exists.
*/
#define finddiff(_cp, _bs, _be, _color) \
(_bs + (_color ? find1span(_cp,_bs,_be) : find0span(_cp,_bs,_be)))
/*
* Like finddiff, but also check the starting bit
* against the end in case start > end.
*/
#define finddiff2(_cp, _bs, _be, _color) \
(_bs < _be ? finddiff(_cp,_bs,_be,_color) : _be)
/*
void
HPDF_Fax3PostEncode(struct _HPDF_CCITT_Data *pData)
{
HPDF_Fax3CodecState* sp = EncoderState(pData);
if (sp->bit != 8)
HPDF_Fax3FlushBits(pData, sp);
}
*/
static const tableentry horizcode =
{ 3, 0x1, 0 }; /* 001 */
static const tableentry passcode =
{ 4, 0x1, 0 }; /* 0001 */
static const tableentry vcodes[7] = {
{ 7, 0x03, 0 }, /* 0000 011 */
{ 6, 0x03, 0 }, /* 0000 11 */
{ 3, 0x03, 0 }, /* 011 */
{ 1, 0x1, 0 }, /* 1 */
{ 3, 0x2, 0 }, /* 010 */
{ 6, 0x02, 0 }, /* 0000 10 */
{ 7, 0x02, 0 } /* 0000 010 */
};
/*
* 2d-encode a row of pixels. Consult the CCITT
* documentation for the algorithm.
*/
static HPDF_STATUS
HPDF_Fax3Encode2DRow(struct _HPDF_CCITT_Data *pData, unsigned char* bp, unsigned char* rp, uint32 bits)
{
#define PIXEL(buf,ix) ((((buf)[(ix)>>3]) >> (7-((ix)&7))) & 1)
uint32 a0 = 0;
uint32 a1 = (PIXEL(bp, 0) != 0 ? 0 : finddiff(bp, 0, bits, 0));
uint32 b1 = (PIXEL(rp, 0) != 0 ? 0 : finddiff(rp, 0, bits, 0));
uint32 a2, b2;
for (;;) {
b2 = finddiff2(rp, b1, bits, PIXEL(rp,b1));
if (b2 >= a1) {
int32 d = b1 - a1;
if (!(-3 <= d && d <= 3)) { /* horizontal mode */
a2 = finddiff2(bp, a1, bits, PIXEL(bp,a1));
putcode(pData, &horizcode);
if (a0+a1 == 0 || PIXEL(bp, a0) == 0) {
putspan(pData, a1-a0, TIFFFaxWhiteCodes);
putspan(pData, a2-a1, TIFFFaxBlackCodes);
} else {
putspan(pData, a1-a0, TIFFFaxBlackCodes);
putspan(pData, a2-a1, TIFFFaxWhiteCodes);
}
a0 = a2;
} else { /* vertical mode */
putcode(pData, &vcodes[d+3]);
a0 = a1;
}
} else { /* pass mode */
putcode(pData, &passcode);
a0 = b2;
}
if (a0 >= bits)
break;
a1 = finddiff(bp, a0, bits, PIXEL(bp,a0));
b1 = finddiff(rp, a0, bits, !PIXEL(bp,a0));
b1 = finddiff(rp, b1, bits, PIXEL(bp,a0));
}
return HPDF_OK;
#undef PIXEL
}
/*
* Encode the requested amount of data.
*/
static HPDF_STATUS
HPDF_Fax4Encode(struct _HPDF_CCITT_Data *pData, tidata_t bp, tsize_t cc/*, tsample_t s*/)
{
HPDF_Fax3CodecState *sp = EncoderState(pData);
/* (void) s; */
while ((long)cc > 0) {
if (HPDF_Fax3Encode2DRow(pData, bp, sp->refline, sp->b.rowpixels)!=HPDF_OK)
return 1;
memcpy(sp->refline, bp, sp->b.rowbytes);
bp += sp->b.rowbytes;
cc -= sp->b.rowbytes;
}
return HPDF_OK;
}
static void
HPDF_Fax4PostEncode(struct _HPDF_CCITT_Data *pData)
{
/* HPDF_Fax3CodecState *sp = EncoderState(pData); */
/* terminate strip w/ EOFB */
HPDF_Fax3PutBits(pData, EOL, 12);
HPDF_Fax3PutBits(pData, EOL, 12);
/*if (sp->bit != 8)
HPDF_Fax3FlushBits(pData, sp);
*/
HPDF_CCITT_FlushData(pData);
}
HPDF_STATUS
HPDF_Stream_CcittToStream( const HPDF_BYTE *buf,
HPDF_Stream dst,
HPDF_Encrypt e,
HPDF_UINT width,
HPDF_UINT height,
HPDF_UINT line_width,
HPDF_BOOL top_is_first)
{
const HPDF_BYTE *pBufPos;
const HPDF_BYTE *pBufEnd; /* end marker */
int lineIncrement;
struct _HPDF_CCITT_Data data;
HPDF_UNUSED (e);
if(height==0) return 1;
if(top_is_first) {
pBufPos = buf;
pBufEnd=buf+(line_width*height);
lineIncrement = line_width;
} else {
pBufPos = buf+(line_width*(height-1));
pBufEnd= buf-line_width;
lineIncrement = -((int)line_width);
}
memset(&data, 0, sizeof(struct _HPDF_CCITT_Data));
data.dst = dst;
data.tif_rawdata = (tidata_t) malloc( 16384 ); /* 16 kb buffer */
data.tif_rawdatasize = 16384;
data.tif_rawcc = 0;
data.tif_rawcp = data.tif_rawdata;
if(HPDF_InitCCITTFax3(&data)!=HPDF_OK)
return 1;
if(HPDF_Fax3SetupState(&data, width, height, line_width)!=HPDF_OK)
{
HPDF_FreeCCITTFax3(&data);
return 1;
}
if(HPDF_Fax3PreEncode(&data)!=HPDF_OK)
{
HPDF_FreeCCITTFax3(&data);
return 1;
}
/* encode data */
while(pBufEnd!=pBufPos)
{
HPDF_Fax4Encode(&data, (tidata_t)pBufPos, line_width);
pBufPos+=lineIncrement;
}
HPDF_Fax4PostEncode(&data);
HPDF_FreeCCITTFax3(&data);
return HPDF_OK;
}
HPDF_Image
HPDF_Image_Load1BitImageFromMem (HPDF_MMgr mmgr,
const HPDF_BYTE *buf,
HPDF_Xref xref,
HPDF_UINT width,
HPDF_UINT height,
HPDF_UINT line_width,
HPDF_BOOL top_is_first
)
{
HPDF_Dict image;
HPDF_STATUS ret = HPDF_OK;
/* HPDF_UINT size; */
HPDF_PTRACE ((" HPDF_Image_Load1BitImage\n"));
image = HPDF_DictStream_New (mmgr, xref);
if (!image)
return NULL;
image->header.obj_class |= HPDF_OSUBCLASS_XOBJECT;
ret += HPDF_Dict_AddName (image, "Type", "XObject");
ret += HPDF_Dict_AddName (image, "Subtype", "Image");
if (ret != HPDF_OK)
return NULL;
/* size = width * height; */
ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray");
if (ret != HPDF_OK)
return NULL;
if (HPDF_Dict_AddNumber (image, "Width", width) != HPDF_OK)
return NULL;
if (HPDF_Dict_AddNumber (image, "Height", height) != HPDF_OK)
return NULL;
if (HPDF_Dict_AddNumber (image, "BitsPerComponent", 1) != HPDF_OK)
return NULL;
if (HPDF_Stream_CcittToStream (buf, image->stream, NULL, width, height, line_width, top_is_first) != HPDF_OK)
return NULL;
return image;
}
/*
* Load image from buffer
* line_width - width of the line in bytes
* top_is_first - image orientation:
* TRUE if image is oriented TOP-BOTTOM;
* FALSE if image is oriented BOTTOM-TOP
*/
HPDF_EXPORT(HPDF_Image)
HPDF_Image_LoadRaw1BitImageFromMem (HPDF_Doc pdf,
const HPDF_BYTE *buf,
HPDF_UINT width,
HPDF_UINT height,
HPDF_UINT line_width,
HPDF_BOOL black_is1,
HPDF_BOOL top_is_first)
{
HPDF_Image image;
HPDF_PTRACE ((" HPDF_Image_Load1BitImageFromMem\n"));
if (!HPDF_HasDoc (pdf))
return NULL;
image = HPDF_Image_Load1BitImageFromMem(pdf->mmgr, buf, pdf->xref, width,
height, line_width, top_is_first);
if (!image)
HPDF_CheckError (&pdf->error);
if (pdf->compression_mode & HPDF_COMP_IMAGE)
{
image->filter = HPDF_STREAM_FILTER_CCITT_DECODE;
image->filterParams = HPDF_Dict_New(pdf->mmgr);
if(image->filterParams==NULL) {
return NULL;
}
/* pure 2D encoding, default is 0 */
HPDF_Dict_AddNumber (image->filterParams, "K", -1);
/* default is 1728 */
HPDF_Dict_AddNumber (image->filterParams, "Columns", width);
/* default is 0 */
HPDF_Dict_AddNumber (image->filterParams, "Rows", height);
HPDF_Dict_AddBoolean (image->filterParams, "BlackIs1", black_is1);
}
return image;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_image.c
* << Haru Free PDF Library >> -- hpdf_image.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -16,8 +19,9 @@
#include "hpdf_utils.h"
#include "hpdf_image.h"
#ifndef HPDF_NOPNGLIB
#ifndef LIBHPDF_HAVE_NOPNGLIB
#include <png.h>
#include <string.h>
static void
PngErrorFunc (png_structp png_ptr,
@ -38,6 +42,7 @@ PngReadFunc (png_structp png_ptr,
static HPDF_STATUS
LoadPngData (HPDF_Dict image,
HPDF_Xref xref,
HPDF_Stream png_data,
HPDF_BOOL delayed_loading);
@ -105,14 +110,15 @@ ReadPngData_Interlaced (HPDF_Dict image,
png_infop info_ptr)
{
png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
png_bytep* row_pointers = HPDF_GetMem (image->mmgr,
info_ptr->height * sizeof (png_bytep));
height * sizeof (png_bytep));
if (row_pointers) {
HPDF_UINT i;
HPDF_MemSet (row_pointers, 0, info_ptr->height * sizeof (png_bytep));
for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
HPDF_MemSet (row_pointers, 0, height * sizeof (png_bytep));
for (i = 0; i < (HPDF_UINT)height; i++) {
row_pointers[i] = HPDF_GetMem (image->mmgr, len);
if (image->error->error_no != HPDF_OK)
@ -120,11 +126,9 @@ ReadPngData_Interlaced (HPDF_Dict image,
}
if (image->error->error_no == HPDF_OK) {
/* } else { remove this line */
png_read_image(png_ptr, row_pointers);
/* if (image->error->error_no != HPDF_OK) { remove this line */
if (image->error->error_no == HPDF_OK) { /* add this line */
for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
for (i = 0; i < (HPDF_UINT)height; i++) {
if (HPDF_Stream_Write (image->stream, row_pointers[i], len) !=
HPDF_OK)
break;
@ -133,9 +137,8 @@ ReadPngData_Interlaced (HPDF_Dict image,
}
/* clean up */
for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
for (i = 0; i < (HPDF_UINT)height; i++) {
HPDF_FreeMem (image->mmgr, row_pointers[i]);
/* i-- remove this line */
}
HPDF_FreeMem (image->mmgr, row_pointers);
@ -150,12 +153,13 @@ ReadPngData (HPDF_Dict image,
png_infop info_ptr)
{
png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
png_bytep buf_ptr = HPDF_GetMem (image->mmgr, len);
if (buf_ptr) {
HPDF_UINT i;
for (i = 0; i < (HPDF_UINT)info_ptr->height; i++) {
for (i = 0; i < (HPDF_UINT)height; i++) {
png_read_rows(png_ptr, (png_byte**)&buf_ptr, NULL, 1);
if (image->error->error_no != HPDF_OK)
break;
@ -170,6 +174,152 @@ ReadPngData (HPDF_Dict image,
return image->error->error_no;
}
static HPDF_STATUS
ReadTransparentPaletteData (HPDF_Dict image,
png_structp png_ptr,
png_infop info_ptr,
png_bytep smask_data,
png_bytep trans,
int num_trans)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_UINT i, j;
png_bytep *row_ptr;
png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
png_uint_32 width = png_get_image_width(png_ptr, info_ptr);
row_ptr = HPDF_GetMem (image->mmgr, height * sizeof(png_bytep));
if (!row_ptr) {
return HPDF_FAILD_TO_ALLOC_MEM;
} else {
png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
for (i = 0; i < (HPDF_UINT)height; i++) {
row_ptr[i] = HPDF_GetMem(image->mmgr, len);
if (!row_ptr[i]) {
for (; i > 0; i--) {
HPDF_FreeMem (image->mmgr, row_ptr[i]);
}
HPDF_FreeMem (image->mmgr, row_ptr);
return HPDF_FAILD_TO_ALLOC_MEM;
}
}
}
png_read_image(png_ptr, row_ptr);
if (image->error->error_no != HPDF_OK) {
ret = HPDF_INVALID_PNG_IMAGE;
goto Error;
}
for (j = 0; j < height; j++) {
for (i = 0; i < width; i++) {
smask_data[width * j + i] = (row_ptr[j][i] < num_trans) ? trans[row_ptr[j][i]] : 0xFF;
}
if (HPDF_Stream_Write (image->stream, row_ptr[j], width) != HPDF_OK) {
ret = HPDF_FILE_IO_ERROR;
goto Error;
}
}
Error:
for (i = 0; i < (HPDF_UINT)height; i++) {
HPDF_FreeMem (image->mmgr, row_ptr[i]);
}
HPDF_FreeMem (image->mmgr, row_ptr);
return ret;
}
static HPDF_STATUS
ReadTransparentPngData (HPDF_Dict image,
png_structp png_ptr,
png_infop info_ptr,
png_bytep smask_data)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_INT row_len;
HPDF_UINT i, j;
png_bytep *row_ptr, row;
png_byte color_type;
png_uint_32 height = png_get_image_height(png_ptr, info_ptr);
png_uint_32 width = png_get_image_width(png_ptr, info_ptr);
color_type = png_get_color_type(png_ptr, info_ptr);
if (!(color_type & PNG_COLOR_MASK_ALPHA)) {
return HPDF_INVALID_PNG_IMAGE;
}
row_ptr = HPDF_GetMem (image->mmgr, height * sizeof(png_bytep));
if (!row_ptr) {
return HPDF_FAILD_TO_ALLOC_MEM;
} else {
png_uint_32 len = png_get_rowbytes(png_ptr, info_ptr);
for (i = 0; i < (HPDF_UINT)height; i++) {
row_ptr[i] = HPDF_GetMem(image->mmgr, len);
if (!row_ptr[i]) {
for (; i > 0; i--) {
HPDF_FreeMem (image->mmgr, row_ptr[i]);
}
HPDF_FreeMem (image->mmgr, row_ptr);
return HPDF_FAILD_TO_ALLOC_MEM;
}
}
}
png_read_image(png_ptr, row_ptr);
if (image->error->error_no != HPDF_OK) {
ret = HPDF_INVALID_PNG_IMAGE;
goto Error;
}
switch (color_type) {
case PNG_COLOR_TYPE_RGB_ALPHA:
row_len = 3 * width * sizeof(png_byte);
for (j = 0; j < height; j++) {
for (i = 0; i < width; i++) {
row = row_ptr[j];
memmove(row + (3 * i), row + (4*i), 3);
smask_data[width * j + i] = row[4 * i + 3];
}
if (HPDF_Stream_Write (image->stream, row, row_len) != HPDF_OK) {
ret = HPDF_FILE_IO_ERROR;
goto Error;
}
}
break;
case PNG_COLOR_TYPE_GRAY_ALPHA:
row_len = width * sizeof(png_byte);
for (j = 0; j < height; j++) {
for (i = 0; i < width; i++) {
row = row_ptr[j];
row[i] = row[2 * i];
smask_data[width * j + i] = row[2 * i + 1];
}
if (HPDF_Stream_Write (image->stream, row, row_len) != HPDF_OK) {
ret = HPDF_FILE_IO_ERROR;
goto Error;
}
}
break;
default:
ret = HPDF_INVALID_PNG_IMAGE;
goto Error;
}
Error:
for (i = 0; i < (HPDF_UINT)height; i++) {
HPDF_FreeMem (image->mmgr, row_ptr[i]);
}
HPDF_FreeMem (image->mmgr, row_ptr);
return ret;
}
static HPDF_STATUS
CreatePallet (HPDF_Dict image,
@ -257,7 +407,7 @@ HPDF_Image_LoadPngImage (HPDF_MMgr mmgr,
if (ret != HPDF_OK)
return NULL;
if (LoadPngData (image, png_data, delayed_loading) != HPDF_OK)
if (LoadPngData (image, xref, png_data, delayed_loading) != HPDF_OK)
return NULL;
return image;
@ -266,106 +416,241 @@ HPDF_Image_LoadPngImage (HPDF_MMgr mmgr,
static HPDF_STATUS
LoadPngData (HPDF_Dict image,
HPDF_Xref xref,
HPDF_Stream png_data,
HPDF_BOOL delayed_loading)
{
HPDF_STATUS ret;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
HPDF_STATUS ret = HPDF_OK;
png_uint_32 width, height;
int bit_depth, color_type;
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
HPDF_PTRACE ((" HPDF_Image_LoadPngImage\n"));
HPDF_PTRACE ((" HPDF_Image_LoadPngImage\n"));
/* create read_struct. */
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
image->error, PngErrorFunc, PngErrorFunc);
/* create read_struct. */
png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING,
image->error, PngErrorFunc, PngErrorFunc);
if (png_ptr == NULL) {
HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0);
return HPDF_FAILD_TO_ALLOC_MEM;
}
if (png_ptr == NULL) {
HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0);
return HPDF_FAILD_TO_ALLOC_MEM;
}
/* create info-struct */
info_ptr = png_create_info_struct (png_ptr);
/* create info-struct */
info_ptr = png_create_info_struct (png_ptr);
if (info_ptr == NULL) {
HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0);
goto Exit;
}
if (info_ptr == NULL) {
HPDF_SetError (image->error, HPDF_FAILD_TO_ALLOC_MEM, 0);
goto Exit;
}
png_set_sig_bytes (png_ptr, HPDF_PNG_BYTES_TO_CHECK);
png_set_read_fn (png_ptr, (void *)png_data, (png_rw_ptr)&PngReadFunc);
png_set_sig_bytes (png_ptr, HPDF_PNG_BYTES_TO_CHECK);
png_set_read_fn (png_ptr, (void *)png_data, (png_rw_ptr)&PngReadFunc);
/* reading info structure. */
png_read_info(png_ptr, info_ptr);
if (image->error->error_no != HPDF_OK)
goto Exit;
/* reading info structure. */
png_read_info(png_ptr, info_ptr);
if (image->error->error_no != HPDF_OK) {
goto Exit;
}
/* 16bit image and alpha color type are not supported. */
if (info_ptr->bit_depth == 16)
png_set_strip_16(png_ptr);
png_get_IHDR(png_ptr, info_ptr, &width, &height, &bit_depth, &color_type, NULL, NULL, NULL);
if (PNG_COLOR_MASK_ALPHA & info_ptr->color_type) {
/* png image with alpha chanel is not supported. */
png_set_strip_alpha(png_ptr);
}
/* 16bit images are not supported. */
if (bit_depth == 16) {
png_set_strip_16(png_ptr);
}
png_read_update_info(png_ptr, info_ptr);
if (image->error->error_no != HPDF_OK)
goto Exit;
png_read_update_info(png_ptr, info_ptr);
if (image->error->error_no != HPDF_OK) {
goto Exit;
}
/* if the image has color palette, copy the pallet of the image to
* create color map.
*/
if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
ret = CreatePallet(image, png_ptr, info_ptr);
else if (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)
ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray");
else
ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB");
/* check palette-based images for transparent areas and load them immediately if found */
if (xref && PNG_COLOR_TYPE_PALETTE & color_type) {
png_bytep trans;
int num_trans;
HPDF_Dict smask;
png_bytep smask_data;
if (ret != HPDF_OK)
goto Exit;
if (!png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS) ||
!png_get_tRNS(png_ptr, info_ptr, &trans, &num_trans, NULL)) {
goto no_transparent_color_in_palette;
}
/* read image-data
* if the image is interlaced, read whole image at once.
* if delayed_loading is HPDF_TRUE, the data does not load this phase.
*/
if (delayed_loading) {
image->before_write_fn = PngBeforeWrite;
image->after_write_fn = PngAfterWrite;
} else {
if (png_get_interlace_type(png_ptr, info_ptr) != PNG_INTERLACE_NONE)
ret = ReadPngData_Interlaced(image, png_ptr, info_ptr);
else
ret = ReadPngData(image, png_ptr, info_ptr);
smask = HPDF_DictStream_New (image->mmgr, xref);
if (!smask) {
ret = HPDF_FAILD_TO_ALLOC_MEM;
goto Exit;
}
if (ret != HPDF_OK)
goto Exit;
}
smask->header.obj_class |= HPDF_OSUBCLASS_XOBJECT;
ret = HPDF_Dict_AddName (smask, "Type", "XObject");
ret += HPDF_Dict_AddName (smask, "Subtype", "Image");
ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)width);
ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)height);
ret += HPDF_Dict_AddName (smask, "ColorSpace", "DeviceGray");
ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)bit_depth);
/* setting the info of the image. */
if (HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)info_ptr->width)
!= HPDF_OK)
goto Exit;
if (ret != HPDF_OK) {
HPDF_Dict_Free(smask);
ret = HPDF_INVALID_PNG_IMAGE;
goto Exit;
}
if (HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)info_ptr->height)
!= HPDF_OK)
goto Exit;
smask_data = HPDF_GetMem(image->mmgr, width * height);
if (!smask_data) {
HPDF_Dict_Free(smask);
ret = HPDF_FAILD_TO_ALLOC_MEM;
goto Exit;
}
if (HPDF_Dict_AddNumber (image, "BitsPerComponent",
(HPDF_UINT)info_ptr->bit_depth) != HPDF_OK)
goto Exit;
if (ReadTransparentPaletteData(image, png_ptr, info_ptr, smask_data, trans, num_trans) != HPDF_OK) {
HPDF_FreeMem(image->mmgr, smask_data);
HPDF_Dict_Free(smask);
ret = HPDF_INVALID_PNG_IMAGE;
goto Exit;
}
/* clean up */
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
if (HPDF_Stream_Write(smask->stream, smask_data, width * height) != HPDF_OK) {
HPDF_FreeMem(image->mmgr, smask_data);
HPDF_Dict_Free(smask);
ret = HPDF_FILE_IO_ERROR;
goto Exit;
}
HPDF_FreeMem(image->mmgr, smask_data);
return HPDF_OK;
ret += CreatePallet(image, png_ptr, info_ptr);
ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width);
ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height);
ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)bit_depth);
ret += HPDF_Dict_Add (image, "SMask", smask);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return HPDF_OK;
}
no_transparent_color_in_palette:
/* read images with alpha channel right away
we have to do this because image transparent mask must be added to the Xref */
if (xref && PNG_COLOR_MASK_ALPHA & color_type) {
HPDF_Dict smask;
png_bytep smask_data;
smask = HPDF_DictStream_New (image->mmgr, xref);
if (!smask) {
ret = HPDF_FAILD_TO_ALLOC_MEM;
goto Exit;
}
smask->header.obj_class |= HPDF_OSUBCLASS_XOBJECT;
ret = HPDF_Dict_AddName (smask, "Type", "XObject");
ret += HPDF_Dict_AddName (smask, "Subtype", "Image");
ret += HPDF_Dict_AddNumber (smask, "Width", (HPDF_UINT)width);
ret += HPDF_Dict_AddNumber (smask, "Height", (HPDF_UINT)height);
ret += HPDF_Dict_AddName (smask, "ColorSpace", "DeviceGray");
ret += HPDF_Dict_AddNumber (smask, "BitsPerComponent", (HPDF_UINT)bit_depth);
if (ret != HPDF_OK) {
HPDF_Dict_Free(smask);
ret = HPDF_INVALID_PNG_IMAGE;
goto Exit;
}
smask_data = HPDF_GetMem(image->mmgr, width * height);
if (!smask_data) {
HPDF_Dict_Free(smask);
ret = HPDF_FAILD_TO_ALLOC_MEM;
goto Exit;
}
if (ReadTransparentPngData(image, png_ptr, info_ptr, smask_data) != HPDF_OK) {
HPDF_FreeMem(image->mmgr, smask_data);
HPDF_Dict_Free(smask);
ret = HPDF_INVALID_PNG_IMAGE;
goto Exit;
}
if (HPDF_Stream_Write(smask->stream, smask_data, width * height) != HPDF_OK) {
HPDF_FreeMem(image->mmgr, smask_data);
HPDF_Dict_Free(smask);
ret = HPDF_FILE_IO_ERROR;
goto Exit;
}
HPDF_FreeMem(image->mmgr, smask_data);
if (color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
ret += HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray");
} else {
ret += HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB");
}
ret += HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width);
ret += HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height);
ret += HPDF_Dict_AddNumber (image, "BitsPerComponent", (HPDF_UINT)bit_depth);
ret += HPDF_Dict_Add (image, "SMask", smask);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return HPDF_OK;
}
/* if the image has color palette, copy the pallet of the image to
* create color map.
*/
if (color_type == PNG_COLOR_TYPE_PALETTE)
ret = CreatePallet(image, png_ptr, info_ptr);
else if (color_type == PNG_COLOR_TYPE_GRAY)
ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceGray");
else
ret = HPDF_Dict_AddName (image, "ColorSpace", "DeviceRGB");
if (ret != HPDF_OK)
goto Exit;
/* read image-data
* if the image is interlaced, read whole image at once.
* if delayed_loading is HPDF_TRUE, the data does not load this phase.
*/
if (delayed_loading) {
image->before_write_fn = PngBeforeWrite;
image->after_write_fn = PngAfterWrite;
} else {
if (png_get_interlace_type(png_ptr, info_ptr) != PNG_INTERLACE_NONE)
ret = ReadPngData_Interlaced(image, png_ptr, info_ptr);
else
ret = ReadPngData(image, png_ptr, info_ptr);
if (ret != HPDF_OK)
goto Exit;
}
/* setting the info of the image. */
if (HPDF_Dict_AddNumber (image, "Width", (HPDF_UINT)width)
!= HPDF_OK)
goto Exit;
if (HPDF_Dict_AddNumber (image, "Height", (HPDF_UINT)height)
!= HPDF_OK)
goto Exit;
if (HPDF_Dict_AddNumber (image, "BitsPerComponent",
(HPDF_UINT)bit_depth) != HPDF_OK)
goto Exit;
/* clean up */
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return HPDF_OK;
Exit:
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
return image->error->error_no;
if (ret != HPDF_OK) {
return ret;
}
return image->error->error_no;
}
@ -386,7 +671,7 @@ PngBeforeWrite (HPDF_Dict obj)
if (!s)
return HPDF_SetError (obj->error, HPDF_MISSING_FILE_NAME_ENTRY, 0);
png_data = HPDF_FileReader_New (obj->mmgr, s->value);
png_data = HPDF_FileReader_New (obj->mmgr, (const char *)(s->value));
if (!HPDF_Stream_Validate (png_data))
return obj->error->error_no;
@ -398,7 +683,7 @@ PngBeforeWrite (HPDF_Dict obj)
return HPDF_SetError (obj->error, HPDF_INVALID_PNG_IMAGE, 0);
}
if ((ret = LoadPngData (obj, png_data, HPDF_FALSE)) != HPDF_OK) {
if ((ret = LoadPngData (obj, NULL, png_data, HPDF_FALSE)) != HPDF_OK) {
HPDF_Stream_Free(png_data);
return ret;
}
@ -420,5 +705,5 @@ PngAfterWrite (HPDF_Dict obj)
}
#endif /* HPDF_NOPNGLIB */
#endif /* LIBHPDF_HAVE_NOPNGLIB */

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_info.c
* << Haru Free PDF Library >> -- hpdf_info.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -16,7 +19,7 @@
#include "hpdf_utils.h"
#include "hpdf_info.h"
static const char *HPDF_INFO_ATTR_NAMES[] = {
static const char * const HPDF_INFO_ATTR_NAMES[] = {
"CreationDate",
"ModDate",
"Author",
@ -25,6 +28,8 @@ static const char *HPDF_INFO_ATTR_NAMES[] = {
"Title",
"Subject",
"Keywords",
"Trapped",
"GTS_PDFXVersion",
NULL
};
@ -57,6 +62,9 @@ HPDF_Info_SetInfoAttr (HPDF_Dict info,
if (type <= HPDF_INFO_MOD_DATE)
return HPDF_SetError (info->error, HPDF_INVALID_PARAMETER, 0);
if (type == HPDF_INFO_TRAPPED)
return HPDF_Dict_AddName(info, name, value);
return HPDF_Dict_Add (info, name, HPDF_String_New (info->mmgr, value,
encoder));
}
@ -79,7 +87,7 @@ HPDF_Info_GetInfoAttr (HPDF_Dict info,
if (!s)
return NULL;
else
return s->value;
return (const char *)(s->value);
}
@ -141,7 +149,7 @@ HPDF_Info_SetInfoDateAttr (HPDF_Dict info,
return HPDF_SetError (info->error, HPDF_INVALID_DATE_TIME, 0);
}
ptmp = HPDF_MemCpy (tmp, "D:", 2);
ptmp = (char *)HPDF_MemCpy ((HPDF_BYTE *)tmp, (HPDF_BYTE *)"D:", 2);
ptmp = HPDF_IToA2 (ptmp, value.year, 5);
ptmp = HPDF_IToA2 (ptmp, value.month, 3);
ptmp = HPDF_IToA2 (ptmp, value.day, 3);

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_list.c
* << Haru Free PDF Library >> -- hpdf_list.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -272,7 +275,7 @@ HPDF_List_Clear (HPDF_List list)
*
*/
HPDF_STATUS
static HPDF_STATUS
Resize (HPDF_List list,
HPDF_UINT count)
{

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_mmgr.c
* << Haru Free PDF Library >> -- hpdf_mmgr.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -104,11 +107,15 @@ HPDF_MMgr_New (HPDF_Error error,
}
#ifdef HPDF_MEM_DEBUG
mmgr->alloc_cnt += 1;
if (mmgr) {
mmgr->alloc_cnt += 1;
}
#endif
}
mmgr->buf_size = buf_size;
if (mmgr) {
mmgr->buf_size = buf_size;
}
} else
HPDF_SetError(error, HPDF_FAILD_TO_ALLOC_MEM, HPDF_NOERROR);

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_name.c
* << Haru Free PDF Library >> -- hpdf_name.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

237
PDF/src/hpdf_namedict.c Normal file
View File

@ -0,0 +1,237 @@
/*
* << Haru Free PDF Library >> -- hpdf_namedict.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* 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.
*
*/
#include "hpdf_conf.h"
#include "hpdf_utils.h"
#include "hpdf_consts.h"
#include "hpdf_namedict.h"
#ifndef HPDF_UNUSED
#define HPDF_UNUSED(a) ((void)(a))
#endif
static const char * const HPDF_NAMEDICT_KEYS[] = {
"EmbeddedFiles"
};
HPDF_NameDict
HPDF_NameDict_New (HPDF_MMgr mmgr,
HPDF_Xref xref)
{
HPDF_NameDict ndict;
HPDF_PTRACE((" HPDF_NameDict_New\n"));
ndict = HPDF_Dict_New (mmgr);
if (!ndict)
return NULL;
if (HPDF_Xref_Add (xref, ndict) != HPDF_OK)
return NULL;
ndict->header.obj_class |= HPDF_OSUBCLASS_NAMEDICT;
return ndict;
}
HPDF_NameTree
HPDF_NameDict_GetNameTree (HPDF_NameDict namedict,
HPDF_NameDictKey key)
{
if (!namedict)
return NULL;
return HPDF_Dict_GetItem (namedict, HPDF_NAMEDICT_KEYS[key], HPDF_OCLASS_DICT);
}
HPDF_STATUS
HPDF_NameDict_SetNameTree (HPDF_NameDict namedict,
HPDF_NameDictKey key,
HPDF_NameTree ntree)
{
return HPDF_Dict_Add (namedict, HPDF_NAMEDICT_KEYS[key], ntree);
}
HPDF_BOOL
HPDF_NameDict_Validate (HPDF_NameDict namedict)
{
if (!namedict)
return HPDF_FALSE;
if (namedict->header.obj_class != (HPDF_OSUBCLASS_NAMEDICT |
HPDF_OCLASS_DICT)) {
HPDF_SetError (namedict->error, HPDF_INVALID_OBJECT, 0);
return HPDF_FALSE;
}
return HPDF_TRUE;
}
/*------- NameTree -------*/
HPDF_NameTree
HPDF_NameTree_New (HPDF_MMgr mmgr,
HPDF_Xref xref)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_NameTree ntree;
HPDF_Array items;
HPDF_PTRACE((" HPDF_NameTree_New\n"));
ntree = HPDF_Dict_New (mmgr);
if (!ntree)
return NULL;
if (HPDF_Xref_Add (xref, ntree) != HPDF_OK)
return NULL;
ntree->header.obj_class |= HPDF_OSUBCLASS_NAMETREE;
items = HPDF_Array_New (mmgr);
if (!ntree)
return NULL;
ret += HPDF_Dict_Add (ntree, "Names", items);
if (ret != HPDF_OK)
return NULL;
return ntree;
}
HPDF_STATUS
HPDF_NameTree_Add (HPDF_NameTree tree,
HPDF_String name,
void *obj)
{
HPDF_Array items;
HPDF_INT32 i, icount;
if (!tree || !name)
return HPDF_INVALID_PARAMETER;
items = HPDF_Dict_GetItem (tree, "Names", HPDF_OCLASS_ARRAY);
if (!items)
return HPDF_INVALID_OBJECT;
/* "The keys shall be sorted in lexical order" -- 7.9.6, Name Trees.
* Since we store keys sorted, it's best to do a linear insertion sort
* Find the first element larger than 'key', and insert 'key' and then
* 'obj' into the items. */
icount = HPDF_Array_Items(items);
/* If we're larger than the last element, append */
if (icount) {
HPDF_String last = HPDF_Array_GetItem(items, icount - 2, HPDF_OCLASS_STRING);
if (HPDF_String_Cmp(name, last) > 0) {
HPDF_Array_Add(items, name);
HPDF_Array_Add(items, obj);
return HPDF_OK;
}
}
/* Walk backwards through the list until we're smaller than an element=
* That's the element to insert in front of. */
for (i = icount - 4; i >= 0; i -= 2) {
HPDF_String elem = HPDF_Array_GetItem(items, i, HPDF_OCLASS_STRING);
if (i == 0 || HPDF_String_Cmp(name, elem) < 0) {
HPDF_Array_Insert(items, elem, name);
HPDF_Array_Insert(items, elem, obj);
return HPDF_OK;
}
}
/* Items list is empty */
HPDF_Array_Add(items, name);
HPDF_Array_Add(items, obj);
return HPDF_OK;
}
HPDF_BOOL
HPDF_NameTree_Validate (HPDF_NameTree nametree)
{
if (!nametree)
return HPDF_FALSE;
if (nametree->header.obj_class != (HPDF_OSUBCLASS_NAMETREE |
HPDF_OCLASS_DICT)) {
HPDF_SetError (nametree->error, HPDF_INVALID_OBJECT, 0);
return HPDF_FALSE;
}
return HPDF_TRUE;
}
/*------- EmbeddedFile -------*/
HPDF_EmbeddedFile
HPDF_EmbeddedFile_New (HPDF_MMgr mmgr,
HPDF_Xref xref,
const char *file)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_Dict ef; /* the dictionary for the embedded file: /Type /EF */
HPDF_String name; /* the name of the file: /F (name) */
HPDF_Dict eff; /* ef has an /EF <<blah>> key - this is it */
HPDF_Dict filestream; /* the stream that /EF <</F _ _ R>> refers to */
HPDF_Stream stream;
ef = HPDF_Dict_New (mmgr);
if (!ef)
return NULL;
if (HPDF_Xref_Add (xref, ef) != HPDF_OK)
return NULL;
filestream = HPDF_DictStream_New (mmgr, xref);
if (!filestream)
return NULL;
stream = HPDF_FileReader_New (mmgr, file);
if (!stream)
return NULL;
HPDF_Stream_Free(filestream->stream);
filestream->stream = stream;
filestream->filter = HPDF_STREAM_FILTER_FLATE_DECODE;
eff = HPDF_Dict_New (mmgr);
if (!eff)
return NULL;
name = HPDF_String_New (mmgr, file, NULL);
if (!name)
return NULL;
ret += HPDF_Dict_AddName (ef, "Type", "F");
ret += HPDF_Dict_Add (ef, "F", name);
ret += HPDF_Dict_Add (ef, "EF", eff);
ret += HPDF_Dict_Add (eff, "F", filestream);
if (ret != HPDF_OK)
return NULL;
return ef;
}
HPDF_BOOL
HPDF_EmbeddedFile_Validate (HPDF_EmbeddedFile emfile)
{
HPDF_UNUSED (emfile);
return HPDF_TRUE;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_null.c
* << Haru Free PDF Library >> -- hpdf_null.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_number.c
* << Haru Free PDF Library >> -- hpdf_number.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- HPDF_objects.c
* << Haru Free PDF Library >> -- hpdf_objects.c
*
* Copyright (c) 1999-2004 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_outline.c
* << Haru Free PDF Library >> -- hpdf_outline.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -64,7 +67,7 @@ HPDF_OutlineRoot_New (HPDF_MMgr mmgr,
open_flg->header.obj_id |= HPDF_OTYPE_HIDDEN;
ret += HPDF_Dict_Add (outline, "_OPENED", open_flg);
ret += HPDF_Dict_AddName (outline, "Type", "Outline");
ret += HPDF_Dict_AddName (outline, "Type", "Outlines");
if (ret != HPDF_OK)
return NULL;
@ -114,7 +117,7 @@ HPDF_Outline_New (HPDF_MMgr mmgr,
open_flg->header.obj_id |= HPDF_OTYPE_HIDDEN;
ret += HPDF_Dict_Add (outline, "_OPENED", open_flg);
ret += HPDF_Dict_AddName (outline, "Type", "Outline");
ret += HPDF_Dict_AddName (outline, "Type", "Outlines");
ret += AddChild (parent, outline);
if (ret != HPDF_OK)
@ -232,7 +235,7 @@ BeforeWrite (HPDF_Dict obj)
return HPDF_Dict_RemoveElement (obj, "Count");
if (!HPDF_Outline_GetOpened ((HPDF_Outline)obj))
count *= -1;
count = count * -1;
if (n)
n->value = count;
@ -325,5 +328,3 @@ HPDF_Outline_SetOpened (HPDF_Outline outline,
return HPDF_OK;
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_page_label.c
* << Haru Free PDF Library >> -- hpdf_page_label.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_pages.c
* << Haru Free PDF Library >> -- hpdf_pages.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -17,6 +20,9 @@
#include "hpdf.h"
#include "hpdf_annotation.h"
#include "hpdf_destination.h"
#include "hpdf_3dmeasure.h"
#include "hpdf_exdata.h"
#include "hpdf_u3d.h"
/*----------------------------------------------------------------------------*/
@ -25,14 +31,14 @@ typedef struct _HPDF_PageSizeValue {
HPDF_REAL y;
} HPDF_PageSizeValue;
static HPDF_PageSizeValue HPDF_PREDEFINED_PAGE_SIZES[] = {
static const HPDF_PageSizeValue HPDF_PREDEFINED_PAGE_SIZES[] = {
{612, 792}, /* HPDF_PAGE_SIZE_LETTER */
{612, 1008}, /* HPDF_PAGE_SIZE_LEGAL */
{841.89, 1199.551}, /* HPDF_PAGE_SIZE_A3 */
{595.276, 841.89}, /* HPDF_PAGE_SIZE_A4 */
{419.528, 595.276}, /* HPDF_PAGE_SIZE_A5 */
{708.661, 1000.63}, /* HPDF_PAGE_SIZE_B4 */
{498.898, 708.661}, /* HPDF_PAGE_SIZE_B5 */
{(HPDF_REAL)841.89, (HPDF_REAL)1190.551}, /* HPDF_PAGE_SIZE_A3 */
{(HPDF_REAL)595.276, (HPDF_REAL)841.89}, /* HPDF_PAGE_SIZE_A4 */
{(HPDF_REAL)419.528, (HPDF_REAL)595.276}, /* HPDF_PAGE_SIZE_A5 */
{(HPDF_REAL)708.661, (HPDF_REAL)1000.63}, /* HPDF_PAGE_SIZE_B4 */
{(HPDF_REAL)498.898, (HPDF_REAL)708.661}, /* HPDF_PAGE_SIZE_B5 */
{522, 756}, /* HPDF_PAGE_SIZE_EXECUTIVE */
{288, 432}, /* HPDF_PAGE_SIZE_US4x6 */
{288, 576}, /* HPDF_PAGE_SIZE_US4x8 */
@ -71,7 +77,7 @@ AddAnnotation (HPDF_Page page,
static HPDF_UINT
GetPageCount (HPDF_Dict pages);
static const char *HPDF_INHERITABLE_ENTRIES[5] = {
static const char * const HPDF_INHERITABLE_ENTRIES[5] = {
"Resources",
"MediaBox",
"CropBox",
@ -159,11 +165,14 @@ HPDF_Page_InsertBefore (HPDF_Page page,
HPDF_PTRACE((" HPDF_Page_InsertBefore\n"));
if (!target)
return HPDF_INVALID_PARAMETER;
attr = (HPDF_PageAttr )target->attr;
parent = attr->parent;
if (!parent)
return HPDF_SetError (parent->error, HPDF_PAGE_CANNOT_SET_PARENT, 0);
return HPDF_PAGE_CANNOT_SET_PARENT;
if (HPDF_Dict_GetItem (page, "Parent", HPDF_OCLASS_DICT))
return HPDF_SetError (parent->error, HPDF_PAGE_CANNOT_SET_PARENT, 0);
@ -337,7 +346,7 @@ HPDF_Page_New (HPDF_MMgr mmgr,
/* add requiered elements */
ret += HPDF_Dict_AddName (page, "Type", "Page");
ret += HPDF_Dict_Add (page, "MediaBox", HPDF_Box_Array_New (page->mmgr,
HPDF_ToBox (0, 0, HPDF_DEF_PAGE_WIDTH, HPDF_DEF_PAGE_HEIGHT)));
HPDF_ToBox (0, 0, (HPDF_INT16)(HPDF_DEF_PAGE_WIDTH), (HPDF_INT16)(HPDF_DEF_PAGE_HEIGHT))));
ret += HPDF_Dict_Add (page, "Contents", attr->contents);
ret += AddResource (page);
@ -454,14 +463,19 @@ AddResource (HPDF_Page page)
if (!procset)
return HPDF_Error_GetCode (page->error);
ret += HPDF_Dict_Add (resource, "ProcSet", procset);
if (HPDF_Dict_Add (resource, "ProcSet", procset) != HPDF_OK)
return HPDF_Error_GetCode (resource->error);
ret += HPDF_Array_Add (procset, HPDF_Name_New (page->mmgr, "PDF"));
ret += HPDF_Array_Add (procset, HPDF_Name_New (page->mmgr, "Text"));
ret += HPDF_Array_Add (procset, HPDF_Name_New (page->mmgr, "ImageB"));
ret += HPDF_Array_Add (procset, HPDF_Name_New (page->mmgr, "ImageC"));
ret += HPDF_Array_Add (procset, HPDF_Name_New (page->mmgr, "ImageI"));
return ret;
if (ret != HPDF_OK)
return HPDF_Error_GetCode (procset->error);
return HPDF_OK;
}
@ -507,7 +521,7 @@ HPDF_Page_GetLocalFontName (HPDF_Page page,
char *ptr;
char *end_ptr = fontName + HPDF_LIMIT_MAX_NAME_LEN;
ptr = HPDF_StrCpy (fontName, "F", end_ptr);
ptr = (char *)HPDF_StrCpy (fontName, "F", end_ptr);
HPDF_IToA (ptr, attr->fonts->list->count + 1, end_ptr);
if (HPDF_Dict_Add (attr->fonts, fontName, font) != HPDF_OK)
@ -596,7 +610,7 @@ HPDF_Page_GetXObjectName (HPDF_Page page,
char *ptr;
char *end_ptr = xobj_name + HPDF_LIMIT_MAX_NAME_LEN;
ptr = HPDF_StrCpy (xobj_name, "X", end_ptr);
ptr = (char *)HPDF_StrCpy (xobj_name, "X", end_ptr);
HPDF_IToA (ptr, attr->xobjects->list->count + 1, end_ptr);
if (HPDF_Dict_Add (attr->xobjects, xobj_name, xobj) != HPDF_OK)
@ -647,7 +661,7 @@ HPDF_Page_GetExtGStateName (HPDF_Page page,
char *ptr;
char *end_ptr = ext_gstate_name + HPDF_LIMIT_MAX_NAME_LEN;
ptr = HPDF_StrCpy (ext_gstate_name, "E", end_ptr);
ptr = (char *)HPDF_StrCpy (ext_gstate_name, "E", end_ptr);
HPDF_IToA (ptr, attr->ext_gstates->list->count + 1, end_ptr);
if (HPDF_Dict_Add (attr->ext_gstates, ext_gstate_name, state) != HPDF_OK)
@ -665,7 +679,7 @@ AddAnnotation (HPDF_Page page,
HPDF_Annotation annot)
{
HPDF_Array array;
HPDF_STATUS ret;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_Pages\n"));
@ -681,8 +695,14 @@ AddAnnotation (HPDF_Page page,
if (ret != HPDF_OK)
return ret;
}
if ((ret = HPDF_Array_Add (array, annot)) != HPDF_OK)
return ret;
return HPDF_Array_Add (array, annot);
/* Add Parent to the annotation */
ret = HPDF_Dict_Add( annot, "P", page);
return ret;
}
@ -708,7 +728,7 @@ HPDF_Page_TextWidth (HPDF_Page page,
return 0;
}
tw = HPDF_Font_TextWidth (attr->gstate->font, text, len);
tw = HPDF_Font_TextWidth (attr->gstate->font, (HPDF_BYTE *)text, len);
ret += attr->gstate->word_space * tw.numspace;
ret += tw.width * attr->gstate->font_size / 1000;
@ -744,7 +764,7 @@ HPDF_Page_MeasureText (HPDF_Page page,
return 0;
}
ret = HPDF_Font_MeasureText (attr->gstate->font, text, len, width,
ret = HPDF_Font_MeasureText (attr->gstate->font, (HPDF_BYTE *)text, len, width,
attr->gstate->font_size, attr->gstate->char_space,
attr->gstate->word_space, wordwrap, real_width);
@ -971,7 +991,7 @@ HPDF_Page_GetTextRenderingMode (HPDF_Page page)
HPDF_EXPORT(HPDF_REAL)
HPDF_Page_GetTextRaise (HPDF_Page page)
{
return HPDF_Page_GetTextRise (page);
return HPDF_Page_GetTextRise (page);
}
HPDF_EXPORT(HPDF_REAL)
@ -1259,7 +1279,6 @@ HPDF_Page_SetBoxValue (HPDF_Page page,
return HPDF_OK;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_Page_SetRotate (HPDF_Page page,
HPDF_UINT16 angle)
@ -1286,6 +1305,25 @@ HPDF_Page_SetRotate (HPDF_Page page,
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_Page_SetZoom (HPDF_Page page,
HPDF_REAL zoom)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE((" HPDF_Page_SetZoom\n"));
if (!HPDF_Page_Validate (page)) {
return HPDF_INVALID_PAGE;
}
if (zoom < 0.08 || zoom > 32) {
return HPDF_RaiseError (page->error, HPDF_INVALID_PARAMETER, 0);
}
ret = HPDF_Dict_AddReal (page, "PZ", zoom);
return ret;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_Page_SetWidth (HPDF_Page page,
@ -1394,6 +1432,33 @@ HPDF_Page_CreateDestination (HPDF_Page page)
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_Create3DAnnot (HPDF_Page page,
HPDF_Rect rect,
HPDF_U3D u3d)
{
HPDF_PageAttr attr;
HPDF_Annotation annot;
HPDF_PTRACE((" HPDF_Page_Create3DAnnot\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
annot = HPDF_3DAnnot_New (page->mmgr, attr->xref, rect, u3d);
if (annot) {
if (AddAnnotation (page, annot) != HPDF_OK) {
HPDF_CheckError (page->error);
annot = NULL;
}
} else
HPDF_CheckError (page->error);
return annot;
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateTextAnnot (HPDF_Page page,
HPDF_Rect rect,
@ -1415,7 +1480,7 @@ HPDF_Page_CreateTextAnnot (HPDF_Page page,
return NULL;
}
annot = HPDF_TextAnnot_New (page->mmgr, attr->xref, rect, text, encoder);
annot = HPDF_MarkupAnnot_New (page->mmgr, attr->xref, rect, text, encoder, HPDF_ANNOT_TEXT_NOTES);
if (annot) {
if (AddAnnotation (page, annot) != HPDF_OK) {
HPDF_CheckError (page->error);
@ -1427,6 +1492,71 @@ HPDF_Page_CreateTextAnnot (HPDF_Page page,
return annot;
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateFreeTextAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder)
{
HPDF_PageAttr attr;
HPDF_Annotation annot;
HPDF_PTRACE((" HPDF_Page_CreateFreeTextAnnot\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
if (encoder && !HPDF_Encoder_Validate (encoder)) {
HPDF_RaiseError (page->error, HPDF_INVALID_ENCODER, 0);
return NULL;
}
annot = HPDF_MarkupAnnot_New (page->mmgr, attr->xref, rect, text, encoder, HPDF_ANNOT_FREE_TEXT);
if (annot) {
if (AddAnnotation (page, annot) != HPDF_OK) {
HPDF_CheckError (page->error);
annot = NULL;
}
} else
HPDF_CheckError (page->error);
return annot;
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateLineAnnot (HPDF_Page page,
const char *text,
HPDF_Encoder encoder)
{
HPDF_PageAttr attr;
HPDF_Annotation annot;
HPDF_Rect rect = {0,0,0,0};
HPDF_PTRACE((" HPDF_Page_CreateLineAnnot\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
if (encoder && !HPDF_Encoder_Validate (encoder)) {
HPDF_RaiseError (page->error, HPDF_INVALID_ENCODER, 0);
return NULL;
}
annot = HPDF_MarkupAnnot_New (page->mmgr, attr->xref, rect, text, encoder, HPDF_ANNOT_LINE);
if (annot) {
if (AddAnnotation (page, annot) != HPDF_OK) {
HPDF_CheckError (page->error);
annot = NULL;
}
} else
HPDF_CheckError (page->error);
return annot;
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateLinkAnnot (HPDF_Page page,
@ -1493,6 +1623,343 @@ HPDF_Page_CreateURILinkAnnot (HPDF_Page page,
return annot;
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateCircleAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder)
{
HPDF_PageAttr attr;
HPDF_Annotation annot;
HPDF_PTRACE((" HPDF_Page_CreateCircleAnnot\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
if (encoder && !HPDF_Encoder_Validate (encoder)) {
HPDF_RaiseError (page->error, HPDF_INVALID_ENCODER, 0);
return NULL;
}
annot = HPDF_MarkupAnnot_New (page->mmgr, attr->xref, rect, text, encoder, HPDF_ANNOT_CIRCLE);
if (annot) {
if (AddAnnotation (page, annot) != HPDF_OK) {
HPDF_CheckError (page->error);
annot = NULL;
}
} else
HPDF_CheckError (page->error);
return annot;
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateSquareAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder)
{
HPDF_PageAttr attr;
HPDF_Annotation annot;
HPDF_PTRACE((" HPDF_Page_CreateCircleAnnot\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
if (encoder && !HPDF_Encoder_Validate (encoder)) {
HPDF_RaiseError (page->error, HPDF_INVALID_ENCODER, 0);
return NULL;
}
annot = HPDF_MarkupAnnot_New (page->mmgr, attr->xref, rect, text, encoder, HPDF_ANNOT_SQUARE);
if (annot) {
if (AddAnnotation (page, annot) != HPDF_OK) {
HPDF_CheckError (page->error);
annot = NULL;
}
} else
HPDF_CheckError (page->error);
return annot;
}
HPDF_EXPORT(HPDF_Dict)
HPDF_Page_Create3DView (HPDF_Page page,
HPDF_U3D u3d,
HPDF_Annotation annot3d,
const char *name)
{
HPDF_PageAttr attr;
HPDF_Dict view;
HPDF_PTRACE((" HPDF_Page_Create3DView\n"));
HPDF_UNUSED(annot3d);
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
view = HPDF_3DView_New( page->mmgr, attr->xref, u3d, name);
if (!view) {
HPDF_CheckError (page->error);
}
return view;
}
HPDF_Annotation
HPDF_Page_CreateTextMarkupAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder,
HPDF_AnnotType subType)
{
HPDF_PageAttr attr;
HPDF_Annotation annot;
HPDF_PTRACE((" HPDF_Page_CreateTextMarkupAnnot\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
if (encoder && !HPDF_Encoder_Validate (encoder)) {
HPDF_RaiseError (page->error, HPDF_INVALID_ENCODER, 0);
return NULL;
}
annot = HPDF_MarkupAnnot_New ( page->mmgr, attr->xref, rect, text, encoder, subType);
if (annot) {
if (AddAnnotation (page, annot) != HPDF_OK) {
HPDF_CheckError (page->error);
annot = NULL;
}
} else
HPDF_CheckError (page->error);
return annot;
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateHighlightAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder)
{
HPDF_PTRACE((" HPDF_Page_CreateHighlightAnnot\n"));
return HPDF_Page_CreateTextMarkupAnnot( page, rect, text, encoder, HPDF_ANNOT_HIGHTLIGHT);
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateSquigglyAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder)
{
HPDF_PTRACE((" HPDF_Page_CreateSquigglyAnnot\n"));
return HPDF_Page_CreateTextMarkupAnnot( page, rect, text, encoder, HPDF_ANNOT_SQUIGGLY);
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateUnderlineAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder)
{
HPDF_PTRACE((" HPDF_Page_CreateUnderlineAnnot\n"));
return HPDF_Page_CreateTextMarkupAnnot( page, rect, text, encoder, HPDF_ANNOT_UNDERLINE);
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateStrikeOutAnnot (HPDF_Page page,
HPDF_Rect rect,
const char *text,
HPDF_Encoder encoder)
{
HPDF_PTRACE((" HPDF_Page_CreateStrikeOutAnnot\n"));
return HPDF_Page_CreateTextMarkupAnnot( page, rect, text, encoder, HPDF_ANNOT_STRIKE_OUT);
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreatePopupAnnot ( HPDF_Page page,
HPDF_Rect rect,
HPDF_Annotation parent)
{
HPDF_PageAttr attr;
HPDF_Annotation annot;
HPDF_PTRACE((" HPDF_Page_CreatePopupAnnot\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
annot = HPDF_PopupAnnot_New ( page->mmgr, attr->xref, rect, parent);
if (annot) {
if (AddAnnotation (page, annot) != HPDF_OK) {
HPDF_CheckError (page->error);
annot = NULL;
}
} else
HPDF_CheckError (page->error);
return annot;
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateStampAnnot ( HPDF_Page page,
HPDF_Rect rect,
HPDF_StampAnnotName name,
const char* text,
HPDF_Encoder encoder)
{
HPDF_PageAttr attr;
HPDF_Annotation annot;
HPDF_PTRACE((" HPDF_Page_CreateStampAnnot\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
annot = HPDF_StampAnnot_New ( page->mmgr, attr->xref, rect, name, text, encoder);
if (annot) {
if (AddAnnotation (page, annot) != HPDF_OK) {
HPDF_CheckError (page->error);
annot = NULL;
}
} else
HPDF_CheckError (page->error);
return annot;
}
HPDF_EXPORT(HPDF_Annotation)
HPDF_Page_CreateProjectionAnnot(HPDF_Page page,
HPDF_Rect rect,
const char* text,
HPDF_Encoder encoder)
{
HPDF_PageAttr attr;
HPDF_Annotation annot;
HPDF_PTRACE((" HPDF_Page_CreateProjectionAnnot\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
annot = HPDF_ProjectionAnnot_New (page->mmgr, attr->xref, rect, text, encoder);
if (annot) {
if (AddAnnotation (page, annot) != HPDF_OK) {
HPDF_CheckError (page->error);
annot = NULL;
}
} else
HPDF_CheckError (page->error);
return annot;
}
HPDF_EXPORT(HPDF_3DMeasure)
HPDF_Page_Create3DC3DMeasure(HPDF_Page page,
HPDF_Point3D firstanchorpoint,
HPDF_Point3D textanchorpoint)
{
HPDF_PageAttr attr;
HPDF_Annotation measure;
HPDF_PTRACE((" HPDF_Page_Create3DC3DMeasure\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
measure = HPDF_3DC3DMeasure_New(page->mmgr, attr->xref, firstanchorpoint, textanchorpoint);
if ( !measure)
HPDF_CheckError (page->error);
return measure;
}
HPDF_EXPORT(HPDF_3DMeasure)
HPDF_Page_CreatePD33DMeasure(HPDF_Page page,
HPDF_Point3D annotationPlaneNormal,
HPDF_Point3D firstAnchorPoint,
HPDF_Point3D secondAnchorPoint,
HPDF_Point3D leaderLinesDirection,
HPDF_Point3D measurementValuePoint,
HPDF_Point3D textYDirection,
HPDF_REAL value,
const char* unitsString
)
{
HPDF_PageAttr attr;
HPDF_Annotation measure;
HPDF_PTRACE((" HPDF_Page_CreatePD33DMeasure\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
measure = HPDF_PD33DMeasure_New(page->mmgr,
attr->xref,
annotationPlaneNormal,
firstAnchorPoint,
secondAnchorPoint,
leaderLinesDirection,
measurementValuePoint,
textYDirection,
value,
unitsString
);
if ( !measure)
HPDF_CheckError (page->error);
return measure;
}
HPDF_EXPORT(HPDF_ExData)
HPDF_Page_Create3DAnnotExData(HPDF_Page page)
{
HPDF_PageAttr attr;
HPDF_Annotation exData;
HPDF_PTRACE((" HPDF_Page_Create3DAnnotExData\n"));
if (!HPDF_Page_Validate (page))
return NULL;
attr = (HPDF_PageAttr)page->attr;
exData = HPDF_3DAnnotExData_New(page->mmgr, attr->xref);
if ( !exData)
HPDF_CheckError (page->error);
return exData;
}
void
HPDF_Page_SetFilter (HPDF_Page page,

386
PDF/src/hpdf_pdfa.c Normal file
View File

@ -0,0 +1,386 @@
/*
* << Haru Free PDF Library >> -- hpdf_pdfa.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* 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.
*
*/
/* This is used to avoid warnings on 'ctime' when compiling in MSVC 9 */
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <time.h>
#include "hpdf_utils.h"
#include "hpdf.h"
#include <string.h>
#define HEADER "<?xpacket begin='' id='W5M0MpCehiHzreSzNTczkc9d'?><x:xmpmeta xmlns:x='adobe:ns:meta/' x:xmptk='XMP toolkit 2.9.1-13, framework 1.6'><rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#' xmlns:iX='http://ns.adobe.com/iX/1.0/'>"
#define DC_HEADER "<rdf:Description xmlns:dc='http://purl.org/dc/elements/1.1/' rdf:about=''>"
#define DC_TITLE_STARTTAG "<dc:title><rdf:Alt><rdf:li xml:lang=\"x-default\">"
#define DC_TITLE_ENDTAG "</rdf:li></rdf:Alt></dc:title>"
#define DC_CREATOR_STARTTAG "<dc:creator><rdf:Seq><rdf:li>"
#define DC_CREATOR_ENDTAG "</rdf:li></rdf:Seq></dc:creator>"
#define DC_DESCRIPTION_STARTTAG "<dc:description><rdf:Alt><rdf:li xml:lang=\"x-default\">"
#define DC_DESCRIPTION_ENDTAG "</rdf:li></rdf:Alt></dc:description>"
#define DC_FOOTER "</rdf:Description>"
#define XMP_HEADER "<rdf:Description xmlns:xmp='http://ns.adobe.com/xap/1.0/' rdf:about=''>"
#define XMP_CREATORTOOL_STARTTAG "<xmp:CreatorTool>"
#define XMP_CREATORTOOL_ENDTAG "</xmp:CreatorTool>"
#define XMP_CREATE_DATE_STARTTAG "<xmp:CreateDate>"
#define XMP_CREATE_DATE_ENDTAG "</xmp:CreateDate>"
#define XMP_MOD_DATE_STARTTAG "<xmp:ModifyDate>"
#define XMP_MOD_DATE_ENDTAG "</xmp:ModifyDate>"
#define XMP_FOOTER "</rdf:Description>"
#define PDF_HEADER "<rdf:Description xmlns:pdf='http://ns.adobe.com/pdf/1.3/' rdf:about=''>"
#define PDF_KEYWORDS_STARTTAG "<pdf:Keywords>"
#define PDF_KEYWORDS_ENDTAG "</pdf:Keywords>"
#define PDF_PRODUCER_STARTTAG "<pdf:Producer>"
#define PDF_PRODUCER_ENDTAG "</pdf:Producer>"
#define PDF_FOOTER "</rdf:Description>"
#define PDFAID_PDFA1A "<rdf:Description rdf:about='' xmlns:pdfaid='http://www.aiim.org/pdfa/ns/id/' pdfaid:part='1' pdfaid:conformance='A'/>"
#define PDFAID_PDFA1B "<rdf:Description rdf:about='' xmlns:pdfaid='http://www.aiim.org/pdfa/ns/id/' pdfaid:part='1' pdfaid:conformance='B'/>"
#define FOOTER "</rdf:RDF></x:xmpmeta><?xpacket end='w'?>"
/*
* Convert date in PDF specific format: D:YYYYMMDDHHmmSS
* to XMP value in format YYYY-MM-DDTHH:mm:SS+offH:offMin
*/
HPDF_STATUS ConvertDateToXMDate(HPDF_Stream stream, const char *pDate)
{
HPDF_STATUS ret;
if(pDate==NULL) return HPDF_INVALID_PARAMETER;
if(strlen(pDate)<16) return HPDF_INVALID_PARAMETER;
if(pDate[0]!='D'||
pDate[1]!=':') return HPDF_INVALID_PARAMETER;
pDate+=2;
/* Copy YYYY */
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 4);
if (ret != HPDF_OK)
return ret;
pDate+=4;
/* Write -MM */
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)"-", 1);
if (ret != HPDF_OK)
return ret;
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2);
if (ret != HPDF_OK)
return ret;
pDate+=2;
/* Write -DD */
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)"-", 1);
if (ret != HPDF_OK)
return ret;
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2);
if (ret != HPDF_OK)
return ret;
pDate+=2;
/* Write THH */
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)"T", 1);
if (ret != HPDF_OK)
return ret;
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2);
if (ret != HPDF_OK)
return ret;
pDate+=2;
/* Write :mm */
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)":", 1);
if (ret != HPDF_OK)
return ret;
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2);
if (ret != HPDF_OK)
return ret;
pDate+=2;
/* Write :SS */
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)":", 1);
if (ret != HPDF_OK)
return ret;
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2);
if (ret != HPDF_OK)
return ret;
pDate+=2;
/* Write +... */
if(pDate[0]==0) {
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)"Z", 1);
return ret;
}
if(pDate[0]=='+'||pDate[0]=='-') {
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 3);
if (ret != HPDF_OK)
return ret;
pDate+=4;
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)":", 1);
if (ret != HPDF_OK)
return ret;
ret = HPDF_Stream_Write(stream, (const HPDF_BYTE*)pDate, 2);
if (ret != HPDF_OK)
return ret;
return ret;
}
return HPDF_SetError (stream->error, HPDF_INVALID_PARAMETER, 0);
}
/* Write XMP Metadata for PDF/A */
HPDF_STATUS
HPDF_PDFA_SetPDFAConformance (HPDF_Doc pdf,HPDF_PDFAType pdfatype)
{
HPDF_OutputIntent xmp;
HPDF_STATUS ret;
const char *dc_title = NULL;
const char *dc_creator = NULL;
const char *dc_description = NULL;
const char *xmp_CreatorTool = NULL;
const char *xmp_CreateDate = NULL;
const char *xmp_ModifyDate = NULL;
const char *pdf_Keywords = NULL;
const char *pdf_Producer = NULL;
const char *info = NULL;
if (!HPDF_HasDoc(pdf)) {
return HPDF_INVALID_DOCUMENT;
}
dc_title = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_TITLE);
dc_creator = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_AUTHOR);
dc_description = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_SUBJECT);
xmp_CreateDate = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_CREATION_DATE);
xmp_ModifyDate = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_MOD_DATE);
xmp_CreatorTool = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_CREATOR);
pdf_Keywords = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_KEYWORDS);
pdf_Producer = (const char *)HPDF_GetInfoAttr(pdf, HPDF_INFO_PRODUCER);
if((dc_title != NULL) || (dc_creator != NULL) || (dc_description != NULL)
|| (xmp_CreateDate != NULL) || (xmp_ModifyDate != NULL) || (xmp_CreatorTool != NULL)
|| (pdf_Keywords != NULL)) {
xmp = HPDF_DictStream_New(pdf->mmgr,pdf->xref);
if (!xmp) {
return HPDF_INVALID_STREAM;
}
/* Update the PDF number version */
pdf->pdf_version = HPDF_VER_14;
HPDF_Dict_AddName(xmp,"Type","Metadata");
HPDF_Dict_AddName(xmp,"SubType","XML");
ret = HPDF_OK;
ret += HPDF_Stream_WriteStr(xmp->stream, HEADER);
/* Add the dc block */
if((dc_title != NULL) || (dc_creator != NULL) || (dc_description != NULL)) {
ret += HPDF_Stream_WriteStr(xmp->stream, DC_HEADER);
if(dc_title != NULL) {
ret += HPDF_Stream_WriteStr(xmp->stream, DC_TITLE_STARTTAG);
ret += HPDF_Stream_WriteStr(xmp->stream, dc_title);
ret += HPDF_Stream_WriteStr(xmp->stream, DC_TITLE_ENDTAG);
}
if(dc_creator != NULL) {
ret += HPDF_Stream_WriteStr(xmp->stream, DC_CREATOR_STARTTAG);
ret += HPDF_Stream_WriteStr(xmp->stream, dc_creator);
ret += HPDF_Stream_WriteStr(xmp->stream, DC_CREATOR_ENDTAG);
}
if(dc_description != NULL) {
ret += HPDF_Stream_WriteStr(xmp->stream, DC_DESCRIPTION_STARTTAG);
ret += HPDF_Stream_WriteStr(xmp->stream, dc_description);
ret += HPDF_Stream_WriteStr(xmp->stream, DC_DESCRIPTION_ENDTAG);
}
ret += HPDF_Stream_WriteStr(xmp->stream, DC_FOOTER);
}
/* Add the xmp block */
if((xmp_CreateDate != NULL) || (xmp_ModifyDate != NULL) || (xmp_CreatorTool != NULL)) {
ret += HPDF_Stream_WriteStr(xmp->stream, XMP_HEADER);
/* Add CreateDate, ModifyDate, and CreatorTool */
if(xmp_CreatorTool != NULL) {
ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATORTOOL_STARTTAG);
ret += HPDF_Stream_WriteStr(xmp->stream, xmp_CreatorTool);
ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATORTOOL_ENDTAG);
}
if(xmp_CreateDate != NULL) {
ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATE_DATE_STARTTAG);
/* Convert date to XMP compatible format */
ret += ConvertDateToXMDate(xmp->stream, xmp_CreateDate);
ret += HPDF_Stream_WriteStr(xmp->stream, XMP_CREATE_DATE_ENDTAG);
}
if(xmp_ModifyDate != NULL) {
ret += HPDF_Stream_WriteStr(xmp->stream, XMP_MOD_DATE_STARTTAG);
ret += ConvertDateToXMDate(xmp->stream, xmp_ModifyDate);
ret += HPDF_Stream_WriteStr(xmp->stream, XMP_MOD_DATE_ENDTAG);
}
ret += HPDF_Stream_WriteStr(xmp->stream, XMP_FOOTER);
}
/* Add the pdf block */
if((pdf_Keywords != NULL) || (pdf_Producer != NULL)) {
ret += HPDF_Stream_WriteStr(xmp->stream, PDF_HEADER);
if(pdf_Keywords != NULL) {
ret += HPDF_Stream_WriteStr(xmp->stream, PDF_KEYWORDS_STARTTAG);
ret += HPDF_Stream_WriteStr(xmp->stream, pdf_Keywords);
ret += HPDF_Stream_WriteStr(xmp->stream, PDF_KEYWORDS_ENDTAG);
}
if(pdf_Producer != NULL) {
ret += HPDF_Stream_WriteStr(xmp->stream, PDF_PRODUCER_STARTTAG);
ret += HPDF_Stream_WriteStr(xmp->stream, pdf_Producer);
ret += HPDF_Stream_WriteStr(xmp->stream, PDF_PRODUCER_ENDTAG);
}
ret += HPDF_Stream_WriteStr(xmp->stream, PDF_FOOTER);
}
/* Add the pdfaid block */
switch(pdfatype) {
case HPDF_PDFA_1A:
ret += HPDF_Stream_WriteStr(xmp->stream, PDFAID_PDFA1A);
break;
case HPDF_PDFA_1B:
ret += HPDF_Stream_WriteStr(xmp->stream, PDFAID_PDFA1B);
break;
}
ret += HPDF_Stream_WriteStr(xmp->stream, FOOTER);
if (ret != HPDF_OK) {
return HPDF_INVALID_STREAM;
}
if ((ret = HPDF_Dict_Add(pdf->catalog, "Metadata", xmp)) != HPDF_OK) {
return ret;
}
return HPDF_PDFA_GenerateID(pdf);
}
return HPDF_OK;
}
/* Generate an ID for the trailer dict, PDF/A needs this.
TODO: Better algorithm for generate unique ID.
*/
HPDF_STATUS
HPDF_PDFA_GenerateID(HPDF_Doc pdf)
{
HPDF_Array id;
HPDF_BYTE *currentTime;
HPDF_BYTE idkey[HPDF_MD5_KEY_LEN];
HPDF_MD5_CTX md5_ctx;
time_t ltime;
ltime = time(NULL);
currentTime = (HPDF_BYTE *)ctime(&ltime);
id = HPDF_Dict_GetItem(pdf->trailer, "ID", HPDF_OCLASS_ARRAY);
if (!id) {
id = HPDF_Array_New(pdf->mmgr);
if (!id || HPDF_Dict_Add(pdf->trailer, "ID", id) != HPDF_OK)
return pdf->error.error_no;
HPDF_MD5Init(&md5_ctx);
HPDF_MD5Update(&md5_ctx, (HPDF_BYTE *) "libHaru", sizeof("libHaru") - 1);
HPDF_MD5Update(&md5_ctx, currentTime, HPDF_StrLen((const char *)currentTime, -1));
HPDF_MD5Final(idkey, &md5_ctx);
if (HPDF_Array_Add (id, HPDF_Binary_New (pdf->mmgr, idkey, HPDF_MD5_KEY_LEN)) != HPDF_OK)
return pdf->error.error_no;
if (HPDF_Array_Add (id, HPDF_Binary_New (pdf->mmgr,idkey,HPDF_MD5_KEY_LEN)) != HPDF_OK)
return pdf->error.error_no;
return HPDF_OK;
}
return HPDF_OK;
}
/* Function to add one outputintents to the PDF
* iccname - name of default ICC profile
* iccdict - dictionary containing number of components
* and stream with ICC profile
*
* How to use:
* 1. Create dictionary with ICC profile
* HPDF_Dict icc = HPDF_DictStream_New (pDoc->mmgr, pDoc->xref);
* if(icc==NULL) return false;
* HPDF_Dict_AddNumber (icc, "N", 3);
* HPDF_STATUS ret = HPDF_Stream_Write (icc->stream, (const HPDF_BYTE *)pICCData, dwICCSize);
* if(ret!=HPDF_OK) {
* HPDF_Dict_Free(icc);
* return false;
* }
*
* 2. Call this function
*/
HPDF_STATUS
HPDF_PDFA_AppendOutputIntents(HPDF_Doc pdf, const char *iccname, HPDF_Dict iccdict)
{
HPDF_Array intents;
HPDF_Dict intent;
HPDF_STATUS ret;
if (!HPDF_HasDoc (pdf))
return HPDF_INVALID_DOCUMENT;
/* prepare intent */
intent = HPDF_Dict_New (pdf->mmgr);
ret = HPDF_Xref_Add (pdf->xref, intent);
if ( ret != HPDF_OK) {
HPDF_Dict_Free(intent);
return ret;
}
ret += HPDF_Dict_AddName (intent, "Type", "OutputIntent");
ret += HPDF_Dict_AddName (intent, "S", "GTS_PDFA1");
ret += HPDF_Dict_Add (intent, "OutputConditionIdentifier", HPDF_String_New (pdf->mmgr, iccname, NULL));
ret += HPDF_Dict_Add (intent, "OutputCondition", HPDF_String_New (pdf->mmgr, iccname,NULL));
ret += HPDF_Dict_Add (intent, "Info", HPDF_String_New (pdf->mmgr, iccname, NULL));
ret += HPDF_Dict_Add (intent, "DestOutputProfile ", iccdict);
if ( ret != HPDF_OK) {
HPDF_Dict_Free(intent);
return ret;
}
/* Copied from HPDF_AddIntent - not public function */
intents = HPDF_Dict_GetItem (pdf->catalog, "OutputIntents", HPDF_OCLASS_ARRAY);
if (intents == NULL) {
intents = HPDF_Array_New (pdf->mmgr);
if (intents) {
HPDF_STATUS ret = HPDF_Dict_Add (pdf->catalog, "OutputIntents", intents);
if (ret != HPDF_OK) {
HPDF_CheckError (&pdf->error);
return HPDF_Error_GetDetailCode (&pdf->error);
}
}
}
HPDF_Array_Add(intents,intent);
return HPDF_Error_GetDetailCode (&pdf->error);
}

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_real.c
* << Haru Free PDF Library >> -- hpdf_real.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_streams.h
* << Haru Free PDF Library >> -- hpdf_streams.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -10,22 +13,28 @@
* in supporting documentation.
* It is provided "as is" without express or implied warranty.
*
* 2005.12.20 Created.
*
*/
#ifndef _CRT_SECURE_NO_WARNINGS
#define _CRT_SECURE_NO_WARNINGS
#endif
#ifndef UNDER_CE
#include <errno.h>
#ifndef HPDF_NOZLIB
#include <zlib.h>
#include <zconf.h>
#endif /* HPDF_NOZLIB */
#endif
#ifndef HPDF_UNUSED
#define HPDF_UNUSED(a) ((void)(a))
#endif
#include "hpdf_conf.h"
#include "hpdf_consts.h"
#include "hpdf_utils.h"
#include "hpdf_streams.h"
#ifndef LIBHPDF_HAVE_NOZLIB
#include <zlib.h>
#include <zconf.h>
#endif /* LIBHPDF_HAVE_NOZLIB */
HPDF_STATUS
HPDF_MemStream_WriteFunc (HPDF_Stream stream,
const HPDF_BYTE *ptr,
@ -147,7 +156,10 @@ HPDF_Stream_ReadLn (HPDF_Stream stream,
HPDF_PTRACE((" HPDF_Stream_ReadLn\n"));
if (!stream || !s || *size == 0)
if (!stream)
return HPDF_INVALID_PARAMETER;
if (!s || *size == 0)
return HPDF_SetError (stream->error, HPDF_INVALID_PARAMETER, 0);
if (!(stream->seek_fn) || !(stream->read_fn))
@ -160,7 +172,7 @@ HPDF_Stream_ReadLn (HPDF_Stream stream,
while (r_size > 1) {
char *pbuf = buf;
HPDF_STATUS ret = HPDF_Stream_Read (stream, buf, &read_size);
HPDF_STATUS ret = HPDF_Stream_Read (stream, (HPDF_BYTE *)buf, &read_size);
if (ret != HPDF_OK && read_size == 0)
return ret;
@ -250,7 +262,7 @@ HPDF_STATUS
HPDF_Stream_WriteChar (HPDF_Stream stream,
char value)
{
return HPDF_Stream_Write(stream, &value, sizeof(char));
return HPDF_Stream_Write(stream, (HPDF_BYTE *)&value, sizeof(char));
}
@ -260,7 +272,7 @@ HPDF_Stream_WriteStr (HPDF_Stream stream,
{
HPDF_UINT len = HPDF_StrLen(value, -1);
return HPDF_Stream_Write(stream, value, len);
return HPDF_Stream_Write(stream, (HPDF_BYTE *)value, len);
}
HPDF_STATUS
@ -278,7 +290,7 @@ HPDF_Stream_WriteInt (HPDF_Stream stream,
char* p = HPDF_IToA(buf, value, buf + HPDF_INT_LEN);
return HPDF_Stream_Write(stream, buf, (HPDF_UINT)(p - buf));
return HPDF_Stream_Write(stream, (HPDF_BYTE *)buf, (HPDF_UINT)(p - buf));
}
HPDF_STATUS
@ -296,7 +308,7 @@ HPDF_Stream_WriteReal (HPDF_Stream stream,
char* p = HPDF_FToA(buf, value, buf + HPDF_REAL_LEN);
return HPDF_Stream_Write(stream, buf, (HPDF_UINT)(p - buf));
return HPDF_Stream_Write(stream, (HPDF_BYTE *)buf, (HPDF_UINT)(p - buf));
}
void
@ -404,7 +416,7 @@ HPDF_Stream_WriteEscapeName (HPDF_Stream stream,
}
*pos2 = 0;
return HPDF_Stream_Write (stream, tmp_char, HPDF_StrLen(tmp_char, -1));
return HPDF_Stream_Write (stream, (HPDF_BYTE *)tmp_char, HPDF_StrLen(tmp_char, -1));
}
HPDF_STATUS
@ -420,23 +432,29 @@ HPDF_Stream_WriteEscapeText2 (HPDF_Stream stream,
HPDF_PTRACE((" HPDF_Stream_WriteEscapeText2\n"));
/* The following block is commented out because it violates "PDF Spec 7.3.4.2 Literal Strings".
* It states that the two matching parentheses must still be present to represent an empty
* string of zero length.
*/
/*
if (!len)
return HPDF_OK;
*/
buf[idx++] = '(';
for (i = 0; i < len; i++) {
for (i = 0; i < (HPDF_INT)len; i++) {
HPDF_BYTE c = (HPDF_BYTE)*p++;
if (HPDF_NEEDS_ESCAPE(c)) {
buf[idx++] = '\\';
buf[idx] = c >> 6;
buf[idx] = (char)(c >> 6);
buf[idx] += 0x30;
idx++;
buf[idx] = (c & 0x38) >> 3;
buf[idx] = (char)((c & 0x38) >> 3);
buf[idx] += 0x30;
idx++;
buf[idx] = (c & 0x07);
buf[idx] = (char)(c & 0x07);
buf[idx] += 0x30;
idx++;
}
@ -444,7 +462,7 @@ HPDF_Stream_WriteEscapeText2 (HPDF_Stream stream,
buf[idx++] = c;
if (idx > HPDF_TEXT_DEFAULT_LEN - 4) {
ret = HPDF_Stream_Write (stream, buf, idx);
ret = HPDF_Stream_Write (stream, (HPDF_BYTE *)buf, idx);
if (ret != HPDF_OK)
return ret;
idx = 0;
@ -452,7 +470,7 @@ HPDF_Stream_WriteEscapeText2 (HPDF_Stream stream,
}
buf[idx++] = ')';
ret = HPDF_Stream_Write (stream, buf, idx);
ret = HPDF_Stream_Write (stream, (HPDF_BYTE *)buf, idx);
return ret;
}
@ -502,7 +520,7 @@ HPDF_Stream_WriteBinary (HPDF_Stream stream,
}
for (i = 0; i < len; i++, p++) {
char c = *p >> 4;
char c = (char)(*p >> 4);
if (c <= 9)
c += 0x30;
@ -510,7 +528,7 @@ HPDF_Stream_WriteBinary (HPDF_Stream stream,
c += 0x41 - 10;
buf[idx++] = c;
c = *p & 0x0f;
c = (char)(*p & 0x0f);
if (c <= 9)
c += 0x30;
else
@ -518,7 +536,7 @@ HPDF_Stream_WriteBinary (HPDF_Stream stream,
buf[idx++] = c;
if (idx > HPDF_TEXT_DEFAULT_LEN - 2) {
ret = HPDF_Stream_Write (stream, buf, idx);
ret = HPDF_Stream_Write (stream, (HPDF_BYTE *)buf, idx);
if (ret != HPDF_OK) {
if (flg)
HPDF_FreeMem (stream->mmgr, pbuf);
@ -529,7 +547,7 @@ HPDF_Stream_WriteBinary (HPDF_Stream stream,
}
if (idx > 0) {
ret = HPDF_Stream_Write (stream, buf, idx);
ret = HPDF_Stream_Write (stream, (HPDF_BYTE *)buf, idx);
}
if (flg)
@ -544,7 +562,7 @@ HPDF_Stream_WriteToStreamWithDeflate (HPDF_Stream src,
HPDF_Stream dst,
HPDF_Encrypt e)
{
#ifndef HPDF_NOZLIB
#ifndef LIBHPDF_HAVE_NOZLIB
#define DEFLATE_BUF_SIZ ((HPDF_INT)(HPDF_STREAM_BUF_SIZ * 1.1) + 13)
@ -658,9 +676,12 @@ HPDF_Stream_WriteToStreamWithDeflate (HPDF_Stream src,
deflateEnd(&strm);
return HPDF_OK;
#else /* HPDF_NOZLIB */
#else /* LIBHPDF_HAVE_NOZLIB */
HPDF_UNUSED (e);
HPDF_UNUSED (dst);
HPDF_UNUSED (src);
return HPDF_UNSUPPORTED_FUNC;
#endif /* HPDF_NOZLIB */
#endif /* LIBHPDF_HAVE_NOZLIB */
}
HPDF_STATUS
@ -675,6 +696,7 @@ HPDF_Stream_WriteToStream (HPDF_Stream src,
HPDF_BOOL flg;
HPDF_PTRACE((" HPDF_Stream_WriteToStream\n"));
HPDF_UNUSED (filter);
if (!dst || !(dst->write_fn)) {
HPDF_SetError (src->error, HPDF_INVALID_OBJECT, 0);
@ -685,15 +707,15 @@ HPDF_Stream_WriteToStream (HPDF_Stream src,
HPDF_Error_GetCode (dst->error) != HPDF_NOERROR)
return HPDF_THIS_FUNC_WAS_SKIPPED;
#ifndef HPDF_NOZLIB
if (filter & HPDF_STREAM_FILTER_FLATE_DECODE)
return HPDF_Stream_WriteToStreamWithDeflate (src, dst, e);
#endif /* HPDF_NOZLIB */
/* initialize input stream */
if (HPDF_Stream_Size (src) == 0)
return HPDF_OK;
#ifndef LIBHPDF_HAVE_NOZLIB
if (filter & HPDF_STREAM_FILTER_FLATE_DECODE)
return HPDF_Stream_WriteToStreamWithDeflate (src, dst, e);
#endif /* LIBHPDF_HAVE_NOZLIB */
ret = HPDF_Stream_Seek (src, 0, HPDF_SEEK_SET);
if (ret != HPDF_OK)
return ret;
@ -741,7 +763,11 @@ HPDF_FileReader_New (HPDF_MMgr mmgr,
HPDF_PTRACE((" HPDF_FileReader_New\n"));
if (!fp) {
#ifdef UNDER_CE
HPDF_SetError (mmgr->error, HPDF_FILE_OPEN_ERROR, GetLastError());
#else
HPDF_SetError (mmgr->error, HPDF_FILE_OPEN_ERROR, errno);
#endif
return NULL;
}
@ -913,7 +939,11 @@ HPDF_FileWriter_New (HPDF_MMgr mmgr,
HPDF_PTRACE((" HPDF_FileWriter_New\n"));
if (!fp) {
#ifdef UNDER_CE
HPDF_SetError (mmgr->error, HPDF_FILE_OPEN_ERROR, GetLastError());
#else
HPDF_SetError (mmgr->error, HPDF_FILE_OPEN_ERROR, errno);
#endif
return NULL;
}
@ -1071,8 +1101,13 @@ HPDF_MemStream_SeekFunc (HPDF_Stream stream,
} else if (mode == HPDF_SEEK_END)
pos = stream->size - pos;
if (pos > stream->size || stream->size == 0)
if (pos > (HPDF_INT)stream->size) {
return HPDF_SetError (stream->error, HPDF_STREAM_EOF, 0);
}
if (stream->size == 0) {
return HPDF_OK;
}
attr->r_ptr_idx = pos / attr->buf_siz;
attr->r_pos = pos % attr->buf_siz;
@ -1163,11 +1198,11 @@ HPDF_MemStream_New (HPDF_MMgr mmgr,
HPDF_PTRACE((" HPDF_MemStream_New\n"));
// Create new HPDF_Stream object.
/* Create new HPDF_Stream object. */
stream = (HPDF_Stream)HPDF_GetMem (mmgr, sizeof(HPDF_Stream_Rec));
if (stream) {
// Create attribute struct.
/* Create attribute struct. */
HPDF_MemStreamAttr attr = (HPDF_MemStreamAttr)HPDF_GetMem (mmgr,
sizeof(HPDF_MemStreamAttr_Rec));

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- hpdf_string.h
* << Haru Free PDF Library >> -- hpdf_string.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -12,6 +15,7 @@
*
*/
#include <string.h>
#include "hpdf_conf.h"
#include "hpdf_utils.h"
#include "hpdf_objects.h"
@ -70,11 +74,11 @@ HPDF_String_SetValue (HPDF_String obj,
if (len > HPDF_LIMIT_MAX_STRING_LEN)
return HPDF_SetError (obj->error, HPDF_STRING_OUT_OF_RANGE, 0);
obj->value = (char *)HPDF_GetMem (obj->mmgr, len + 1);
obj->value = HPDF_GetMem (obj->mmgr, len + 1);
if (!obj->value)
return HPDF_Error_GetCode (obj->error);
HPDF_StrCpy (obj->value, value, obj->value + len);
HPDF_StrCpy ((char *)obj->value, value, (char *)obj->value + len);
obj->len = len;
return ret;
@ -116,12 +120,12 @@ HPDF_String_Write (HPDF_String obj,
return ret;
if ((ret = HPDF_Stream_WriteBinary (stream, obj->value,
HPDF_StrLen (obj->value, -1), e)) != HPDF_OK)
HPDF_StrLen ((char *)obj->value, -1), e)) != HPDF_OK)
return ret;
return HPDF_Stream_WriteChar (stream, '>');
} else {
return HPDF_Stream_WriteEscapeText (stream, obj->value);
return HPDF_Stream_WriteEscapeText (stream, (char *)obj->value);
}
} else {
HPDF_BYTE* src = obj->value;
@ -141,7 +145,7 @@ HPDF_String_Write (HPDF_String obj,
HPDF_Encoder_SetParseText (obj->encoder, &parse_state, src, len);
for (i = 0; i < len; i++) {
for (i = 0; (HPDF_INT32)i < len; i++) {
HPDF_BYTE b = src[i];
HPDF_UNICODE tmp_unicode;
HPDF_ByteType btype = HPDF_Encoder_ByteType (obj->encoder,
@ -159,7 +163,7 @@ HPDF_String_Write (HPDF_String obj,
if (btype != HPDF_BYTE_TYPE_TRIAL) {
if (btype == HPDF_BYTE_TYPE_LEAD) {
HPDF_BYTE b2 = src[i + 1];
HPDF_UINT16 char_code = (HPDF_UINT) b * 256 + b2;
HPDF_UINT16 char_code = (HPDF_UINT16)((HPDF_UINT) b * 256 + b2);
tmp_unicode = HPDF_Encoder_ToUnicode (obj->encoder,
char_code);
@ -187,3 +191,12 @@ HPDF_String_Write (HPDF_String obj,
return HPDF_OK;
}
HPDF_INT32
HPDF_String_Cmp (HPDF_String s1,
HPDF_String s2)
{
if (s1->len < s2->len) return -1;
if (s1->len > s2->len) return +1;
return memcmp(s1->value, s2->value, s1->len);
}

880
PDF/src/hpdf_u3d.c Normal file
View File

@ -0,0 +1,880 @@
/*
* << Haru Free PDF Library >> -- hpdf_u3d.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* 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.
*
*/
#include "hpdf_conf.h"
#include "hpdf_utils.h"
#include "hpdf.h"
#include <string.h>
#ifndef M_PI
/* Not defined in MSVC6 */
#define M_PI 3.14159265358979323846
#endif
HPDF_U3D
HPDF_U3D_LoadU3D (HPDF_MMgr mmgr,
HPDF_Stream u3d_data,
HPDF_Xref xref);
static const char u3d[] = "U3D";
static const char prc[] = "PRC";
static HPDF_STATUS Get3DStreamType (HPDF_Stream stream, const char **type)
{
HPDF_BYTE tag[4];
HPDF_UINT len;
HPDF_PTRACE ((" HPDF_U3D_Get3DStreamType\n"));
len = 4;
if (HPDF_Stream_Read (stream, tag, &len) != HPDF_OK) {
return HPDF_Error_GetCode (stream->error);
}
if (HPDF_Stream_Seek (stream, 0, HPDF_SEEK_SET) != HPDF_OK) {
return HPDF_Error_GetCode (stream->error);
}
if (HPDF_MemCmp(tag, (HPDF_BYTE *)u3d, 4/* yes, \0 is required */) == 0) {
*type = u3d;
return HPDF_OK;
}
if (HPDF_MemCmp(tag, (HPDF_BYTE *)prc, 3) == 0) {
*type = prc;
return HPDF_OK;
}
return HPDF_INVALID_U3D_DATA;
}
HPDF_U3D
HPDF_U3D_LoadU3DFromMem ( HPDF_MMgr mmgr,
const HPDF_BYTE *buf,
HPDF_UINT size,
HPDF_Xref xref )
{
HPDF_Dict image;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE ((" HPDF_U3D_LoadU3DFromMem\n"));
image = HPDF_DictStream_New (mmgr, xref);
if (!image) {
return NULL;
}
image->header.obj_class |= HPDF_OSUBCLASS_XOBJECT;
ret = HPDF_Dict_AddName (image, "Type", "XObject");
if (ret != HPDF_OK) {
HPDF_Dict_Free(image);
return NULL;
}
ret = HPDF_Dict_AddName (image, "Subtype", "Image");
if (ret != HPDF_OK) {
HPDF_Dict_Free(image);
return NULL;
}
if (HPDF_Stream_Write (image->stream, buf, size) != HPDF_OK) {
HPDF_Dict_Free(image);
return NULL;
}
return image;
}
HPDF_EXPORT(HPDF_Image)
HPDF_LoadU3DFromFile (HPDF_Doc pdf,
const char *filename)
{
HPDF_Stream imagedata;
HPDF_Image image;
HPDF_PTRACE ((" HPDF_LoadU3DFromFile\n"));
if (!HPDF_HasDoc (pdf)) {
return NULL;
}
/* create file stream */
imagedata = HPDF_FileReader_New (pdf->mmgr, filename);
if (HPDF_Stream_Validate (imagedata)) {
image = HPDF_U3D_LoadU3D (pdf->mmgr, imagedata, pdf->xref);
} else {
image = NULL;
}
/* destroy file stream */
HPDF_Stream_Free (imagedata);
if (!image) {
HPDF_CheckError (&pdf->error);
}
return image;
}
HPDF_EXPORT(HPDF_Image)
HPDF_LoadU3DFromMem (HPDF_Doc pdf,
const HPDF_BYTE *buffer,
HPDF_UINT size)
{
HPDF_Stream imagedata;
HPDF_Image image;
HPDF_PTRACE ((" HPDF_LoadU3DFromMem\n"));
if (!HPDF_HasDoc (pdf)) {
return NULL;
}
/* create file stream */
imagedata = HPDF_MemStream_New (pdf->mmgr, size);
if (!HPDF_Stream_Validate (imagedata)) {
HPDF_RaiseError (&pdf->error, HPDF_INVALID_STREAM, 0);
return NULL;
}
if (HPDF_Stream_Write (imagedata, buffer, size) != HPDF_OK) {
HPDF_Stream_Free (imagedata);
return NULL;
}
if (HPDF_Stream_Validate (imagedata)) {
image = HPDF_U3D_LoadU3D (pdf->mmgr, imagedata, pdf->xref);
} else {
image = NULL;
}
/* destroy file stream */
HPDF_Stream_Free (imagedata);
if (!image) {
HPDF_CheckError (&pdf->error);
}
return image;
}
HPDF_U3D
HPDF_U3D_LoadU3D (HPDF_MMgr mmgr,
HPDF_Stream u3d_data,
HPDF_Xref xref)
{
HPDF_Dict u3d;
const char *type;
HPDF_PTRACE ((" HPDF_U3D_LoadU3D\n"));
u3d = HPDF_DictStream_New (mmgr, xref);
if (!u3d) {
return NULL;
}
u3d->header.obj_class |= HPDF_OSUBCLASS_XOBJECT;
/* add required elements */
u3d->filter = HPDF_STREAM_FILTER_NONE;
if (HPDF_Dict_AddName (u3d, "Type", "3D") != HPDF_OK) {
HPDF_Dict_Free(u3d);
return NULL;
}
if (Get3DStreamType (u3d_data, &type) != HPDF_OK) {
HPDF_Dict_Free(u3d);
return NULL;
}
if (HPDF_Dict_AddName (u3d, "Subtype", type) != HPDF_OK) {
HPDF_Dict_Free(u3d);
return NULL;
}
for (;;) {
HPDF_BYTE buf[HPDF_STREAM_BUF_SIZ];
HPDF_UINT len = HPDF_STREAM_BUF_SIZ;
HPDF_STATUS ret = HPDF_Stream_Read (u3d_data, buf, &len);
if (ret != HPDF_OK) {
if (ret == HPDF_STREAM_EOF) {
if (len > 0) {
ret = HPDF_Stream_Write (u3d->stream, buf, len);
if (ret != HPDF_OK) {
HPDF_Dict_Free(u3d);
return NULL;
}
}
break;
} else {
HPDF_Dict_Free(u3d);
return NULL;
}
}
if (HPDF_Stream_Write (u3d->stream, buf, len) != HPDF_OK) {
HPDF_Dict_Free(u3d);
return NULL;
}
}
return u3d;
}
HPDF_EXPORT(HPDF_Dict) HPDF_Create3DView(HPDF_MMgr mmgr, const char *name)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_Dict view;
HPDF_PTRACE ((" HPDF_Create3DView\n"));
if (name == NULL || name[0] == '\0') {
return NULL;
}
view = HPDF_Dict_New (mmgr);
if (!view) {
return NULL;
}
ret = HPDF_Dict_AddName (view, "TYPE", "3DView");
if (ret != HPDF_OK) {
HPDF_Dict_Free (view);
return NULL;
}
ret = HPDF_Dict_Add (view, "XN", HPDF_String_New (mmgr, name, NULL));
if (ret != HPDF_OK) {
HPDF_Dict_Free (view);
return NULL;
}
ret = HPDF_Dict_Add (view, "IN", HPDF_String_New (mmgr, name, NULL));
if (ret != HPDF_OK) {
HPDF_Dict_Free (view);
return NULL;
}
return view;
}
HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_Add3DView(HPDF_U3D u3d, HPDF_Dict view)
{
HPDF_Array views = NULL;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE ((" HPDF_Add3DView\n"));
if (u3d == NULL || view == NULL) {
return HPDF_INVALID_U3D_DATA;
}
views = (HPDF_Array)HPDF_Dict_GetItem (u3d, "VA", HPDF_OCLASS_ARRAY);
if (views == NULL) {
views = HPDF_Array_New (u3d->mmgr);
if (!views) {
return HPDF_Error_GetCode (u3d->error);
}
ret = HPDF_Dict_Add (u3d, "VA", views);
if (ret == HPDF_OK) {
ret = HPDF_Dict_AddNumber (u3d, "DV", 0);
} else {
HPDF_Array_Free (views);
return ret;
}
}
if (ret == HPDF_OK) {
ret = HPDF_Array_Add( views, view);
}
return ret;
}
HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_AddOnInstanciate(HPDF_U3D u3d, HPDF_JavaScript javascript)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE ((" HPDF_U3D_AddOnInstanciate\n"));
if (u3d == NULL || javascript == NULL) {
return HPDF_INVALID_U3D_DATA;
}
ret = HPDF_Dict_Add(u3d, "OnInstantiate", javascript);
return ret;
}
HPDF_EXPORT(HPDF_STATUS) HPDF_U3D_SetDefault3DView(HPDF_U3D u3d, const char *name)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE ((" HPDF_U3D_SetDefault3DView\n"));
if (u3d == NULL || name == NULL || name[0] == '\0') {
return HPDF_INVALID_U3D_DATA;
}
ret = HPDF_Dict_Add (u3d, "DV", HPDF_String_New (u3d->mmgr, name, NULL));
return ret;
}
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_AddNode(HPDF_Dict view, const char *name, HPDF_REAL opacity, HPDF_BOOL visible)
{
HPDF_Array nodes = NULL;
HPDF_Dict node;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE ((" HPDF_3DView_AddNode\n"));
if (view == NULL || opacity < 0 || opacity > 1 || name == NULL || name[0] == '\0') {
return HPDF_INVALID_U3D_DATA;
}
nodes = (HPDF_Array)HPDF_Dict_GetItem (view, "NA", HPDF_OCLASS_ARRAY);
if (nodes == NULL) {
nodes = HPDF_Array_New (view->mmgr);
if (!nodes) {
return HPDF_Error_GetCode (view->error);
}
ret = HPDF_Dict_Add (view, "NA", nodes);
if (ret != HPDF_OK) {
HPDF_Array_Free (nodes);
return ret;
}
}
node = HPDF_Dict_New (view->mmgr);
if (!node) {
HPDF_Array_Free (nodes);
return HPDF_Error_GetCode (view->error);
}
ret = HPDF_Dict_AddName (node, "Type", "3DNode");
if (ret != HPDF_OK) {
HPDF_Array_Free (nodes);
HPDF_Dict_Free (node);
return ret;
}
ret = HPDF_Dict_Add (node, "N", HPDF_String_New (view->mmgr, name, NULL));
if (ret != HPDF_OK) {
HPDF_Array_Free (nodes);
HPDF_Dict_Free (node);
return ret;
}
ret = HPDF_Dict_AddReal (node, "O", opacity);
if (ret != HPDF_OK) {
HPDF_Array_Free (nodes);
HPDF_Dict_Free (node);
return ret;
}
ret = HPDF_Dict_AddBoolean (node, "V", visible);
if (ret != HPDF_OK) {
HPDF_Dict_Free (node);
HPDF_Array_Free (nodes);
return ret;
}
ret = HPDF_Array_Add(nodes, node);
if (ret != HPDF_OK) {
HPDF_Dict_Free (node);
HPDF_Array_Free (nodes);
return ret;
}
return ret;
}
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetLighting(HPDF_Dict view, const char *scheme)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_Dict lighting;
int i;
static const char * const schemes[] =
{ "Artwork", "None", "White", "Day", "Night", "Hard", "Primary", "Blue", "Red", "Cube", "CAD", "Headlamp" };
HPDF_PTRACE ((" HPDF_3DView_SetLighting\n"));
if (view == NULL || scheme == NULL || scheme[0] == '\0') {
return HPDF_INVALID_U3D_DATA;
}
for (i = 0; i < 12; i++) {
if (!strcmp(scheme, schemes[i])) {
break;
}
}
if (i == 12) {
return HPDF_INVALID_U3D_DATA;
}
lighting = HPDF_Dict_New (view->mmgr);
if (!lighting) {
return HPDF_Error_GetCode (view->error);
}
ret = HPDF_Dict_AddName (lighting, "Type", "3DLightingScheme");
if (ret != HPDF_OK) {
HPDF_Dict_Free (lighting);
return ret;
}
ret = HPDF_Dict_AddName (lighting, "Subtype", scheme);
if (ret != HPDF_OK) {
HPDF_Dict_Free (lighting);
return ret;
}
ret = HPDF_Dict_Add (view, "LS", lighting);
if (ret != HPDF_OK) {
HPDF_Dict_Free (lighting);
return ret;
}
return ret;
}
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetBackgroundColor(HPDF_Dict view, HPDF_REAL r, HPDF_REAL g, HPDF_REAL b)
{
HPDF_Array color;
HPDF_STATUS ret = HPDF_OK;
HPDF_Dict background;
HPDF_PTRACE ((" HPDF_3DView_SetBackgroundColor\n"));
if (view == NULL || r < 0 || r > 1 || g < 0 || g > 1 || b < 0 || b > 1) {
return HPDF_INVALID_U3D_DATA;
}
background = HPDF_Dict_New (view->mmgr);
if (!background) {
return HPDF_Error_GetCode (view->error);
}
color = HPDF_Array_New (view->mmgr);
if (!color) {
HPDF_Dict_Free (background);
return HPDF_Error_GetCode (view->error);
}
ret = HPDF_Array_AddReal (color, r);
if (ret != HPDF_OK) {
HPDF_Array_Free (color);
HPDF_Dict_Free (background);
return ret;
}
ret = HPDF_Array_AddReal (color, g);
if (ret != HPDF_OK) {
HPDF_Array_Free (color);
HPDF_Dict_Free (background);
return ret;
}
ret = HPDF_Array_AddReal (color, b);
if (ret != HPDF_OK) {
HPDF_Array_Free (color);
HPDF_Dict_Free (background);
return ret;
}
ret = HPDF_Dict_AddName (background, "Type", "3DBG");
if (ret != HPDF_OK) {
HPDF_Array_Free (color);
HPDF_Dict_Free (background);
return ret;
}
ret = HPDF_Dict_Add (background, "C", color);
if (ret != HPDF_OK) {
HPDF_Array_Free (color);
HPDF_Dict_Free (background);
return ret;
}
ret = HPDF_Dict_Add (view, "BG", background);
if (ret != HPDF_OK) {
HPDF_Array_Free (color);
HPDF_Dict_Free (background);
return ret;
}
return ret;
}
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetPerspectiveProjection(HPDF_Dict view, HPDF_REAL fov)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_Dict projection;
HPDF_PTRACE ((" HPDF_3DView_SetPerspectiveProjection\n"));
if (view == NULL || fov < 0 || fov > 180) {
return HPDF_INVALID_U3D_DATA;
}
projection = HPDF_Dict_New (view->mmgr);
if (!projection) {
return HPDF_Error_GetCode (view->error);
}
ret = HPDF_Dict_AddName (projection, "Subtype", "P");
if (ret != HPDF_OK) {
HPDF_Dict_Free (projection);
return ret;
}
ret = HPDF_Dict_AddName (projection, "PS", "Min");
if (ret != HPDF_OK) {
HPDF_Dict_Free (projection);
return ret;
}
ret = HPDF_Dict_AddReal (projection, "FOV", fov);
if (ret != HPDF_OK) {
HPDF_Dict_Free (projection);
return ret;
}
ret = HPDF_Dict_Add (view, "P", projection);
if (ret != HPDF_OK) {
HPDF_Dict_Free (projection);
return ret;
}
return ret;
}
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetOrthogonalProjection(HPDF_Dict view, HPDF_REAL mag)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_Dict projection;
HPDF_PTRACE ((" HPDF_3DView_SetOrthogonalProjection\n"));
if (view == NULL || mag <= 0) {
return HPDF_INVALID_U3D_DATA;
}
projection = HPDF_Dict_New (view->mmgr);
if (!projection) {
return HPDF_Error_GetCode (view->error);
}
ret = HPDF_Dict_AddName (projection, "Subtype", "O");
if (ret != HPDF_OK) {
HPDF_Dict_Free (projection);
return ret;
}
ret = HPDF_Dict_AddReal (projection, "OS", mag);
if (ret != HPDF_OK) {
HPDF_Dict_Free (projection);
return ret;
}
ret = HPDF_Dict_Add (view, "P", projection);
if (ret != HPDF_OK) {
HPDF_Dict_Free (projection);
return ret;
}
return ret;
}
#define normalize(x, y, z) \
{ \
HPDF_REAL modulo; \
modulo = (float)sqrt((float)(x*x) + (float)(y*y) + (float)(z*z)); \
if (modulo != 0.0) \
{ \
x = x/modulo; \
y = y/modulo; \
z = z/modulo; \
} \
}
/* building the transformation matrix*/
/* #1,#2,#3 centre of orbit coordinates (coo)*/
/* #4,#5,#6 centre of orbit to camera direction vector (c2c)*/
/* #7 orbital radius (roo)*/
/* #8 camera roll (roll)*/
HPDF_EXPORT(HPDF_STATUS) HPDF_3DView_SetCamera(HPDF_Dict view, HPDF_REAL coox, HPDF_REAL cooy, HPDF_REAL cooz, HPDF_REAL c2cx, HPDF_REAL c2cy, HPDF_REAL c2cz, HPDF_REAL roo, HPDF_REAL roll)
{
HPDF_REAL viewx, viewy, viewz;
HPDF_REAL leftx, lefty, leftz;
HPDF_REAL upx, upy, upz;
HPDF_REAL transx, transy, transz;
HPDF_Array matrix;
HPDF_STATUS ret = HPDF_OK;
HPDF_PTRACE ((" HPDF_3DView_SetCamera\n"));
if (view == NULL) {
return HPDF_INVALID_U3D_DATA;
}
/* view vector (opposite to c2c) */
viewx = -c2cx;
viewy = -c2cy;
viewz = -c2cz;
/* c2c = (0, -1, 0) by default */
if (viewx == 0.0 && viewy == 0.0 && viewz == 0.0) {
viewy = 1.0;
}
/* normalize view vector */
normalize(viewx, viewy, viewz);
/* rotation matrix */
/* top and bottom views */
leftx = -1.0f;
lefty = 0.0f;
leftz = 0.0f;
/* up-vector */
if (viewz < 0.0) /* top view*/
{
upx = 0.0f;
upy = 1.0f;
upz = 0.0f;
}
else /* bottom view*/
{
upx = 0.0f;
upy =-1.0f;
upz = 0.0f;
}
if ( fabs(viewx) + fabs(viewy) != 0.0f) /* other views than top and bottom*/
{
/* up-vector = up_world - (up_world dot view) view*/
upx = -viewz*viewx;
upy = -viewz*viewy;
upz = -viewz*viewz + 1.0f;
/* normalize up-vector*/
normalize(upx, upy, upz);
/* left vector = up x view*/
leftx = viewz*upy - viewy*upz;
lefty = viewx*upz - viewz*upx;
leftz = viewy*upx - viewx*upy;
/* normalize left vector*/
normalize(leftx, lefty, leftz);
}
/* apply camera roll*/
{
HPDF_REAL leftxprime, leftyprime, leftzprime;
HPDF_REAL upxprime, upyprime, upzprime;
HPDF_REAL sinroll, cosroll;
sinroll = (HPDF_REAL)sin((roll/180.0f)*M_PI);
cosroll = (HPDF_REAL)cos((roll/180.0f)*M_PI);
leftxprime = leftx*cosroll + upx*sinroll;
leftyprime = lefty*cosroll + upy*sinroll;
leftzprime = leftz*cosroll + upz*sinroll;
upxprime = upx*cosroll + leftx*sinroll;
upyprime = upy*cosroll + lefty*sinroll;
upzprime = upz*cosroll + leftz*sinroll;
leftx = leftxprime;
lefty = leftyprime;
leftz = leftzprime;
upx = upxprime;
upy = upyprime;
upz = upzprime;
}
/* translation vector*/
roo = (HPDF_REAL)fabs(roo);
if (roo == 0.0) {
roo = (HPDF_REAL)0.000000000000000001;
}
transx = coox - roo*viewx;
transy = cooy - roo*viewy;
transz = cooz - roo*viewz;
/* transformation matrix*/
matrix = HPDF_Array_New (view->mmgr);
if (!matrix) {
return HPDF_Error_GetCode (view->error);
}
ret = HPDF_Array_AddReal (matrix, leftx);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Array_AddReal (matrix, lefty);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Array_AddReal (matrix, leftz);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Array_AddReal (matrix, upx);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Array_AddReal (matrix, upy);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Array_AddReal (matrix, upz);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Array_AddReal (matrix, viewx);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Array_AddReal (matrix, viewy);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Array_AddReal (matrix, viewz);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Array_AddReal (matrix, transx);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Array_AddReal (matrix, transy);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Array_AddReal (matrix, transz);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Dict_AddName (view, "MS", "M");
if (ret != HPDF_OK) goto failed;
ret = HPDF_Dict_Add (view, "C2W", matrix);
if (ret != HPDF_OK) goto failed;
ret = HPDF_Dict_AddNumber (view, "CO", (HPDF_INT32)roo);
failed:
if (ret != HPDF_OK) {
HPDF_Array_Free (matrix);
return ret;
}
return ret;
}
HPDF_Dict HPDF_3DView_New( HPDF_MMgr mmgr, HPDF_Xref xref, HPDF_U3D u3d, const char *name)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_Dict view;
HPDF_PTRACE ((" HPDF_3DView_New\n"));
if (name == NULL || name[0] == '\0') {
return NULL;
}
view = HPDF_Dict_New (mmgr);
if (!view) {
return NULL;
}
if (HPDF_Xref_Add (xref, view) != HPDF_OK)
return NULL;
ret = HPDF_Dict_AddName (view, "TYPE", "3DView");
if (ret != HPDF_OK) {
HPDF_Dict_Free (view);
return NULL;
}
ret = HPDF_Dict_Add (view, "XN", HPDF_String_New (mmgr, name, NULL));
if (ret != HPDF_OK) {
HPDF_Dict_Free (view);
return NULL;
}
ret = HPDF_Dict_Add (view, "IN", HPDF_String_New (mmgr, name, NULL));
if (ret != HPDF_OK) {
HPDF_Dict_Free (view);
return NULL;
}
ret = HPDF_U3D_Add3DView( u3d, view);
if (ret != HPDF_OK) {
HPDF_Dict_Free (view);
return NULL;
}
return view;
}
HPDF_EXPORT(HPDF_STATUS)
HPDF_3DView_Add3DC3DMeasure(HPDF_Dict view,
HPDF_3DMeasure measure)
{
HPDF_STATUS ret = HPDF_OK;
HPDF_Array array;
void* a;
a = HPDF_Dict_GetItem (view, "MA", HPDF_OCLASS_ARRAY);
if ( a )
{
array = (HPDF_Array)a;
}
else
{
array = HPDF_Array_New (view->mmgr);
if (!array)
return 0;
if (HPDF_Dict_Add (view, "MA", array) != HPDF_OK)
return 0;
}
ret = HPDF_Array_Add(array, measure);
return ret;
}
HPDF_EXPORT(HPDF_JavaScript) HPDF_CreateJavaScript( HPDF_Doc pdf, const char *code )
{
HPDF_JavaScript javaScript;
int len ;
HPDF_PTRACE ((" HPDF_CreateJavaScript\n"));
javaScript = (HPDF_JavaScript) HPDF_DictStream_New(pdf->mmgr, pdf->xref);
if (!javaScript) {
return NULL;
}
len = (HPDF_UINT)strlen(code);
if (HPDF_Stream_Write (javaScript->stream, (HPDF_BYTE *)code, len) != HPDF_OK) {
HPDF_Dict_Free(javaScript);
return NULL;
}
return javaScript;
}
#undef normalize

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.0 >> -- HPDF_utils.c
* << Haru Free PDF Library >> -- hpdf_utils.c
*
* Copyright (c) 1999-2004 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -24,6 +27,10 @@ HPDF_AToI (const char *s)
HPDF_BOOL flg = HPDF_FALSE;
HPDF_INT v = 0;
if (!s) {
return 0;
}
/* increment pointer until the charactor of 's' is not
* white-space-charactor.
*/
@ -129,7 +136,7 @@ HPDF_IToA (char *s,
*t-- = 0;
while (val > 0) {
*t = (char)(val % 10) + '0';
*t = (char)((char)(val % 10) + '0');
val /= 10;
t--;
}
@ -158,7 +165,7 @@ HPDF_IToA2 (char *s,
*u = 0;
t = u - 1;
while (val > 0 && t >= s) {
*t = (char)(val % 10) + '0';
*t = (char)((char)(val % 10) + '0');
val /= 10;
t--;
}
@ -202,7 +209,7 @@ HPDF_FToA (char *s,
/* process decimal part */
for (i = 0; i < 5; i++) {
*t = (char)(fpart_val % 10) + '0';
*t = (char)((char)(fpart_val % 10) + '0');
fpart_val /= 10;
t--;
}
@ -214,7 +221,7 @@ HPDF_FToA (char *s,
t--;
while (int_val > 0) {
*t = (char)(int_val % 10) + '0';
*t = (char)((char)(int_val % 10) + '0');
int_val /= 10;
t--;
}
@ -266,7 +273,7 @@ HPDF_StrCpy (char *out,
*out = 0;
return out;
return (HPDF_BYTE *)out;
}
@ -370,7 +377,7 @@ HPDF_StrStr (const char *s1,
maxlen++;
while (maxlen > 0) {
if (HPDF_MemCmp (s1, s2, len) == 0)
if (HPDF_MemCmp ((HPDF_BYTE *)s1, (HPDF_BYTE *)s2, len) == 0)
return s1;
s1++;

View File

@ -1,7 +1,10 @@
/*
* << Haru Free PDF Library 2.0.3 >> -- hpdf_xref.h
* << Haru Free PDF Library >> -- hpdf_xref.c
*
* URL: http://libharu.org
*
* Copyright (c) 1999-2006 Takeshi Kanno <takeshi_kanno@est.hi-ho.ne.jp>
* Copyright (c) 2007-2009 Antony Dovgal <tony@daylessday.org>
*
* Permission to use, copy, modify, distribute and sell this software
* and its documentation for any purpose is hereby granted without fee,
@ -276,7 +279,7 @@ HPDF_Xref_WriteToStream (HPDF_Xref xref,
tmp_xref->addr = stream->size;
pbuf = buf;
pbuf = HPDF_StrCpy (pbuf, "xref\012", eptr);
pbuf = (char *)HPDF_StrCpy (pbuf, "xref\012", eptr);
pbuf = HPDF_IToA (pbuf, tmp_xref->start_offset, eptr);
*pbuf++ = ' ';
pbuf = HPDF_IToA (pbuf, tmp_xref->entries->count, eptr);
@ -295,7 +298,7 @@ HPDF_Xref_WriteToStream (HPDF_Xref xref,
pbuf = HPDF_IToA2 (pbuf, entry->gen_no, HPDF_GEN_NO_LEN + 1);
*pbuf++ = ' ';
*pbuf++ = entry->entry_typ;
HPDF_StrCpy (pbuf, "\015\012", eptr);
HPDF_StrCpy (pbuf, "\015\012", eptr); /* Acrobat 8.15 requires both \r and \n here */
ret = HPDF_Stream_WriteStr (stream, buf);
if (ret != HPDF_OK)
return ret;

285
PDF/src/t4.h Normal file
View File

@ -0,0 +1,285 @@
/* $Id: t4.h,v 1.20 2007/11/10 18:40:44 drolon Exp $ */
/*
* Copyright (c) 1988-1997 Sam Leffler
* Copyright (c) 1991-1997 Silicon Graphics, Inc.
*
* Permission to use, copy, modify, distribute, and sell this software and
* its documentation for any purpose is hereby granted without fee, provided
* that (i) the above copyright notices and this permission notice appear in
* all copies of the software and related documentation, and (ii) the names of
* Sam Leffler and Silicon Graphics may not be used in any advertising or
* publicity relating to the software without the specific, prior written
* permission of Sam Leffler and Silicon Graphics.
*
* THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
* EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
* WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
*
* IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
* ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
* OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
* WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
* LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
* OF THIS SOFTWARE.
*/
#ifndef _T4_
#define _T4_
/*
* CCITT T.4 1D Huffman runlength codes and
* related definitions. Given the small sizes
* of these tables it does not seem
* worthwhile to make code & length 8 bits.
*/
typedef struct tableentry {
unsigned short length; /* bit length of g3 code */
unsigned short code; /* g3 code */
short runlen; /* run length in bits */
} tableentry;
#define EOL 0x001 /* EOL code value - 0000 0000 0000 1 */
/* status values returned instead of a run length */
#define G3CODE_EOL -1 /* NB: ACT_EOL - ACT_WRUNT */
#define G3CODE_INVALID -2 /* NB: ACT_INVALID - ACT_WRUNT */
#define G3CODE_EOF -3 /* end of input data */
#define G3CODE_INCOMP -4 /* incomplete run code */
/*
* Note that these tables are ordered such that the
* index into the table is known to be either the
* run length, or (run length / 64) + a fixed offset.
*
* NB: The G3CODE_INVALID entries are only used
* during state generation (see mkg3states.c).
*/
#ifdef G3CODES
const tableentry TIFFFaxWhiteCodes[] = {
{ 8, 0x35, 0 }, /* 0011 0101 */
{ 6, 0x7, 1 }, /* 0001 11 */
{ 4, 0x7, 2 }, /* 0111 */
{ 4, 0x8, 3 }, /* 1000 */
{ 4, 0xB, 4 }, /* 1011 */
{ 4, 0xC, 5 }, /* 1100 */
{ 4, 0xE, 6 }, /* 1110 */
{ 4, 0xF, 7 }, /* 1111 */
{ 5, 0x13, 8 }, /* 1001 1 */
{ 5, 0x14, 9 }, /* 1010 0 */
{ 5, 0x7, 10 }, /* 0011 1 */
{ 5, 0x8, 11 }, /* 0100 0 */
{ 6, 0x8, 12 }, /* 0010 00 */
{ 6, 0x3, 13 }, /* 0000 11 */
{ 6, 0x34, 14 }, /* 1101 00 */
{ 6, 0x35, 15 }, /* 1101 01 */
{ 6, 0x2A, 16 }, /* 1010 10 */
{ 6, 0x2B, 17 }, /* 1010 11 */
{ 7, 0x27, 18 }, /* 0100 111 */
{ 7, 0xC, 19 }, /* 0001 100 */
{ 7, 0x8, 20 }, /* 0001 000 */
{ 7, 0x17, 21 }, /* 0010 111 */
{ 7, 0x3, 22 }, /* 0000 011 */
{ 7, 0x4, 23 }, /* 0000 100 */
{ 7, 0x28, 24 }, /* 0101 000 */
{ 7, 0x2B, 25 }, /* 0101 011 */
{ 7, 0x13, 26 }, /* 0010 011 */
{ 7, 0x24, 27 }, /* 0100 100 */
{ 7, 0x18, 28 }, /* 0011 000 */
{ 8, 0x2, 29 }, /* 0000 0010 */
{ 8, 0x3, 30 }, /* 0000 0011 */
{ 8, 0x1A, 31 }, /* 0001 1010 */
{ 8, 0x1B, 32 }, /* 0001 1011 */
{ 8, 0x12, 33 }, /* 0001 0010 */
{ 8, 0x13, 34 }, /* 0001 0011 */
{ 8, 0x14, 35 }, /* 0001 0100 */
{ 8, 0x15, 36 }, /* 0001 0101 */
{ 8, 0x16, 37 }, /* 0001 0110 */
{ 8, 0x17, 38 }, /* 0001 0111 */
{ 8, 0x28, 39 }, /* 0010 1000 */
{ 8, 0x29, 40 }, /* 0010 1001 */
{ 8, 0x2A, 41 }, /* 0010 1010 */
{ 8, 0x2B, 42 }, /* 0010 1011 */
{ 8, 0x2C, 43 }, /* 0010 1100 */
{ 8, 0x2D, 44 }, /* 0010 1101 */
{ 8, 0x4, 45 }, /* 0000 0100 */
{ 8, 0x5, 46 }, /* 0000 0101 */
{ 8, 0xA, 47 }, /* 0000 1010 */
{ 8, 0xB, 48 }, /* 0000 1011 */
{ 8, 0x52, 49 }, /* 0101 0010 */
{ 8, 0x53, 50 }, /* 0101 0011 */
{ 8, 0x54, 51 }, /* 0101 0100 */
{ 8, 0x55, 52 }, /* 0101 0101 */
{ 8, 0x24, 53 }, /* 0010 0100 */
{ 8, 0x25, 54 }, /* 0010 0101 */
{ 8, 0x58, 55 }, /* 0101 1000 */
{ 8, 0x59, 56 }, /* 0101 1001 */
{ 8, 0x5A, 57 }, /* 0101 1010 */
{ 8, 0x5B, 58 }, /* 0101 1011 */
{ 8, 0x4A, 59 }, /* 0100 1010 */
{ 8, 0x4B, 60 }, /* 0100 1011 */
{ 8, 0x32, 61 }, /* 0011 0010 */
{ 8, 0x33, 62 }, /* 0011 0011 */
{ 8, 0x34, 63 }, /* 0011 0100 */
{ 5, 0x1B, 64 }, /* 1101 1 */
{ 5, 0x12, 128 }, /* 1001 0 */
{ 6, 0x17, 192 }, /* 0101 11 */
{ 7, 0x37, 256 }, /* 0110 111 */
{ 8, 0x36, 320 }, /* 0011 0110 */
{ 8, 0x37, 384 }, /* 0011 0111 */
{ 8, 0x64, 448 }, /* 0110 0100 */
{ 8, 0x65, 512 }, /* 0110 0101 */
{ 8, 0x68, 576 }, /* 0110 1000 */
{ 8, 0x67, 640 }, /* 0110 0111 */
{ 9, 0xCC, 704 }, /* 0110 0110 0 */
{ 9, 0xCD, 768 }, /* 0110 0110 1 */
{ 9, 0xD2, 832 }, /* 0110 1001 0 */
{ 9, 0xD3, 896 }, /* 0110 1001 1 */
{ 9, 0xD4, 960 }, /* 0110 1010 0 */
{ 9, 0xD5, 1024 }, /* 0110 1010 1 */
{ 9, 0xD6, 1088 }, /* 0110 1011 0 */
{ 9, 0xD7, 1152 }, /* 0110 1011 1 */
{ 9, 0xD8, 1216 }, /* 0110 1100 0 */
{ 9, 0xD9, 1280 }, /* 0110 1100 1 */
{ 9, 0xDA, 1344 }, /* 0110 1101 0 */
{ 9, 0xDB, 1408 }, /* 0110 1101 1 */
{ 9, 0x98, 1472 }, /* 0100 1100 0 */
{ 9, 0x99, 1536 }, /* 0100 1100 1 */
{ 9, 0x9A, 1600 }, /* 0100 1101 0 */
{ 6, 0x18, 1664 }, /* 0110 00 */
{ 9, 0x9B, 1728 }, /* 0100 1101 1 */
{ 11, 0x8, 1792 }, /* 0000 0001 000 */
{ 11, 0xC, 1856 }, /* 0000 0001 100 */
{ 11, 0xD, 1920 }, /* 0000 0001 101 */
{ 12, 0x12, 1984 }, /* 0000 0001 0010 */
{ 12, 0x13, 2048 }, /* 0000 0001 0011 */
{ 12, 0x14, 2112 }, /* 0000 0001 0100 */
{ 12, 0x15, 2176 }, /* 0000 0001 0101 */
{ 12, 0x16, 2240 }, /* 0000 0001 0110 */
{ 12, 0x17, 2304 }, /* 0000 0001 0111 */
{ 12, 0x1C, 2368 }, /* 0000 0001 1100 */
{ 12, 0x1D, 2432 }, /* 0000 0001 1101 */
{ 12, 0x1E, 2496 }, /* 0000 0001 1110 */
{ 12, 0x1F, 2560 }, /* 0000 0001 1111 */
{ 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */
{ 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */
{ 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */
{ 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */
{ 12, 0x0, G3CODE_INVALID }, /* 0000 0000 0000 */
};
const tableentry TIFFFaxBlackCodes[] = {
{ 10, 0x37, 0 }, /* 0000 1101 11 */
{ 3, 0x2, 1 }, /* 010 */
{ 2, 0x3, 2 }, /* 11 */
{ 2, 0x2, 3 }, /* 10 */
{ 3, 0x3, 4 }, /* 011 */
{ 4, 0x3, 5 }, /* 0011 */
{ 4, 0x2, 6 }, /* 0010 */
{ 5, 0x3, 7 }, /* 0001 1 */
{ 6, 0x5, 8 }, /* 0001 01 */
{ 6, 0x4, 9 }, /* 0001 00 */
{ 7, 0x4, 10 }, /* 0000 100 */
{ 7, 0x5, 11 }, /* 0000 101 */
{ 7, 0x7, 12 }, /* 0000 111 */
{ 8, 0x4, 13 }, /* 0000 0100 */
{ 8, 0x7, 14 }, /* 0000 0111 */
{ 9, 0x18, 15 }, /* 0000 1100 0 */
{ 10, 0x17, 16 }, /* 0000 0101 11 */
{ 10, 0x18, 17 }, /* 0000 0110 00 */
{ 10, 0x8, 18 }, /* 0000 0010 00 */
{ 11, 0x67, 19 }, /* 0000 1100 111 */
{ 11, 0x68, 20 }, /* 0000 1101 000 */
{ 11, 0x6C, 21 }, /* 0000 1101 100 */
{ 11, 0x37, 22 }, /* 0000 0110 111 */
{ 11, 0x28, 23 }, /* 0000 0101 000 */
{ 11, 0x17, 24 }, /* 0000 0010 111 */
{ 11, 0x18, 25 }, /* 0000 0011 000 */
{ 12, 0xCA, 26 }, /* 0000 1100 1010 */
{ 12, 0xCB, 27 }, /* 0000 1100 1011 */
{ 12, 0xCC, 28 }, /* 0000 1100 1100 */
{ 12, 0xCD, 29 }, /* 0000 1100 1101 */
{ 12, 0x68, 30 }, /* 0000 0110 1000 */
{ 12, 0x69, 31 }, /* 0000 0110 1001 */
{ 12, 0x6A, 32 }, /* 0000 0110 1010 */
{ 12, 0x6B, 33 }, /* 0000 0110 1011 */
{ 12, 0xD2, 34 }, /* 0000 1101 0010 */
{ 12, 0xD3, 35 }, /* 0000 1101 0011 */
{ 12, 0xD4, 36 }, /* 0000 1101 0100 */
{ 12, 0xD5, 37 }, /* 0000 1101 0101 */
{ 12, 0xD6, 38 }, /* 0000 1101 0110 */
{ 12, 0xD7, 39 }, /* 0000 1101 0111 */
{ 12, 0x6C, 40 }, /* 0000 0110 1100 */
{ 12, 0x6D, 41 }, /* 0000 0110 1101 */
{ 12, 0xDA, 42 }, /* 0000 1101 1010 */
{ 12, 0xDB, 43 }, /* 0000 1101 1011 */
{ 12, 0x54, 44 }, /* 0000 0101 0100 */
{ 12, 0x55, 45 }, /* 0000 0101 0101 */
{ 12, 0x56, 46 }, /* 0000 0101 0110 */
{ 12, 0x57, 47 }, /* 0000 0101 0111 */
{ 12, 0x64, 48 }, /* 0000 0110 0100 */
{ 12, 0x65, 49 }, /* 0000 0110 0101 */
{ 12, 0x52, 50 }, /* 0000 0101 0010 */
{ 12, 0x53, 51 }, /* 0000 0101 0011 */
{ 12, 0x24, 52 }, /* 0000 0010 0100 */
{ 12, 0x37, 53 }, /* 0000 0011 0111 */
{ 12, 0x38, 54 }, /* 0000 0011 1000 */
{ 12, 0x27, 55 }, /* 0000 0010 0111 */
{ 12, 0x28, 56 }, /* 0000 0010 1000 */
{ 12, 0x58, 57 }, /* 0000 0101 1000 */
{ 12, 0x59, 58 }, /* 0000 0101 1001 */
{ 12, 0x2B, 59 }, /* 0000 0010 1011 */
{ 12, 0x2C, 60 }, /* 0000 0010 1100 */
{ 12, 0x5A, 61 }, /* 0000 0101 1010 */
{ 12, 0x66, 62 }, /* 0000 0110 0110 */
{ 12, 0x67, 63 }, /* 0000 0110 0111 */
{ 10, 0xF, 64 }, /* 0000 0011 11 */
{ 12, 0xC8, 128 }, /* 0000 1100 1000 */
{ 12, 0xC9, 192 }, /* 0000 1100 1001 */
{ 12, 0x5B, 256 }, /* 0000 0101 1011 */
{ 12, 0x33, 320 }, /* 0000 0011 0011 */
{ 12, 0x34, 384 }, /* 0000 0011 0100 */
{ 12, 0x35, 448 }, /* 0000 0011 0101 */
{ 13, 0x6C, 512 }, /* 0000 0011 0110 0 */
{ 13, 0x6D, 576 }, /* 0000 0011 0110 1 */
{ 13, 0x4A, 640 }, /* 0000 0010 0101 0 */
{ 13, 0x4B, 704 }, /* 0000 0010 0101 1 */
{ 13, 0x4C, 768 }, /* 0000 0010 0110 0 */
{ 13, 0x4D, 832 }, /* 0000 0010 0110 1 */
{ 13, 0x72, 896 }, /* 0000 0011 1001 0 */
{ 13, 0x73, 960 }, /* 0000 0011 1001 1 */
{ 13, 0x74, 1024 }, /* 0000 0011 1010 0 */
{ 13, 0x75, 1088 }, /* 0000 0011 1010 1 */
{ 13, 0x76, 1152 }, /* 0000 0011 1011 0 */
{ 13, 0x77, 1216 }, /* 0000 0011 1011 1 */
{ 13, 0x52, 1280 }, /* 0000 0010 1001 0 */
{ 13, 0x53, 1344 }, /* 0000 0010 1001 1 */
{ 13, 0x54, 1408 }, /* 0000 0010 1010 0 */
{ 13, 0x55, 1472 }, /* 0000 0010 1010 1 */
{ 13, 0x5A, 1536 }, /* 0000 0010 1101 0 */
{ 13, 0x5B, 1600 }, /* 0000 0010 1101 1 */
{ 13, 0x64, 1664 }, /* 0000 0011 0010 0 */
{ 13, 0x65, 1728 }, /* 0000 0011 0010 1 */
{ 11, 0x8, 1792 }, /* 0000 0001 000 */
{ 11, 0xC, 1856 }, /* 0000 0001 100 */
{ 11, 0xD, 1920 }, /* 0000 0001 101 */
{ 12, 0x12, 1984 }, /* 0000 0001 0010 */
{ 12, 0x13, 2048 }, /* 0000 0001 0011 */
{ 12, 0x14, 2112 }, /* 0000 0001 0100 */
{ 12, 0x15, 2176 }, /* 0000 0001 0101 */
{ 12, 0x16, 2240 }, /* 0000 0001 0110 */
{ 12, 0x17, 2304 }, /* 0000 0001 0111 */
{ 12, 0x1C, 2368 }, /* 0000 0001 1100 */
{ 12, 0x1D, 2432 }, /* 0000 0001 1101 */
{ 12, 0x1E, 2496 }, /* 0000 0001 1110 */
{ 12, 0x1F, 2560 }, /* 0000 0001 1111 */
{ 12, 0x1, G3CODE_EOL }, /* 0000 0000 0001 */
{ 9, 0x1, G3CODE_INVALID }, /* 0000 0000 1 */
{ 10, 0x1, G3CODE_INVALID }, /* 0000 0000 01 */
{ 11, 0x1, G3CODE_INVALID }, /* 0000 0000 001 */
{ 12, 0x0, G3CODE_INVALID }, /* 0000 0000 0000 */
};
#else
extern const tableentry TIFFFaxWhiteCodes[];
extern const tableentry TIFFFaxBlackCodes[];
#endif
#endif /* _T4_ */