Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i want to remove the font lock #132

Open
173619070 opened this issue Feb 5, 2023 · 1 comment
Open

i want to remove the font lock #132

173619070 opened this issue Feb 5, 2023 · 1 comment
Assignees
Labels

Comments

@173619070
Copy link

173619070 commented Feb 5, 2023

I prefer not to use LOCK_FONTCACHE&UNLOCK_FONTCACHE in the vkvg_fonts. cpp file, because locking will reduce the efficiency of the program, so i think traverse all bitmaps of a font and copy them to texture at one time, for font size, we can use scaling factor for coordinates,just like this:

		// Writing horisontal text
		auto gi = fi->GetGlyphInfo(font_face, text[0]);
		auto trans = glm::vec2{ 0,gi->horisontal_coords.top_left.y };
		location -= trans;//change the baseline

		ret.aabb.top_left = gi->horisontal_coords.top_left * scale + location; //scale to change the font size
		ret.aabb.bottom_right = gi->horisontal_coords.bottom_right * scale + location;

		for (auto c : text) {
			auto gi = fi->GetGlyphInfo(font_face, c);
			AppendBox(location, gi->horisontal_coords, gi->uv_coords, gi->atlas_index);
			location.x += (gi->horisontal_advance + kerning) * scale.x;
		}

and the function of GetGlyphInfo:


const vk2d::vk2d_internal::GlyphInfo *vk2d::vk2d_internal::FontResourceImpl::GetGlyphInfo(
	uint32_t		font_face,
	uint32_t		character
) const
{
	auto & face_info	= face_infos[ font_face ];
	auto & charmap		= face_info.charmap;
	auto glyph_it		= charmap.find( character );
	auto glyph_index	= uint32_t( 0 );
	if( glyph_it != charmap.end() ) {
		glyph_index		= glyph_it->second;
	} else {
		glyph_index		= face_info.fallback_glyph_index;
	}
	return &face_info.glyph_infos[ glyph_index ];
}

The above code comes from https://github.com/Noxagonal/Vulkan2DRenderer

@jpbruyere
Copy link
Owner

jpbruyere commented Feb 5, 2023

The ideal solution for the font lock would be a reader/writer lock, I may think also of an alternative font provider (selectable on compile, or maybe a runtime option) that will be static with all preloaded glyph and no locking on consume.
You can maybe propose a PR for such a solution with all preloaded glyph, on my side I have some priorities with client (employer) that makes it hard for me to work on that for now.

@jpbruyere jpbruyere self-assigned this Feb 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants