示例#1
0
static bool MCTextLayoutFontFromHFONT(void *p_font, MCTextLayoutFont*& r_font)
{
	bool t_success;
	t_success = true;

	// First fetch the HFONT's LOGFONT structure
	LOGFONTA t_logfont;
	if (t_success)
		if (!GetObjectA(p_font, sizeof(LOGFONTA), &t_logfont))
			t_success = false;

	if (t_success)
		t_logfont . lfHeight = -256;

	// Now use this to search for an existing layout font
	MCTextLayoutFont *self;
	self = nil;
	if (t_success)
	{
		self = MCTextLayoutFontFind(t_logfont);
		if (self != nil)
		{
			r_font = self;
			return true;
		}
	}

	// Otherwise we must go ahead and create a new font
	if (t_success)
		t_success = MCMemoryNew(self);

	if (t_success)
	{
		self -> handle = CreateFontIndirectA(&t_logfont);
		if (self -> handle == nil)
			t_success = false;
	}

	if (t_success)
	{
		MCListPushFront(s_fonts, self);
		self -> info = t_logfont;

		// Now see if the font is a linked font
		for(MCTextLayoutLinkedFont *t_links = s_linked_fonts; t_links != nil; t_links = t_links -> next)
			if (MCCStringEqualCaseless(t_links -> name, self -> info . lfFaceName))
			{
				self -> linking = t_links;
				break;
			}

		r_font = self;
	}
	else
		MCTextLayoutFontDestroy(self);
	
	return t_success;
}
示例#2
0
static bool MCTextLayoutFontLinkCallback(void *p_context, const char *p_key, DWORD p_type, void *p_value, uint32_t p_value_length)
{
	bool t_success;
	t_success = true;

	// Ignore the empty key
	if (MCCStringEqual(p_key, ""))
		return true;

	// Ignore a non REG_MULTI_SZ type
	if (p_type != REG_MULTI_SZ)
		return true;

	// Create a new linked font structure
	MCTextLayoutLinkedFont *t_font;
	t_font = nil;
	if (t_success)
		t_success = MCMemoryNew(t_font);

	if (t_success)
		t_success = MCCStringClone(p_key, t_font -> name);

	// Attempt to parse the font link string - it should be of type
	// REG_MULTI_SZ and be a list of entries of the form:
	//   file, face, [ scale, scale ]
	if (t_success)
	{
		char *t_ptr;
		uint32_t t_len;
		t_ptr = (char *)p_value;
		t_len = p_value_length;
		while(t_success && t_len > 0)
		{
			char *t_end;
			for(t_end = t_ptr; *t_end != '\0' && t_len > 0; t_end += 1, t_len -= 1)
				;

			if (t_end - t_ptr > 0)
			{
				char **t_items;
				uint32_t t_item_count;
				t_items = nil;
				t_item_count = 0;
				if (t_success)
					t_success = MCCStringSplit(t_ptr, ',', t_items, t_item_count);

				if (t_item_count >= 2)
				{
					if (t_success)
						t_success = MCMemoryResizeArray(t_font -> entry_count + 1, t_font -> entries, t_font -> entry_count);
				
					if (t_success)
						t_success = MCCStringClone(t_items[1], t_font -> entries[t_font -> entry_count - 1] . face);
				}

				for(uint32_t i = 0; i < t_item_count; i++)
					MCCStringFree(t_items[i]);
				MCMemoryDeleteArray(t_items);
			}

			t_ptr = t_end + 1;
			t_len -= 1;
		}
	}

	if (t_success)
		MCListPushFront(s_linked_fonts, t_font);
	else
		MCTextLayoutLinkedFontDestroy(t_font);

	return t_success;
}