⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 text.c

📁 一个用于智能手机的多媒体库适合S60 WinCE的跨平台开发库
💻 C
📖 第 1 页 / 共 3 页
字号:
		/*free unicode buffer*/		free(lines[i].wcText);	}	/*free remaining unicode buffers*/	for (; i < txt->string.count; i++) free(lines[i].wcText);	free(lines);	st->bounds.width = final.width;	st->bounds.x = final.x;}static void Text_SetupBounds(RenderEffect3D *eff, TextStack *st){	CachedTextLine *tl;	u32 i;	/*text is not splitted, handle as a whole node*/	if (!eff->text_split_mode) {		if (eff->parent) group_end_text_child(eff->parent, &st->bounds, st->ascent, st->descent, 0);		gf_bbox_from_rect(&eff->bbox, &st->bounds);		return;	}	assert(eff->parent);	/*otherwise notify each node as a different group*/	i=0;	while ((tl = (CachedTextLine *)gf_list_enum(st->text_lines, &i))) {		/*the first one is always started by parent group*/		if (i>1) group_start_child(eff->parent, NULL);		group_end_text_child(eff->parent, &tl->bounds, st->ascent, st->descent, i);	}}static void Text_FillTextLine(RenderEffect3D *eff, CachedTextLine *tl){	if (!tl->mesh) {		tl->mesh = new_mesh();		mesh_from_path(tl->mesh, tl->path);	}	VS3D_DrawMesh(eff, tl->mesh);}static void Text_StrikeTextLine(RenderEffect3D *eff, CachedTextLine *tl, Aspect2D *asp, Bool vect_outline){	if (!tl->outline_mesh) {		tl->outline_mesh = new_mesh();#ifndef GPAC_USE_OGL_ES		if (vect_outline) {			if (!tl->outline) tl->outline = gf_path_get_outline(tl->path, asp->pen_props);			TesselatePath(tl->outline_mesh, tl->outline, asp->txh ? 2 : 1);		} else {			mesh_get_outline(tl->outline_mesh, tl->path);		}#else		/*VECTORIAL TEXT OUTLINE NOT SUPPORTED ON OGL-ES AT CURRENT TIME*/		vect_outline = 0;		mesh_get_outline(tl->outline_mesh, tl->path);#endif	}	if (vect_outline) {		VS3D_DrawMesh(eff, tl->outline_mesh);	} else {		VS3D_StrikeMesh(eff, tl->outline_mesh, Aspect_GetLineWidth(asp), asp->pen_props.dash);	}}static void Text_Draw(RenderEffect3D *eff, TextStack *st){	u32 i;	Aspect2D asp;	const char *fs_style;	char *hlight;	SFColorRGBA hl_color;	CachedTextLine *tl;	Bool draw2D, draw3D, vect_outline, can_texture_text;	Render3D *sr = (Render3D*)st->compositor->visual_renderer->user_priv;	M_FontStyle *fs = (M_FontStyle *) ((M_Text *) st->owner)->fontStyle;	vect_outline = !sr->raster_outlines;	VS3D_SetState(eff->surface, F3D_BLEND, 0);	/*get material, check if 2D or 3D drawing shall be used*/	if (!VS_GetAspect2D(eff, &asp)) {		draw2D = 0;		draw3D = VS_SetupAppearance(eff);	} else {		draw3D = 0;		draw2D = (asp.filled && asp.alpha) ? 1 : 0;		hl_color = gf_sg_sfcolor_to_rgba(asp.fill_color);	}	fs_style = FSSTYLE;	hlight = NULL;	hlight = strstr(fs_style, "HIGHLIGHT");	if (hlight) hlight = strchr(hlight, '#');	if (hlight && (draw2D || draw3D) ) {		hlight += 1;		/*reverse video: highlighting uses the text color, and text color is inverted (except alpha channel)		the ideal impl would be to use the background color for the text, but since the text may be 		displayed over anything non uniform this would require clipping the highlight rect with the text		which is too onerous (and not supported anyway) */		if (!strnicmp(hlight, "RV", 2)) {			if (draw3D) {				if (eff->appear) {					SFColor c, rc;					c = ((M_Material *) ((M_Appearance *)  eff->appear)->material)->diffuseColor;					hl_color = gf_sg_sfcolor_to_rgba(c);					hl_color.alpha = ((M_Material *) ((M_Appearance *)  eff->appear)->material)->transparency;					/*invert diffuse color and resetup*/					rc.red = FIX_ONE - c.red;					rc.green = FIX_ONE - c.green;					rc.blue = FIX_ONE - c.blue;					((M_Material *) ((M_Appearance *)  eff->appear)->material)->diffuseColor = rc;					VS_SetupAppearance(eff);					((M_Material *) ((M_Appearance *)  eff->appear)->material)->diffuseColor = c;				} else {					hl_color.red = hl_color.green = hl_color.blue = 0;					hl_color.alpha = FIX_ONE;				}			} else {				hl_color = gf_sg_sfcolor_to_rgba(asp.fill_color);				if (asp.alpha) {					asp.fill_color.red = FIX_ONE - asp.fill_color.red;					asp.fill_color.green = FIX_ONE - asp.fill_color.green;					asp.fill_color.blue = FIX_ONE - asp.fill_color.blue;				}			}		} else {			u32 hlc;			sscanf(hlight, "%x", &hlc);			hl_color.alpha = INT2FIX(GF_COL_A(hlc)) / 255;			hl_color.red = INT2FIX(GF_COL_R(hlc)) / 255;			hl_color.green = INT2FIX(GF_COL_G(hlc)) / 255;			hl_color.blue = INT2FIX(GF_COL_B(hlc)) / 255;		}		if (asp.alpha == 0) hlight = NULL;	}	if (strstr(fs_style, "TEXTURED")) st->texture_text_flag = 1;	/*setup texture*/	VS_setup_texture(eff);	can_texture_text = 0;	if (draw2D || draw3D) {		/*check if we can use text texturing*/		if (sr->compositor->texture_text_mode || st->texture_text_flag) {			if (draw2D && asp.pen_props.width) {				can_texture_text = 0;			} else {				can_texture_text = eff->mesh_has_texture ? 0 : 1;			}		}	}	VS3D_SetAntiAlias(eff->surface, st->compositor->antiAlias);	if (draw2D || draw3D || eff->mesh_has_texture) {		if (draw2D) VS3D_SetMaterial2D(eff->surface, asp.fill_color, asp.alpha);		if (eff->split_text_idx) {			tl = (CachedTextLine *)gf_list_get(st->text_lines, eff->split_text_idx-1);			assert(tl);			if (hlight) {				VS3D_FillRect(eff->surface, tl->bounds, hl_color);				if (draw2D) VS3D_SetMaterial2D(eff->surface, asp.fill_color, asp.alpha);				else VS_SetupAppearance(eff);			}			if (can_texture_text && TextLine_TextureIsReady(tl)) {				eff->mesh_has_texture = 1;				tx_enable(&tl->txh, NULL);				VS3D_DrawMesh(eff, tl->tx_mesh);				tx_disable(&tl->txh);				/*be nice to GL, we remove the text from HW at each frame since there may be a lot of text*/				R3D_TextureHWReset(&tl->txh);			} else {				Text_FillTextLine(eff, tl);			}		} else {			i=0; 			while ((tl = (CachedTextLine *)gf_list_enum(st->text_lines, &i))) {				if (hlight) {					VS3D_FillRect(eff->surface, tl->bounds, hl_color);					if (draw2D) VS3D_SetMaterial2D(eff->surface, asp.fill_color, asp.alpha);					else VS_SetupAppearance(eff);				}				if (can_texture_text && TextLine_TextureIsReady(tl)) {					eff->mesh_has_texture = 1;					tx_enable(&tl->txh, NULL);					VS3D_DrawMesh(eff, tl->tx_mesh);					tx_disable(&tl->txh);					/*be nice to GL, we remove the text from HW at each frame since there may be a lot of text*/					R3D_TextureHWReset(&tl->txh);				} else {					Text_FillTextLine(eff, tl);				}			}		}		/*reset texturing in case of line texture*/		VS_disable_texture(eff);	}	VS3D_SetState(eff->surface, F3D_BLEND, 0);	if (!draw3D && asp.pen_props.width) {		Fixed w = asp.pen_props.width;		asp.pen_props.width = gf_divfix(asp.pen_props.width, asp.line_scale);		VS_Set2DStrikeAspect(eff, &asp);		if (eff->split_text_idx) {			tl = (CachedTextLine *)gf_list_get(st->text_lines, eff->split_text_idx-1);			Text_StrikeTextLine(eff, tl, &asp, vect_outline);		} else {			i=0;			while ((tl = (CachedTextLine *)gf_list_enum(st->text_lines, &i))) {				Text_StrikeTextLine(eff, tl, &asp, vect_outline);			}		}		asp.pen_props.width = w;	}}static void Text_Render(GF_Node *n, void *rs, Bool is_destroy){	M_Text *txt = (M_Text *) n;	TextStack *st = (TextStack *) gf_node_get_private(n);	RenderEffect3D *eff = (RenderEffect3D *)rs;	if (is_destroy) {		clean_paths(st);		stack2D_predestroy((stack2D *)st);		gf_list_del(st->text_lines);		free(st);		return;	}	if (!st->compositor->font_engine) return;	if (!txt->string.count) return;	/*check for geometry change*/	if (gf_node_dirty_get(n)) {		clean_paths(st);		stack2D_reset((stack2D *) st);		gf_node_dirty_clear(n, 0);		if (eff->text_split_mode == 2) {			split_text_letters(st, txt, eff);		} else if (eff->text_split_mode == 1) {			split_text_words(st, txt, eff);		} else {			BuildTextGraph(st, txt, eff);		}		/*that's the largest bounds of the text in normal display - store it for culling*/		gf_bbox_from_rect(&st->mesh->bounds, &st->bounds);	}	/*drawing*/	if (!eff->traversing_mode) {		Text_Draw(eff, st);	}	/*getting bounds info*/	else if (eff->traversing_mode==TRAVERSE_GET_BOUNDS) {		Text_SetupBounds(eff, st);	}}static Bool TextIntersectWithRay(GF_Node *owner, GF_Ray *ray, SFVec3f *outPoint){	TextStack *st = (TextStack*)gf_node_get_private(owner);	u32 i;	CachedTextLine *tl;	if (!R3D_Get2DPlaneIntersection(ray, outPoint)) return 0;	i=0;	while ((tl = (CachedTextLine *)gf_list_enum(st->text_lines, &i))) {			if ( (outPoint->x >= tl->bounds.x) 		&& (outPoint->y <= tl->bounds.y) 		&& (outPoint->x <= tl->bounds.x + tl->bounds.width)		&& (outPoint->y >= tl->bounds.y - tl->bounds.height) 		) return 1;	}	return 0;}void R3D_InitText(Render3D *sr, GF_Node *node){	TextStack *stack;	GF_SAFEALLOC(stack, TextStack);	stack2D_setup((stack2D *)stack, sr->compositor, node);	/*override all funct*/	stack->ascent = stack->descent = 0;	stack->text_lines = gf_list_new();	gf_node_set_private(node, stack);	gf_node_set_callback_function(node, Text_Render);	stack->IntersectWithRay = TextIntersectWithRay;}#include "mesh.h"void Text_Extrude(GF_Node *node, RenderEffect3D *eff, GF_Mesh *mesh, MFVec3f *thespine, Fixed creaseAngle, Bool begin_cap, Bool end_cap, MFRotation *spine_ori, MFVec2f *spine_scale, Bool txAlongSpine){	u32 i, count;	Fixed min_cx, min_cy, width_cx, width_cy;	CachedTextLine *tl;	TextStack *st = (TextStack *) gf_node_get_private(node);	/*rebuild text node*/	if (gf_node_dirty_get(node)) {		struct _parent_group *parent = eff->parent;		eff->parent = NULL;		clean_paths(st);		stack2D_reset((stack2D *) st);		gf_node_dirty_clear(node, 0);		BuildTextGraph(st, (M_Text *)node, eff);		eff->parent = parent;	}	min_cx = st->bounds.x;	min_cy = st->bounds.y - st->bounds.height;	width_cx = st->bounds.width;	width_cy = st->bounds.height;	mesh_reset(mesh);	count = gf_list_count(st->text_lines);	for (i=0; i<count; i++) {		tl = (CachedTextLine *)gf_list_get(st->text_lines, i);		mesh_extrude_path_ext(mesh, tl->path, thespine, creaseAngle, min_cx, min_cy, width_cx, width_cy, begin_cap, end_cap, spine_ori, spine_scale, txAlongSpine);	}	mesh_update_bounds(mesh);	gf_mesh_build_aabbtree(mesh);}static void RenderTextureText(GF_Node *node, void *rs, Bool is_destroy){	u32 ntag;	TextStack *stack;	GF_Node *text;	GF_FieldInfo field;	if (is_destroy) return;	if (gf_node_get_field(node, 0, &field) != GF_OK) return;	if (field.fieldType != GF_SG_VRML_SFNODE) return;	text = *(GF_Node **)field.far_ptr;	if (!text) return;	if (gf_node_get_field(node, 1, &field) != GF_OK) return;	if (field.fieldType != GF_SG_VRML_SFBOOL) return;	ntag = gf_node_get_tag(text);	if ((ntag != TAG_MPEG4_Text) && (ntag != TAG_X3D_Text)) return;	stack = (TextStack *) gf_node_get_private(text);	stack->texture_text_flag = *(SFBool*)field.far_ptr ? 1 : 0;}void R3D_InitTextureText(Render3D *sr, GF_Node *node){	gf_node_set_callback_function(node, RenderTextureText);}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -