Exemplo n.º 1
0
 bool stash::add_font( const void *ptr, size_t size, const std::string &alias )
 {
     std::vector<unsigned char> data;
     data.resize( size );
     memcpy( &data[0], ptr, size );
     return add_font( data, alias );
 }
Exemplo n.º 2
0
litehtml::uint_ptr litehtml::document::get_font(const wchar_t* name, int size,
						const wchar_t* weight, const wchar_t* style,
						const wchar_t* decoration) {
     if (!name || name && !wcscmp(name, L"inherit")) {
	  name = m_font_name.c_str();
     }

     if (!size) {
	  size = container()->get_default_font_size();
     }

     // convert integer to wchar_t crossplatform way
     wchar_t strSize[20];
     swprintf(strSize, sizeof(strSize) / sizeof(*strSize), L"%d", size);

     std::wstring key = name;
     key += L":";
     key += strSize;
     key += L":";
     key += weight;
     key += L":";
     key += style;
     key += L":";
     key += decoration;

     fonts_map::iterator el = m_fonts.find(key);

     if (el != m_fonts.end()) {
	  return el->second;
     }
     return add_font(name, size, weight, style, decoration);
}
Exemplo n.º 3
0
 bool stash::add_font( const std::string &path, const std::string &alias )
 {
     std::vector<unsigned char> data;
     std::string content = moon9::file(path).read();
     data.resize( content.size() );
     std::copy( content.begin(), content.end(), data.begin() );
     return add_font( data, alias );
 }
Exemplo n.º 4
0
 int
 add_char (tree fn, string c) {
   //cout << "Add " << c << " to " << fn << "\n";
   add_font (fn, REWRITE_NONE);
   int nr= fn_nr [fn];
   if (starts (c, "<")) cht (c)= nr;
   else chv [(int) (unsigned char) c[0]]= nr;
   return nr;
 }
Exemplo n.º 5
0
xui_method_explain(xui_family_create_win, get_bits, void*			)( const xui_family& family, u16 wc )
{
	add_font(family);

	gdiinfo* info = m_gdiinfo_map[family.to_string()];

	//draw char
	SolidBrush brush(Color::White);
	info->gdig->SetTextRenderingHint(TextRenderingHintAntiAliasGridFit);
	info->gdig->Clear(Color(0));
	info->gdig->DrawString(
		(LPWSTR)(&wc), 
		1, 
		info->gdif, 
		PointF(0.0f,0.0f), 
		StringFormat::GenericTypographic(), 
		&brush);

	//char size
	RectF rect;
	info->gdig->MeasureString(
		(LPWSTR)(&wc), 
		1, 
		info->gdif, 
		PointF(0.0f, 0.0f), 
		StringFormat::GenericTypographic(), 
		&rect);

	info->size.w = (s32)ceilf(rect.Width ); 
	info->size.h = (s32)ceilf(rect.Height);

	if (info->size.w == 0)
		info->size.w =  family.size / 2;

	//copy buffer
	s32 w = info->size.w;
	s32 h = info->size.h;

	Color color;
	for (s32 y = 0; y < h; ++y)
	{
		for (s32 x = 0; x < w; ++x)
		{
			info->gdib->GetPixel(x, y, &color);
			info->bits[y*w+x] = color.GetAlpha();
		}
	}

	return info->bits;
}
Exemplo n.º 6
0
int parse_frame_entry(struct frame *pa)
{
int a, c, i, j, x, y, z;
char *token, *running;
struct frame *pb = 0;
struct object *po = 0;
double da, dx, dy;
double dgx, dgy, dgz;
int frame_nr;
char *cptr, *tptr;
int screen_lines;
int line_height;
char font_dir[4096];
char font_name[4096];
font_desc_t *pfd;
int temp_palette[16][3];
int text_start, max_width, line_len;
struct object *pf = 0;
struct object *pc;
int bg_height, bg_width;

if(debug_flag)
	{
	tc_log_msg(MOD_NAME,
	"subtitler(): parse_frame_entry():\n\
	pa->name=%s pa->type=%d\n\
	pa->end_frame=%d\n\
	pa->data=%lu",
	pa -> name,
	pa -> type,
	pa -> end_frame,
	(unsigned long)pa -> data);
	}

if(pa -> data[0] == '*')
	{
	/* parse the data line */
	running = strsave(pa -> data);
	if(! running)
		{
		tc_log_warn(MOD_NAME, "subtitler(): strsave(pa -> data) failed");

		return -1;
		}

	po = 0;
	while(1)
		{
		token = strsep (&running, " ");
		if(token == NULL) break;

		if(debug_flag)
			{
			tc_log_msg(MOD_NAME, "token=%s", token);
			}

		/* avoid empty string */
		if(token[0] == 0) continue;

		/* check for object reference */
		if(token[0] == '*')
			{
			/* recursive we are in our own list */
			pb = lookup_frame(token);
			if(! pb)
				{
				tc_log_msg(MOD_NAME,
				"subtitler(): undefined object referenced: %s ignoring",
				token);

				return 1;
//				exit(1);
				}

			/* get data for this object */
			if(debug_flag)
				{
//				tc_log_msg(MOD_NAME, "parser(): object %s data=%s", token, pb -> data);
				}

			/*
			add this object to the display list, if it is already there,
			we get a pointer to it.
			*/
			po = install_object_at_end_of_list(token);
			if(! po)
				{
				tc_log_msg(MOD_NAME,
				"subtitler(): parse_frame_entry():\n\
				could not install or find object %s in display list",\
				token);

				exit(1);
				}
			}
		else /* token[0] != 0, must be an argument */
			{
			/* modify arguments for display object */
			/*
			po must have been set in the preceeding argument in this
			line, so '11 *this vpos=5', but '11 vops=5 *this' will NOT work,
			and cause an error exit.
			*/
			if(! po)
				{
				tc_log_msg(MOD_NAME,
		"subtitler(): syntax error (object must be first), line reads:\n\
				%s", pa -> name);

				exit(1);
				}
			/* copy data if not there yet */
			if(! po -> data)
				{
				po -> type = pb -> type;
				po -> data = pb -> data;
				po -> org_xsize = (double) pb -> xsize;
				po -> org_ysize = (double) pb -> ysize;
				po -> org_zsize = (double) pb -> zsize;
				po -> xsize = (double) pb -> xsize;
				po -> ysize = (double) pb -> ysize;
				po -> zsize = (double) pb -> zsize;
				po -> id = pb -> id;

				po -> pfd = pb -> pfd;

				pa -> status = OBJECT_STATUS_NEW;

				/* set some defaults */
				po -> extra_character_space = extra_character_space;

				}

			/* parse line */
			sscanf(token, "de_stripe=%lf", &po -> de_stripe);
			sscanf(token, "show_output=%lf", &po -> show_output);

			sscanf(token, "xpos=%lf", &po -> xpos);
			sscanf(token, "ypos=%lf", &po -> ypos);
			sscanf(token, "zpos=%lf", &po -> zpos);

			sscanf(token, "dxpos=%lf", &po -> dxpos);
			sscanf(token, "dypos=%lf", &po -> dypos);
			sscanf(token, "dzpos=%lf", &po -> dzpos);

			a = sscanf(token, "xdest=%lf", &dgx);
			if(a) po -> status |= OBJECT_STATUS_HAVE_X_DEST;

			a = sscanf(token, "ydest=%lf", &dgy);
			if(a) po -> status |= OBJECT_STATUS_HAVE_Y_DEST;

			a = sscanf(token, "zdest=%lf", &dgz);
			if(a) po -> status |= OBJECT_STATUS_HAVE_Z_DEST;

			if(\
			(po -> status & OBJECT_STATUS_HAVE_X_DEST) ||\
			(po -> status & OBJECT_STATUS_HAVE_Y_DEST) ||\
			(po -> status & OBJECT_STATUS_HAVE_Z_DEST)\
			)
				{
				/* use current position if nothing specified */
				if(po -> status & OBJECT_STATUS_HAVE_X_DEST)
					{
					po -> xdest = dgx;
					}
				else
					{
					po -> xdest = po -> xpos;
					}

				if(po -> status & OBJECT_STATUS_HAVE_Y_DEST)
					{
					po -> ydest = dgy;
					}
				else
					{
					po -> ydest = po -> ypos;
					}

				if(! po -> status & OBJECT_STATUS_HAVE_Z_DEST)
					{
					po -> zdest = dgz;
					}
				else
					{
					po -> zdest = po -> zpos;
					}

				/* calculate a distance */
				/* x distance */
				dx = po -> xdest - po -> xpos;

				/*
				since the 'heading' calculation in object_list.c
				uses aspect correction, we have to to pre-correct here
				the other way around.
				*/
				dx *=\
				(double)image_height / (double)image_width;

				/* y distance */
				dy = po -> ydest - po -> ypos;

				/* true distance */
				po -> distance = sqrt( (dx * dx) + (dy * dy) );

				/* sine */
				da = dx / po -> distance;

				/* calculate a heading angle */
				errno = 0;
				po -> heading = asin(da);
				if(errno == EDOM)
					{
					tc_log_perror(MOD_NAME, "subtitler(): parse_frame_entry():\n\
					asin NOT A NUMBER :-)");

					exit(1);
					}

				/* flip y, x=0, y=0 is top left */
				dy = -1 * dy;

				/* if dy is negative, we move to the other 2 quadrants */
				if(dy < 0) po -> heading = M_PI - po -> heading;

				po -> heading *= 180.0 / M_PI;

				/* indicate we are on our way */
				po -> status |= OBJECT_STATUS_GOTO;

				/*
				in object list we will now each frame substract the
                travelled distance, until po -> distance is 0.
				Then we will reset the mode to NEW.
				*/
				} /* end if some x, y, or z dest */

			sscanf(token, "xrot=%lf", &po -> xrotation);
			sscanf(token, "yrot=%lf", &po -> yrotation);
			sscanf(token, "zrot=%lf", &po -> zrotation);

			sscanf(token, "dxrot=%lf", &po -> dxrotation);
			sscanf(token, "dyrot=%lf", &po -> dyrotation);
			sscanf(token, "dzrot=%lf", &po -> dzrotation);

			sscanf(token, "xshear=%lf", &po -> xshear);
			sscanf(token, "yshear=%lf", &po -> yshear);
			sscanf(token, "zshear=%lf", &po -> zshear);

			sscanf(token, "dxshear=%lf", &po -> dxshear);
			sscanf(token, "dyshear=%lf", &po -> dyshear);
			sscanf(token, "dzshear=%lf", &po -> dzshear);

			sscanf(token, "xsize=%lf", &po -> xsize);
			sscanf(token, "ysize=%lf", &po -> ysize);
			sscanf(token, "zsize=%lf", &po -> zsize);

			sscanf(token, "dxsize=%lf", &po -> dxsize);
			sscanf(token, "dysize=%lf", &po -> dysize);
			sscanf(token, "dzsize=%lf", &po -> dzsize);

			if(strncmp(token, "rsize", 5) == 0)
				{
				po -> xsize = po -> org_xsize;
				po -> ysize = po -> org_ysize;
				po -> zsize = po -> org_zsize;

				po -> dxsize = 0.0;
				po -> dysize = 0.0;
				po -> dzsize = 0.0;
				}

			sscanf(token, "heading=%lf", &po -> heading);
			sscanf(token, "dheading=%lf", &po -> dheading);

			sscanf(token, "speed=%lf", &po -> speed);
			sscanf(token, "dspeed=%lf", &po -> dspeed);
			sscanf(token, "ddspeed=%lf", &po -> ddspeed);

			sscanf(token, "transp=%lf", &po -> transparency);
			sscanf(token, "dtransp=%lf", &po -> dtransparency);

			sscanf(token, "sat=%lf", &po -> saturation);
			sscanf(token, "dsat=%lf", &po -> dsaturation);

			sscanf(token, "hue=%lf", &po -> hue);
			sscanf(token, "dhue=%lf", &po -> dhue);

			sscanf(token, "hue_ldrift=%lf", &po -> hue_line_drift);
			sscanf(token, "dhue_ldrift=%lf", &po -> dhue_line_drift);

			sscanf(token, "contr=%lf", &po -> contrast);
			sscanf(token, "dcontr=%lf", &po -> dcontrast);

			sscanf(token, "u_shift=%lf", &po -> u_shift);
			sscanf(token, "du_shift=%lf", &po -> du_shift);

			sscanf(token, "v_shift=%lf", &po -> v_shift);
			sscanf(token, "dv_shift=%lf", &po -> dv_shift);

			sscanf(token, "slice=%lf", &po -> slice_level);
			sscanf(token, "dslice=%lf", &po -> dslice_level);

			sscanf(token, "mask=%lf", &po -> mask_level);
			sscanf(token, "dmask=%lf", &po -> dmask_level);

			sscanf(token, "bright=%lf", &po -> brightness);
			sscanf(token, "dbright=%lf", &po -> dbrightness);

			sscanf(token, "ck_color=%lf", &po -> chroma_key_color);
			sscanf(token, "dck_color=%lf", &po -> dchroma_key_color);

			sscanf(token, "ck_sat=%lf", &po -> chroma_key_saturation);
			sscanf(token, "dck_sat=%lf", &po -> dchroma_key_saturation);

			sscanf(token, "ck_window=%lf", &po -> chroma_key_window);
			sscanf(token, "dck_window=%lf", &po -> dchroma_key_window);

			sscanf(token, "u=%lf", &po -> u);
			sscanf(token, "du=%lf", &po -> du);

			sscanf(token, "v=%lf", &po -> v);
			sscanf(token, "dv=%lf", &po -> dv);

			sscanf(token, "color=%lf", &po -> color);
			sscanf(token, "dcolor=%lf", &po -> dcolor);

			a = sscanf(token, "center=%lf", &da);
			if(a == 1) center_flag = (int)da;

			sscanf(token, "aspect=%lf", &po -> aspect);

			/* these are globals (double) for subtitles */
			sscanf(token, "hfactor=%lf", &subtitle_h_factor);
			sscanf(token, "vfactor=%lf", &subtitle_v_factor);

			/* font related */

			font_dir[0] = 0;
			a = sscanf(token, "font_dir=%s", font_dir);
			if(a == 1)
				{
				po -> font_dir = strsave(font_dir);
				if(! po -> font_dir)
					{
					tc_log_msg(MOD_NAME,
					"subtitler: parse_frame_entry(): could not allocate space for font_dir, aborting");

					exit(1);
					}
				}

			/* also allow font_path, for compatibility with xste-3.1 */
			a = sscanf(token, "font_path=%s", font_dir);
			if(a == 1)
				{
				po -> font_dir = strsave(font_dir);
				if(! po -> font_dir)
					{
					tc_log_msg(MOD_NAME,
					"subtitler: parse_frame_entry(): could not allocate space for font_dir, aborting");

					exit(1);
					}
				}

			font_name[0] = 0;
			a = sscanf(token, "font_name=%s", font_name);
			if(a == 1)
				{
				po -> font_name = strsave(font_name);
				if(! po -> font_name)
					{
					tc_log_msg(MOD_NAME,
					"subtitler: parse_frame_entry(): could not allocate space for font_name, aborting");

					exit(1);
					}
				}

			a = sscanf(token, "font_size=%d", &po -> font_size);
			a = sscanf(token, "font_iso_extension=%d", &po -> font_iso_extension);
			a = sscanf(token, "font_outline_thickness=%lf", &po -> font_outline_thickness);
			a = sscanf(token, "font_blur_radius=%lf", &po -> font_blur_radius);

			if(debug_flag)
				{
				tc_log_msg(MOD_NAME, "frame=%s font_dir=%s font_name=%s\n\
				font_size=%d font_iso_extension=%d font_outline_thickness=%.2f font_blur_radius=%.2f",\
				pa -> name, po -> font_dir, po -> font_name,\
				po -> font_size, po -> font_iso_extension,\
				po -> font_outline_thickness, po -> font_blur_radius);
				}

			/* also reload font if font_factor changed */
			if( (po -> font_dir) && (po -> font_name) &&\
			(po -> font_size > 0) && (po -> font_iso_extension > 0) &&\
			(po -> font_outline_thickness > 0.0) && (po -> font_blur_radius > 0.0) )
				{
				/*
				IMPORTANT! this sets data in frame_list (pb)!!!!! NOT<<
           	    in object_list (po).
				In fact replaces frame_list pb -> font_dir with the
                new definition.
				Later, when the object is referenced again, a pointer
				is handed to the object list.
				Else the data would be erased when the object was no
           	    longer displayed.
				*/
				po -> font_symbols = default_subtitle_font_symbols;

				/* read in font (also needed for frame counter) */

				pfd = add_font(\
					po -> font_name, po -> font_symbols, po -> font_size, po -> font_iso_extension,\
					po -> font_outline_thickness, po -> font_blur_radius);
				if(! pfd)
					{
					tc_log_msg(MOD_NAME,
					"subtitler(): parser.c: could not load font:\n\
					font_dir=%s font_name=%s symbols=%d size=%d iso extension=%d\n\
					outline_thickness=%.2f  blur_radius=%.2f, aborting",\
					po -> font_dir, po -> font_name, po -> font_symbols, po -> font_size,\
					po -> font_iso_extension,\
					po -> font_outline_thickness, po -> font_blur_radius );

					/* return error */
					exit(1);
					}