📄 dynamic_text_ins.c.svn-base
字号:
#include "base_types.h"#include "config.h"#include "define.h"#include "movie_clips_def.h"#include "swf_file_pub.h"#include "dynamic_text_def.h"#include "static_text_def.h"#include "dynamic_text_ins.h"#include "swf_file_pub.h"#include "instance.h"#include "font_def.h"#include <glib.h>#include <stdio.h>#include <string.h>#include <math.h>#include <wchar.h>#include <stdlib.h>#include <sys/types.h>#include <iconv.h>#include <ft2build.h>#include FT_FREETYPE_H#include FT_GLYPH_H#include FT_OUTLINE_H#include FT_BBOX_H#include <assert.h>#if WITH_DMALLOC#include <dmalloc.h>#endif#define PRINT_DG#define OUTLEN 1024struct Globle_Var { uint32_t tmpCode[OUTLEN]; double scale ; int Gx ; int Gy ; int yAxis ; int *Gadvance; int MyNum ; int Mytmp ; struct ShapeRecord *headRec,*endRec; struct ShapeRecord **MyRecA; struct DefineText GlobleText;} ;/* from this function,we can call FT_Outline_Decompose function to get the glyph shape * the func call four funcs such as handle_move_to,handle_line_to,handle_conic_to,handle_cubic_to */void draw_outline (FT_OutlineGlyph glyph,struct Globle_Var *Globle_VarP);// translate the size to EM sizedouble floatify (FT_Pos x,struct Globle_Var *Globle_VarP);// get the glyph move to point and sign it to the globle shape recordint handle_move_to (FT_Vector *to, void *user);// get the glyph line to point and sign it to the globle shape recordint handle_line_to (FT_Vector *to, void *user);// get the glyph conic to point and sign it to the globle shape recordint handle_conic_to (FT_Vector *control, FT_Vector *to, void *user);// get the glyph cubic to point and trans it to conic point then sign it to the globle shape recordint handle_cubic_to (FT_Vector *control1, FT_Vector *control2, FT_Vector *to, void *user);// init the Gloable MyRecord Array to save the Edit Text recordvoid initMyRecA(struct Globle_Var *Globle_VarP);// delete the Gloable MyRecord Array to free spacevoid freeMyRecA(struct Globle_Var *Globle_VarP);// init the temp recordvoid initRec(struct Globle_Var *Globle_VarP);//void freeRec(struct Globle_Var *Globle_VarP);void freeDefineText(struct DefineText *data);void freeDefineShape(struct DefineShape *data);void freeFillStyle(struct FillStyle *data);//get the bounds shape recordint getTextBounds(GNode* node_p,struct TextRecord *outRecordP);//get the cursor shape recordint getCursor(GNode* node_p,struct TextRecord *outRecordP,long x,long y);//draw the bounds and cursor shape recordint drawTextBounds(GNode* node_p,struct Globle_Var *Globle_VarP);//when the input string is HTML,decompose it and get the body stringint DecomposeHTML(char *str);/* * use iconv func to translate the charactor code from UTF-8 to UTF-32 */int code_convert(char *from_charset,char *to_charset,char *inbuf,int inlen,char *outbuf,int outlen);/* * according to the input string, use the simsun font, find out the right glyph shape record * then save them to the globle shape record as device glyph shape. */int FontToShape(GNode* node_p,struct Globle_Var *Globle_VarP);//int TextToShape(struct DefineEditText* intext,struct ShapeRecord* outText);//deal with glyph fontint EmbedtoShape(GNode* node_p,struct Globle_Var *Globle_VarP);//deal with device text shape record arrayint DevicetoShape(GNode* node_p,struct Globle_Var *Globle_VarP);void PrnShapeRec(struct ShapeRecord* mc) { struct ShapeRecord *tmp; struct StraightEdgeRecord *SER; struct CurvedEdgeRecord *CER; struct StyleChangeRecord *SCR; while(mc) { if(mc->Flags&StateMoveTo) { SCR = (struct StyleChangeRecord *)mc; printf("the Shape Change Record -----Flags is %d\n",SCR->Flags); printf("the Shape Change Record -----MoveDeltaX is %ld\n",SCR->MoveDeltaX); printf("the Shape Change Record -----MoveDeltaY is %ld\n",SCR->MoveDeltaY); printf("the Shape Change Record -----FillStyle0 is %ld\n",SCR->FillStyle0); printf("the Shape Change Record -----FillStyle1 is %ld\n",SCR->FillStyle1); printf("the Shape Change Record -----LineStyle is %ld\n",SCR->LineStyle); printf("the Shape Change Record -----FillStylesP is %p\n",SCR->FillStylesP); printf("the Shape Change Record -----LineStylesP is %p\n",SCR->LineStylesP); printf("the Shape Change Record -----NumFillBits is %ld\n",SCR->NumFillBits); printf("the Shape Change Record -----NumLineBits is %ld\n",SCR->NumLineBits); } if(mc->Flags==TStraightEdge) { SER = (struct StraightEdgeRecord *)mc; printf("the Shape StraightEdge Record -----Flags is %d\n",SER->Flags); printf("the Shape StraightEdge Record -----StraightLineFlag is %d\n",SER->StraightLineFlag); printf("the Shape StraightEdge Record -----StraightLineDeltaX is %ld\n",SER->StraightLineDeltaX); printf("the Shape StraightEdge Record -----StraightLineDeltaY is %ld\n",SER->StraightLineDeltaY); printf("the Shape StraightEdge Record -----VertLineFlag is %d\n",SER->VertLineFlag); printf("the Shape StraightEdge Record -----HorLineDeltaX is %ld\n",SER->HorLineDeltaX); printf("the Shape StraightEdge Record -----VertLineDeltaY is %ld\n",SER->VertLineDeltaY); } if(mc->Flags==TCurvedEdge) { CER = (struct CurvedEdgeRecord *)mc; printf("the Shape CurvedEdge Record -----Flags is %d\n",CER->Flags); printf("the Shape CurvedEdge Record -----ControlDeltaX is %ld\n",CER->ControlDeltaX); printf("the Shape CurvedEdge Record -----ControlDeltaY is %ld\n",CER->ControlDeltaY); printf("the Shape CurvedEdge Record -----AnchorDeltaX is %ld\n",CER->AnchorDeltaX); printf("the Shape CurvedEdge Record -----AnchorDeltaY is %ld\n",CER->AnchorDeltaY); } tmp = mc; mc = tmp->NextP; }}void PrnTextRecord(struct TextRecord* mc) { struct TextRecord *tmp; int i; while(mc) { tmp = mc; printf("the TextRecord Record -----GlyphCount is %d\n",mc->GlyphCount); printf("the TextRecord Record -----GlyphEntries is %p\n",mc->GlyphEntries); for(i=0; i<mc->GlyphCount; i++) { printf("------------------------------------the TextRecord Record -----number is %d\n",i); PrnShapeRec(mc->GlyphEntries[i].Shape.ShapeRecordsP); } mc = tmp->NextP; }}void PrnDefineText(struct DefineText* mc) { printf("the DefineText Record -----CharacterType is %d\n",mc->CharacterType); printf("the DefineText Record -----CharacterID is %d\n",mc->CharacterID); printf("the DefineText Record -----TextRecordsP is %p\n",mc->TextRecordsP); PrnTextRecord(mc->TextRecordsP);}void dtx_ins_change(GNode* node_p,struct PlaceObject *cmd_p) { // dtx_ins_t *data_p = (dtx_ins_t*)(node_p->data);#ifdef PRINT_DG fprintf(stderr,"=============dtx_ins_change start============\n");#endif dtx_update_shape(node_p);#ifdef PRINT_DG fprintf(stderr,"=============dtx_ins_change end============\n");#endif}static GNode *dtx_var_name_to_node_do(GNode* node_p,char** name_ary_p,int depth) { GNode *child = node_p; char *name_p = name_ary_p[depth]; if (name_ary_p[depth+1] == NULL) { while (child) { if ( (((dtx_ins_t*)(child->data))->ins_type == INS_DTX) && (((dtx_ins_t*)(child->data))->var_name_p != NULL)) { if (g_strcasecmp(((dtx_ins_t*)(child->data))->var_name_p,name_p)==0) { return child; }; }; child = child->next; }; return 0; } else { while (child) { if (((instance_t*)(child->data))->name_p != NULL) { if (g_strcasecmp(((instance_t*)(child->data))->name_p,name_p)==0) { return dtx_var_name_to_node_do(g_node_first_child(child),name_ary_p,depth+1); }; }; child = child->next; }; return 0; };};#define MAX_DEPTH 20GNode* dtx_var_name_to_node(GNode* node_p,const char* name_p) { char **str_array; GNode *p = NULL; str_array = g_strsplit(name_p,".",MAX_DEPTH); p = dtx_var_name_to_node_do(node_p,str_array,0); g_strfreev(str_array); return p;};char* dtx_get_var_full_name(GNode* node_p) { dtx_ins_t *data_p = (dtx_ins_t*)(node_p->data); GNode* p; char *n1_p = NULL , *n2_p = NULL; char *orig_name_p; orig_name_p = data_p->name_p; data_p->name_p = data_p->var_name_p; p = node_p; while (p) { n2_p = g_strjoin(".",((dtx_ins_t*)(p->data))->name_p,n1_p,NULL); if (n1_p) free(n1_p); n1_p = n2_p; p = p->parent; } data_p->name_p = orig_name_p; return n2_p;};/* * input DefineEditText ,according to it's flags to judge weather to use embeded font or device font. * then translate to DefineText ,draw the shape to it and put out * when the flag has EditTextUseOutlines ,then use glyph font ,otherwise use device font */void dtx_update_shape(GNode* node_p) { dtx_ins_t *data_p = (dtx_ins_t*)(node_p->data); swf_file_t *swf_p = data_p->swf_p; struct Globle_Var *Globle_VarP; struct DefineText *tmpText; data_p->value_p = dvar_get_value(data_p->var_full_name_p);#ifdef PRINT_DG fprintf(stderr,"value %s \n",data_p->value_p);#endif if(data_p->define_p->Flags&EditTextUseOutlines) {} else { freeDefineText(data_p->text_p); } free(data_p->text_p); data_p->text_p = NULL; //printf("\n --------------------------data_p->value_p is : %s \n",data_p->value_p); Globle_VarP = (struct Globle_Var *)malloc(sizeof(struct Globle_Var)); bzero((void *)(Globle_VarP),sizeof(struct Globle_Var)); Globle_VarP->yAxis = -1; tmpText = (struct DefineText *)malloc(sizeof(struct DefineText )); bzero((void *)(tmpText),sizeof(struct DefineText)); data_p->text_p =tmpText; drawTextBounds((GNode*)node_p,Globle_VarP); if(data_p->define_p->Flags&EditTextUseOutlines) {#ifdef PRINT_DG fprintf(stderr,"=============EmbedtoShape============\n");#endif EmbedtoShape((GNode*)node_p,Globle_VarP); } else { if(data_p->define_p->Flags&EditTextHTML) {} else {#ifdef PRINT_DG fprintf(stderr,"=============DevicetoShape============\n");#endif FontToShape((GNode*)node_p,Globle_VarP); DevicetoShape((GNode*)node_p,Globle_VarP); } } Globle_VarP->GlobleText.CharacterType = CharText; Globle_VarP->GlobleText.TextBounds = data_p->define_p->Bounds; Globle_VarP->GlobleText.GlyphBits = 0; Globle_VarP->GlobleText.AdvanceBits = 0; // data_p->shape->CharacterType = CharText; // data_p->shape->TextBounds = data_p->define_p->Bounds; // data_p->shape->GlyphBits = 0; // data_p->shape->AdvanceBits = 0; // PrnDefineText(&Globle_VarP->GlobleText); *data_p->text_p = Globle_VarP->GlobleText; free(Globle_VarP); //printf("-----------------data_p->shape is : %p \n",data_p->shape );}int EmbedtoShape(GNode* node_p,struct Globle_Var *Globle_VarP) { struct DefineFont *Font; struct TextRecord *headTextRecordP,*endTextRecordP; struct TextRecord *TextRecordP; struct TextRecord *tmpHeadTextRecordP; // struct TextRecord *TextBoundP; struct TextRecord *CursorP; // struct ShapeArray *p; struct Matrix TextMatrix; struct Matrix FontMatrix; long x,y; int CurPos =0; long CurX,CurY; int showCur = 1; int row = 0,rownum = 0; long Textlen = 0; long *TextAlign; long FontHeight=0; UI16 MaxLength =0; char* src_str; unsigned char out[OUTLEN]; int rc; int i =0,j=0,outlen =OUTLEN ; uint32_t code[OUTLEN]; int n =0,num=0; struct GlyphEntry *g_p ; struct DefineEditText *Text; dtx_ins_t *data_p = (dtx_ins_t*)(node_p->data); x=y=0; showCur = data_p->focusd; src_str = data_p->value_p; Text = data_p->define_p; if (!src_str) { // Globle_VarP->GlobleText.TextRecordsP = NULL; return 0; } rc = code_convert("utf-8","utf-32",src_str,strlen(src_str),out,outlen); if(rc == 0) { for(i=0,j=0;;i=i+4,j++) { if(out[i]=='\0'&&out[i+1]=='\0'&&out[i+2]=='\0'&&out[i+3]=='\0') break; if(i+4>OUTLEN) break; code[j] = out[i]<<24|out[i+1]<<16 |out[i+2]<<8|out[i+3]; } } else { // Globle_VarP->GlobleText.TextRecordsP = NULL; return 0; } if (j==0) { // Globle_VarP->GlobleText.TextRecordsP = NULL; return 0; } Font = (struct DefineFont *)data_p->swf_p->dict_p->dict[Text->FontID]; if(Text->Flags&EditTextHasMaxLength) MaxLength = Text->MaxLength; headTextRecordP = NULL; endTextRecordP = NULL; num = 0; for(i=1;i<j;i++) { if(Text->Flags&EditTextHasMaxLength) { if(i > MaxLength) break; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -