Skip to content

[Feature Request] Support fallback fonts in style::FontDesc #700

Open
@cppHusky

Description

@cppHusky

What is the feature ?

Add support for multi fonts in one style::FontDesc.

for example, make family a Vec<FontFamily>; or provide Vec<FontDesc> in style::TextStyle.

(Optional) Why this feature is useful and how people would use the feature ?

Explain why this feature is important

When I draw some text with element::Text, like "测试文本 Test", I want to use Times New Roman for latin characters and Noto Serif CJK SC for CJK characters. But I found that style::FontDesc can support only one font.

If it support fallback font, I can set ["Times New Roman", "Noto Serif CJK SC"] so that latin characters use the former, and CJK characters use the latter.

(Optional) Additional Information

More details are appreciated:)

I use the following code for test:

use plotters::prelude::*;
fn main()->Result<(),Box<dyn std::error::Error>>{
	let root=BitMapBackend::new(
		"test.png",
		(600,200),
	).into_drawing_area();
	//let font:FontDesc=("Times New Roman",80.).into();
	let font:FontDesc=("Noto Serif CJK SC",80.).into();
	let _=root.fill(&WHITE);
	root.draw(&Text::new("测试文本 Test",(100,80),font))?;
	Ok(())
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions