📄 dynamic_text_ins.c.svn-base
字号:
for(n=0;n<Font->NumGlyphs;n++) { if(code[i]==Font->GlyphShape[n].Code) { num++; break; } } } bzero((void *)(&TextMatrix),sizeof(struct Matrix)); MatrixPrepare(&TextMatrix); bzero((void *)(&FontMatrix),sizeof(struct Matrix)); FontHeight=Text->FontHeight; FontMatrix.HasScale=1; FontMatrix.ScaleX=FontHeight/1024.0; FontMatrix.ScaleY=FontHeight/1024.0; TextRecordP = (struct TextRecord*)malloc(sizeof(struct TextRecord)+(num-1)*sizeof(struct GlyphEntry)); bzero((void *)TextRecordP,sizeof(struct TextRecord)+(num-1)*sizeof(struct GlyphEntry)); TextRecordP->Flags =StyleFlagsHasColor; TextRecordP->FontID =Text->FontID; TextRecordP->TextColor = Text->TextColor; TextRecordP->TextHeight = Text->FontHeight; TextRecordP->GlyphCount = num; //get text rows for(i=1;i<j;i++) { if(Text->Flags&EditTextHasMaxLength) { if(i > MaxLength) break; } if(Text->Flags&EditTextMultiline) { if(code[i]=='\r') { x=0; rownum++; } } if(Text->Flags&EditTextWordWrap) if((x+Font->GlyphShape[n].FontAdvance*(FontMatrix.ScaleX))>Text->Bounds.Xmax) { x=0; rownum++; } for(n=0;n<Font->NumGlyphs;n++) { if(code[i]==Font->GlyphShape[n].Code) { x+=Font->GlyphShape[n].FontAdvance*(FontMatrix.ScaleX); break; } } } TextAlign = (long *)malloc(sizeof(long)*(rownum+1)); bzero((void*)TextAlign,sizeof(long)*(rownum+1)); TextAlign[0] = 0; row = 0; if(Text->Flags&EditTextHasLayout) { for(i=1;i<j;i++) { if(Text->Flags&EditTextHasMaxLength) { if(i > MaxLength) break; } switch(Text->Align) { case 0: TextAlign[row] = 0; break; case 1: TextAlign[row] = Text->Bounds.Xmax - Textlen - Font->GlyphShape[n].FontAdvance*(FontMatrix.ScaleX)*0.5; break; case 2: TextAlign[row] = (Text->Bounds.Xmax - Textlen)/2; break; case 3: TextAlign[row] = 0; break; } if(Text->Flags&EditTextMultiline) { if(code[i]=='\r') { Textlen = 0; row++; } } if(Text->Flags&EditTextWordWrap) if((Textlen+Font->GlyphShape[n].FontAdvance*(FontMatrix.ScaleX))>Text->Bounds.Xmax) { Textlen = 0; row++; } for(n=0;n<Font->NumGlyphs;n++) { if(code[i]==Font->GlyphShape[n].Code) { Textlen+=Font->GlyphShape[n].FontAdvance*(FontMatrix.ScaleX); break; } } } } switch(Text->Align) { case 0: TextAlign[row] = 0; break; case 1: TextAlign[row] = Text->Bounds.Xmax - Textlen - Font->GlyphShape[n].FontAdvance*(FontMatrix.ScaleX)*0.5; break; case 2: TextAlign[row] = (Text->Bounds.Xmax - Textlen)/2; break; case 3: TextAlign[row] = 0; break; } num = 0; row = 0; y=Text->FontHeight; x=TextAlign[row]; CurPos = i+1; CurY=Text->FontHeight; CurX=TextAlign[row]; for(i=1;i<j;i++) { if(Text->Flags&EditTextHasMaxLength) { if(i > MaxLength) break; } if(Text->Flags&EditTextMultiline) { if(code[i]=='\r') { row++; x=TextAlign[row]; y+=Text->FontHeight; if(i<CurPos) { CurY+=Text->FontHeight; CurX=TextAlign[row]; } } } if(Text->Flags&EditTextWordWrap) if((x+Font->GlyphShape[n].FontAdvance*(FontMatrix.ScaleX))>Text->Bounds.Xmax) { row++; x=TextAlign[row]; y+=Text->FontHeight; if(i<CurPos) { CurY+=Text->FontHeight; CurX=TextAlign[row]; } } for(n=0;n<Font->NumGlyphs;n++) { if(code[i]==Font->GlyphShape[n].Code) { g_p = &(TextRecordP->GlyphEntries[num]); //printf("--------------the TextRecordP->GlyphEntries[%d] is %p \n",num,g_p); mat_new(&(g_p->GlyphMatrix)); g_p->GlyphMatrix.TranslateX = x; g_p->GlyphMatrix.TranslateY = y; g_p->GlyphMatrix.ScaleX = FontHeight/1024.0; g_p->GlyphMatrix.ScaleY = FontHeight/1024.0; g_p->Shape.CharacterType = CharShape; g_p->Shape.ShapeBounds = Font->GlyphShape[n].FontBounds; // p->TextShapes[num].Shape.ShapeBounds=Text->Bounds; g_p->Shape.ShapeRecordsP = Font->GlyphShape[n].ShapeRecordP; x+=Font->GlyphShape[n].FontAdvance*(FontMatrix.ScaleX); if(i<CurPos) { CurX+=Font->GlyphShape[n].FontAdvance*(FontMatrix.ScaleX); } num++; break; } } } // TextRecordP->ShapesP=p; headTextRecordP = TextRecordP; TextRecordP->NextP = NULL; endTextRecordP = TextRecordP; /* if(Text->Flags&EditTextBorder) { TextBoundP = (struct TextRecord*)malloc(sizeof(struct TextRecord)); bzero((void *)TextBoundP,(sizeof(struct TextRecord))); TextBoundP->Flags =StyleFlagsHasColor; TextBoundP->FontID =Text->FontID; TextBoundP->TextColor = Text->TextColor; TextBoundP->TextHeight = Text->FontHeight; TextBoundP->GlyphCount = 1; TextBoundP->GlyphEntries[0].Shape.FillStylesP = NULL; TextBoundP->GlyphEntries[0].Shape.LineStylesP = NULL; getTextBounds(node_p,TextBoundP); TextBoundP->NextP = NULL; endTextRecordP->NextP = TextBoundP; endTextRecordP = TextBoundP; } */ if(showCur) { showCur = 0; CursorP = (struct TextRecord*)malloc(sizeof(struct TextRecord)); bzero((void *)CursorP,(sizeof(struct TextRecord))); CursorP->Flags =StyleFlagsHasColor; CursorP->FontID =Text->FontID; CursorP->TextColor = Text->TextColor; CursorP->TextHeight = Text->FontHeight; CursorP->GlyphCount = 1; CursorP->GlyphEntries[0].Shape.FillStylesP = NULL; CursorP->GlyphEntries[0].Shape.LineStylesP = NULL; getCursor(node_p,CursorP,CurX,CurY); CursorP->NextP = NULL; endTextRecordP->NextP = CursorP; endTextRecordP = CursorP; } endTextRecordP->NextP = NULL; Globle_VarP->GlobleText.TextMatrix = TextMatrix; tmpHeadTextRecordP = Globle_VarP->GlobleText.TextRecordsP; if(tmpHeadTextRecordP) { while(tmpHeadTextRecordP->NextP) tmpHeadTextRecordP = tmpHeadTextRecordP->NextP; tmpHeadTextRecordP->NextP = headTextRecordP; } else { Globle_VarP->GlobleText.TextRecordsP = headTextRecordP; } // Globle_VarP->GlobleText.TextRecordsP->NextP = headTextRecordP; free(TextAlign); return 0;}int FontToShape(GNode* node_p,struct Globle_Var *Globle_VarP) { FT_Library library; FT_Face face; FT_UInt glyph_index; FT_Glyph glyph; UI16 MaxLength =0; char* filename; char* src_str; unsigned char out[OUTLEN]; int rc; int i=0,j=0,outlen =OUTLEN ; uint32_t code[OUTLEN]; struct DefineEditText *Text; dtx_ins_t *data_p = (dtx_ins_t*)(node_p->data);#ifdef PRINT_DG fprintf(stderr,"FontToShape start --- \n");#endif src_str = NULL; /* string */ Text = NULL; src_str = data_p->value_p; Text = data_p->define_p; // filename = "/usr/home/chenz/myfont/simsun.ttc"; filename = "simsun.ttc"; if (!src_str) return 0; if(Text->Flags&EditTextHasMaxLength) MaxLength = Text->MaxLength; 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]; Globle_VarP->tmpCode[j]=code[j]; } } else { return 0; } // freeMyRecA(Globle_VarP); // free(Globle_VarP->Gadvance); Globle_VarP->MyNum = j; if(Globle_VarP->MyNum==0) return 0; if(Text->Flags&EditTextHasMaxLength) { Globle_VarP->MyNum = j<=MaxLength ?j:(MaxLength+1); } Globle_VarP->Mytmp = 0; initMyRecA(Globle_VarP); Globle_VarP->Gadvance = (int*)malloc(sizeof(int)*Globle_VarP->MyNum); bzero((void *)(Globle_VarP->Gadvance),sizeof(FT_Pos)*Globle_VarP->MyNum); initRec(Globle_VarP); rc = FT_Init_FreeType( &library ); if(rc) { return 0; } rc = FT_New_Face( library,filename, 0, &face ); if(rc) { return 0; } FT_Set_Pixel_Sizes(face,1024,0); Globle_VarP->scale = (double)1024.0/face->units_per_EM; for(i=1;i<j;i++) { if(Text->Flags&EditTextHasMaxLength) { if(i > MaxLength) break; } initRec(Globle_VarP); /* retrieve glyph index from character code */ glyph_index = FT_Get_Char_Index( face, code[i]); /* load glyph image into the slot (erase previous one) */ FT_Load_Glyph( face, glyph_index, FT_LOAD_NO_SCALE ); FT_Get_Glyph(face->glyph, &glyph); draw_outline((FT_OutlineGlyph) glyph,Globle_VarP); Globle_VarP->Mytmp++; } FT_Done_Glyph(glyph); FT_Done_Face ( face ); FT_Done_FreeType( library );#ifdef PRINT_DG fprintf(stderr,"FontToShape end --- \n");#endif return 0;}voiddraw_outline (FT_OutlineGlyph glyph,struct Globle_Var *Globle_VarP) { FT_Outline_Funcs handlers; FT_Error err; FT_BBox bbox; err = FT_Outline_Get_BBox(&glyph->outline, &bbox); /* I have a feeling that the bounding box in an EPS is meant to only * use integer values, so I round them down and up as appropriate. */ handlers.move_to = handle_move_to; handlers.line_to = handle_line_to; handlers.conic_to = handle_conic_to; handlers.cubic_to = handle_cubic_to; handlers.shift = 0; handlers.delta = 0; Globle_VarP->Gadvance[Globle_VarP->Mytmp] = (int) ceil(floatify(bbox.xMax,Globle_VarP)) -(int) floor(floatify(bbox.xMin,Globle_VarP)) ; FT_Outline_Decompose(&glyph->outline, &handlers, (void *)Globle_VarP); if(Globle_VarP->endRec!=NULL) Globle_VarP->endRec->NextP = NULL; Globle_VarP->MyRecA[Globle_VarP->Mytmp] = Globle_VarP->headRec;}doublefloatify (FT_Pos x,struct Globle_Var *Globle_VarP) { double rc; rc = x*Globle_VarP->scale; return (double) rc;}inthandle_move_to (FT_Vector *to, void *user) { struct StyleChangeRecord *chg ; struct Globle_Var *Globle_VarP = (struct Globle_Var *)user; chg = (struct StyleChangeRecord*)malloc(sizeof(struct StyleChangeRecord)); bzero((void *)chg,sizeof(struct StyleChangeRecord)); Globle_VarP->Gx = floatify(to->x,Globle_VarP) ; Globle_VarP->Gy = floatify(to->y,Globle_VarP) *Globle_VarP->yAxis;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -