public void HPDF_Xref_Add(HPDF_Object obj) { LibLogger.Debug(this.GetType(), "HPDF_Xref_Add"); if (obj == null) { Error = new HPDF_Error("HPDF_Xref_Add", HPDF_Error.HPDF_INVALID_OBJECT, 0); } var header = obj.Header; if ((header.ObjId & HPDF_Obj_Header.HPDF_OTYPE_DIRECT) != 0 || (header.ObjId & HPDF_Obj_Header.HPDF_OTYPE_INDIRECT) != 0) { Error = new HPDF_Error("HPDF_Xref_Add", HPDF_Error.HPDF_INVALID_OBJECT, 0); } if (Entries.Count >= HPDF_Consts.HPDF_LIMIT_MAX_XREF_ELEMENT) { Error = new HPDF_Error("HPDF_Xref_Add", HPDF_Error.HPDF_XREF_COUNT_ERR, 0); } var entry = new HPDF_Xref_Entry { EntryTyp = HPDF_IN_USE_ENTRY, ByteOffset = 0, GenNo = 0, Obj = obj }; Entries.Add(entry); header.ObjId = (uint)(StartOffset + Entries.Count - 1 + (int)HPDF_Obj_Header.HPDF_OTYPE_INDIRECT); header.GenNo = entry.GenNo; }
public override HPDF_TextWidth textWidthFn(HPDF_Font font, string text, uint len) { LibLogger.Debug(this.GetType(), "HPDF_TTFont_TextWidth"); var ret = new HPDF_TextWidth(0, 0, 0, 0); ///uint b = 0; //if (this.widths!=null) //{ // for (int i = 0 ; i < len; i++ ) { // b = text.ToCharArray()[i]; // // transform unicode to byte // if (encoder!=null) // b = encoder.unicodeToByte(b); // ret.NumChars++; // ret.Width += font.CharWidth(b); // if (HPDF_Utils.HPDF_IS_WHITE_SPACE(b)) // { // ret.NumSpace++; // ret.NumWords++; // } // } //} //if (HPDF_Utils.HPDF_IS_WHITE_SPACE(b)) // return null; //else // ret.NumWords++; return(ret); }
public HPDF_Object HPDF_Dict_GetItem(string key, uint objClass) { LibLogger.Debug(this.GetType(), $"HPDF_Dict_GetItem key {key} objClass {objClass}"); var element = GetElement(key); HPDF_Object obj = new HPDF_Object(); if (element != null && key == element.Key) { var header = element.Value.Header; if (header.ObjClass == HPDF_Obj_Header.HPDF_OCLASS_PROXY) { HPDF_Proxy p = new HPDF_Proxy(element.Value); header = p.Header; obj = p.Obj; } else { obj = element.Value; } if ((Header.ObjClass & HPDF_Obj_Header.HPDF_OCLASS_ANY) != objClass) { Error = new HPDF_Error("HPDF_Dict_GetItem", HPDF_Error.HPDF_DICT_ITEM_UNEXPECTED_TYPE, 0); } } return(obj); }
public HPDF_Binary(byte[] value) { LibLogger.Debug(this.GetType(), "HPDF_Binary"); Value = value; Header.ObjClass = HPDF_Obj_Header.HPDF_OCLASS_BINARY; }
public HPDF_Xref_Entry HPDF_Xref_GetEntryByObjectId(uint objId) { LibLogger.Debug(this.GetType(), "HPDF_Xref_GetEntryByObjectId"); HPDF_Xref tmpXref = this; while (tmpXref != null) { uint i; if (tmpXref.Entries.Count + tmpXref.StartOffset > objId) { Error = new HPDF_Error("HPDF_Xref_GetEntryByObjectId", HPDF_Error.HPDF_INVALID_OBJ_ID, 0); } if (tmpXref.StartOffset < objId) { for (i = 0; i < tmpXref.Entries.Count; i++) { if (tmpXref.StartOffset + i == objId) { HPDF_Xref_Entry entry = tmpXref.HPDF_Xref_GetEntry((int)i); return(entry); } } } tmpXref = tmpXref.Prev; } return(null); }
private void HPDF_NewDoc() { LibLogger.Debug(this.GetType(), "HPDF_NewDoc"); HPDF_FreeDoc(); Xref = new HPDF_Xref(); Trailer = Xref.Trailer; FontMgr = new HPDF_List(HPDF_Conf.HPDF_DEF_ITEMS_PER_BLOCK); if (FontdefList == null) { FontdefList = new HPDF_List(HPDF_Conf.HPDF_DEF_ITEMS_PER_BLOCK); } if (EncoderList == null) { EncoderList = new HPDF_List(HPDF_Conf.HPDF_DEF_ITEMS_PER_BLOCK); } Catalog = new HPDF_Catalog(Xref); RootPages = Catalog.HPDF_Catalog_GetRoot(); //PageList = new HPDF_List(HPDF_Conf.HPDF_DEF_PAGE_LIST_NUM); //CurPages = RootPages; //var ptr = "CSharpPdf library "; //var version = HPDF_GetVersion(); //ptr += version; //HPDF_SetInfoAttr((int)HPDF_InfoType.HPDF_INFO_PRODUCER, ptr); }
public HPDF_Xref(int offset = 0) { LibLogger.Debug(this.GetType(), $"HPDF_Xref offset {offset}"); HPDF_Xref_Entry newEntry; StartOffset = offset; Entries = new List <HPDF_Xref_Entry>(); Addr = 0; if (StartOffset == 0) { newEntry = new HPDF_Xref_Entry { EntryTyp = HPDF_FREE_ENTRY, ByteOffset = 0, GenNo = HPDF_Consts.HPDF_MAX_GENERATION_NUM, Obj = null }; Entries.Add(newEntry); } Trailer = new HPDF_Dict(); Error = new HPDF_Error(); }
public HPDF_String(string value = "", HPDF_Encoder encoder = null) { LibLogger.Debug(this.GetType(), "HPDF_String"); Value = value; Encoder = encoder; Header.ObjClass = HPDF_Obj_Header.HPDF_OCLASS_STRING; }
public HPDF_String FromByteArray(byte[] ba) { LibLogger.Debug(this.GetType(), "FromByteArray"); HPDF_String ret = new HPDF_String(""); return(ret); }
public void HPDF_Error_Reset() { LibLogger.Debug(this.GetType(), "HPDF_Error_Reset"); Message = ""; ErrorNo = 0; DetailNo = 0; }
public HPDF_Error(string message = "", int id = 0, int detailNo = 0) { LibLogger.Error(this.GetType(), $"HPDF_Error message {message} id {id} detailNo {detailNo}"); Message = ""; ErrorNo = id; DetailNo = detailNo; }
public HPDF_Error() { LibLogger.Debug(this.GetType(), "ctor"); Message = ""; ErrorNo = 0; DetailNo = 0; }
public static HPDF_Annotation HPDF_LinkAnnot_New(HPDF_Xref xref, HPDF_Rect rect, HPDF_Destination dest) { LibLogger.Debug(MethodBase.GetCurrentMethod().DeclaringType, "HPDF_LinkAnnot_New"); HPDF_Annotation annot = new HPDF_Annotation(xref, (uint)HPDF_AnnotType.HPDF_ANNOT_LINK, rect); annot.HPDF_Dict_Add("Dest", dest); return(annot); }
public HPDF_Doc(Func <string> userErrorFunc = null, object userData = null) { LibLogger.Debug(this.GetType(), "ctor"); PdfVersion = (int)HPDF_PdfVer.HPDF_VER_13; sigBytes = HPDF_SIG_BYTES; CompressionMode = HPDF_Consts.HPDF_COMP_NONE; HPDF_NewDoc(); }
public int HPDF_SetError(int errorNo, int detailNo, string message = "") { LibLogger.Debug(this.GetType(), $"HPDF_SetError errorNo {errorNo} detailNo {detailNo} message {message}"); ErrorNo = 0; DetailNo = 0; Message = message; return(ErrorNo); }
public HPDF_Catalog(HPDF_Xref xref) { LibLogger.Debug(this.GetType(), "HPDF_Catalog"); Header.ObjClass |= HPDF_Obj_Header.HPDF_OSUBCLASS_CATALOG; xref.HPDF_Xref_Add(this); HPDF_Dict_AddName("Type", "Catalog"); HPDF_Dict_Add("Pages", new HPDF_Pages(null, xref)); }
private uint HPDF_MD5STEP(Func <uint, uint, uint, uint> f, uint w, uint x, uint y, uint z, uint data, uint s) { LibLogger.Debug(this.GetType(), "HPDF_MD5STEP"); uint ff = f(x, y, z); uint ret = w + ff + data; //ret = ret << s | ret >>> (32 - s); //ret += x; return(ret); }
public void HPDF_MD5Init() { LibLogger.Debug(this.GetType(), "HPDF_MD5Init"); buf[0] = 0x67452301; buf[1] = 0xefcdab89; buf[2] = 0x98badcfe; buf[3] = 0x10325476; bits[0] = 0; bits[1] = 0; }
public void HPDF_Dict_Add(string key, HPDF_Object obj) { LibLogger.Debug(this.GetType(), $"HPDF_Dict_Add key {key} obj.Header.ObjId {obj.Header.ObjId}"); HPDF_Obj_Header header = obj.Header; HPDF_DictElement element; if ((header.ObjId & HPDF_Obj_Header.HPDF_OTYPE_DIRECT) != 0) { Error = new HPDF_Error("HPDF_Dict_Add line - invalid object", HPDF_Error.HPDF_INVALID_OBJECT, 0); } if (key == null) { Error = new HPDF_Error("HPDF_Dict_Add line - invalid object", HPDF_Error.HPDF_INVALID_OBJECT, 0); } if (List.Count >= HPDF_Consts.HPDF_LIMIT_MAX_DICT_ELEMENT) { LibLogger.Debug(this.GetType(), " HPDF_Dict_Add exceed limitatin of dict count(" + HPDF_Consts.HPDF_LIMIT_MAX_DICT_ELEMENT.ToString() + ")"); Error = new HPDF_Error("HPDF_Dict_Add line - invalid object", HPDF_Error.HPDF_DICT_COUNT_ERR, 0); } /* check whether there is an object which has same name */ element = GetElement(key); if (element != null) { element.Value = null; } else { element = new HPDF_DictElement { Key = key, Value = null }; List.Add(element); } if ((header.ObjId & HPDF_Obj_Header.HPDF_OTYPE_INDIRECT) != 0) { var proxy = new HPDF_Proxy(obj); element.Value = proxy; proxy.Header.ObjId |= HPDF_Obj_Header.HPDF_OTYPE_DIRECT; } else { element.Value = obj; header.ObjId |= HPDF_Obj_Header.HPDF_OTYPE_DIRECT; } }
public HPDF_Dict() { LibLogger.Debug(this.GetType(), "ctor"); Header = new HPDF_Obj_Header { ObjClass = HPDF_Obj_Header.HPDF_OCLASS_DICT }; List = new List <HPDF_DictElement>(); Filter = HPDF_Stream.HPDF_STREAM_FILTER_NONE; Error = new HPDF_Error(); }
public override double measureTextFn(HPDF_Font font, string text, uint len, double width, double fontSize, double charSpace, double wordSpace, bool wordwrap, C_NumberPointer realWidth) { LibLogger.Debug(this.GetType(), "HPDF_TTFont_MeasureText"); return(0); //double w = 0; //uint tmpLen = 0; //uint i; //for (i = 0; i < len; i++) //{ // uint b = text.ToCharArray()[i]; // // use encoder // if (encoder!=null) // b = encoder.unicodeToByte(b); // if (HPDF_Utils.HPDF_IS_WHITE_SPACE(b)) // { // tmpLen = i + 1; // if (realWidth!=null) // realWidth.Value = w; // w += wordSpace; // } // else if (!wordwrap) // { // tmpLen = i; // if (realWidth != null) // realWidth.Value = w; // } // w += font.CharWidth(b) * fontSize / 1000; // /* 2006.08.04 break when it encountered line feed */ // if (w > width || b == 0x0A) // return tmpLen; // if (i > 0) // w += charSpace; //} ///* all of text can be put in the specified width */ //if (realWidth != null) // realWidth.Value = w; //return len; }
public void HPDF_Obj_WriteValue(HPDF_Object obj, HPDF_Encrypt e) { LibLogger.Debug(this.GetType(), "HPDF_Obj_WriteValue"); HPDF_Obj_Header header = obj.Header; var clas = header.ObjClass & HPDF_Obj_Header.HPDF_OCLASS_ANY; switch (clas) { case HPDF_Obj_Header.HPDF_OCLASS_NAME: HPDF_Name_Write(obj as HPDF_Name); break; case HPDF_Obj_Header.HPDF_OCLASS_NUMBER: HPDF_Number_Write(obj as HPDF_Number); break; case HPDF_Obj_Header.HPDF_OCLASS_REAL: HPDF_Real_Write(obj as HPDF_Real); break; case HPDF_Obj_Header.HPDF_OCLASS_STRING: HPDF_String_Write(obj as HPDF_String, e); break; case HPDF_Obj_Header.HPDF_OCLASS_BINARY: HPDF_Binary_Write(obj as HPDF_Binary, e); break; case HPDF_Obj_Header.HPDF_OCLASS_ARRAY: HPDF_Array_Write(obj as HPDF_Array, e); break; case HPDF_Obj_Header.HPDF_OCLASS_DICT: HPDF_Dict_Write(obj as HPDF_Dict, e); break; case HPDF_Obj_Header.HPDF_OCLASS_BOOLEAN: HPDF_Boolean_Write(obj as HPDF_Boolean); break; case HPDF_Obj_Header.HPDF_OCLASS_NULL: HPDF_Stream_WriteStr("null"); break; default: Error = new HPDF_Error("HPDF_Obj_WriteValue", HPDF_Error.HPDF_ERR_UNKNOWN_CLASS, 0); break; } }
public void HPDF_FreeDoc() { LibLogger.Debug(this.GetType(), "HPDF_FreeDoc"); Error = new HPDF_Error(); if (Xref != null) { Xref.HPDF_Xref_Free(); Xref = null; } PdfVersion = (int)HPDF_PdfVer.HPDF_VER_13; }
public HPDF_DictElement GetElement(string key) { LibLogger.Debug(this.GetType(), $"GetElement key {key}"); for (int i = 0; i < List.Count; i++) { var el = List[i]; if (el.Key == key) { return(el); } } return(null); }
public int HPDF_List_Find(object item) { LibLogger.Debug(this.GetType(), " HPDF_List_Find"); for (int i = 0; i < Obj.Count; i++) { if (Obj[i] == item) { return(i); } } return(-1); }
private int CharWidth(HPDF_Font font, int code) { LibLogger.Debug(this.GetType(), "CharWidth"); //if ( this.used[code] == 0 ) // { // uint unicode = encoder.HPDF_Encoder_ToUnicode(code); // used[code] = 1; // widths[code] = fontdef.HPDF_TTFontDef_GetCharWidth(unicode); // } //return widths[code]; return(0); }
public HPDF_Pages(HPDF_Pages parent, HPDF_Xref xref) { LibLogger.Debug(this.GetType(), "HPDF_Pages"); Header.ObjClass |= HPDF_Obj_Header.HPDF_OSUBCLASS_PAGES; xref.HPDF_Xref_Add(this); HPDF_Dict_AddName("Type", "Pages"); HPDF_Dict_Add("Kids", new HPDF_Array()); HPDF_Dict_Add("Count", new HPDF_Number(0)); if (parent != null) { parent.HPDF_Pages_AddKids(this); } }
public static HPDF_BuiltinEncodingData HPDF_BasicEncoder_FindBuiltinData(string encodingName) { uint i = 0; LibLogger.Debug(MethodBase.GetCurrentMethod().DeclaringType, " HPDF_BasicEncoder_FindBuiltinData"); while (HPDF_BUILTIN_ENCODINGS[i].EncodingName != null) { if (HPDF_BUILTIN_ENCODINGS[i].EncodingName == encodingName) { break; } i++; } return(HPDF_BUILTIN_ENCODINGS[i]); }
public HPDF_Annotation HPDF_URILinkAnnot_New(HPDF_Xref xref, HPDF_Rect rect, string uri) { LibLogger.Debug(this.GetType(), "HPDF_URILinkAnnot_New"); HPDF_Annotation annot; HPDF_Dict action; annot = new HPDF_Annotation(xref, (uint)HPDF_AnnotType.HPDF_ANNOT_LINK, rect); /* create action dictionary */ action = new HPDF_Dict(); annot.HPDF_Dict_Add("A", action); action.HPDF_Dict_AddName("Type", "Action"); action.HPDF_Dict_AddName("S", "URI"); action.HPDF_Dict_Add("URI", new HPDF_String(uri, null)); return(annot); }
public double HPDF_Xref_Free() { LibLogger.Debug(this.GetType(), "HPDF_Xref_Free"); HPDF_Xref lxref = this; while (lxref != null) { /* delete all objects belong to the xref. */ if (lxref.Entries.Count > 0) { for (int i = 0; i < lxref.Entries.Count; i++) { var entry = lxref.HPDF_Xref_GetEntry(i); if (entry.Obj != null) { //HPDF_Obj_ForceFree (xref->mmgr, entry->obj); entry.Obj = null; } // HPDF_FreeMem (xref->mmgr, entry); } ///HPDF_List_Free(xref->entries); lxref.Entries = null; } if (lxref.Trailer != null) { // HPDF_Dict_Free (xref->trailer); lxref.Trailer = null; } var tmpXref = lxref.Prev; //HPDF_FreeMem (xref->mmgr, xref); lxref = null; lxref = tmpXref; } return(HPDF_Consts.HPDF_OK); }