# use vtkTextActor to display chinese

**URL:** https://discourse.vtk.org/t/use-vtktextactor-to-display-chinese/12999
**Category:** Support
**Tags:** code
**Created:** [January 3, 2024, 1:42pm UTC](https://discourse.vtk.org/t/use-vtktextactor-to-display-chinese/12999 "2024-01-03T13:42:40Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![501586528](https://discourse.vtk.org/user_avatar/discourse.vtk.org/501586528/32/7907_2.png) [@501586528](https://discourse.vtk.org/u/501586528)
#### Post date: [January 3, 2024, 1:42pm UTC](https://discourse.vtk.org/t/use-vtktextactor-to-display-chinese/12999/1 "2024-01-03T13:42:40Z")

</div>

I’m a chinese developer, I want to display chinese. when I set font size less than 18, it won’t display.Only font size greater than 18 display. How can i display chinese with font size less than 18?

Here is my code.

```auto
std::string text = "华文仿宋中文字体测试";
this->text_->GetTextProperty()->SetFontFamily(VTK_FONT_FILE);
this->text_->GetTextProperty()->SetFontFile("C:\\Windows\\Fonts\\simfang.ttf");

this->text_->SetInput(text.c_str());
this->text_->GetTextProperty()->SetFontSize(8);
this->text_->GetTextProperty()->SetColor(0, 0, 0);

```

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [January 3, 2024, 2:53pm UTC](https://discourse.vtk.org/t/use-vtktextactor-to-display-chinese/12999/2 "2024-01-03T14:53:04Z")

</div>

Does the font support such sizes in the first place? Could it be DPI-related in that low-DPI doesn’t support the detail needed for characters at that size (sorry, not very well-versed in such glyphs in practice)?

Maybe showing that freetype can do such font sizes at all (outside of VTK) would be useful. This library seems useful for that: [freetype-py · PyPI](https://pypi.org/project/freetype-py/)

---

<div class="post-metadata">

### Author: ![501586528](https://discourse.vtk.org/user_avatar/discourse.vtk.org/501586528/32/7907_2.png) [@501586528](https://discourse.vtk.org/u/501586528)
#### Post date: [January 4, 2024, 6:03am UTC](https://discourse.vtk.org/t/use-vtktextactor-to-display-chinese/12999/3 "2024-01-04T06:03:54Z")

</div>

thank you! I have solved it.

---

<div class="post-metadata">

### Author: ![ben.boeckel](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.vtk.org/u/ben.boeckel)
#### Post date: [January 4, 2024, 1:21pm UTC](https://discourse.vtk.org/t/use-vtktextactor-to-display-chinese/12999/4 "2024-01-04T13:21:15Z")

</div>

For posterity and to help others that may encounter the same issue, do you mind sharing your solution?

---

<div class="post-metadata">

### Author: ![501586528](https://discourse.vtk.org/user_avatar/discourse.vtk.org/501586528/32/7907_2.png) [@501586528](https://discourse.vtk.org/u/501586528)
#### Post date: [January 5, 2024, 1:36am UTC](https://discourse.vtk.org/t/use-vtktextactor-to-display-chinese/12999/5 "2024-01-05T01:36:56Z")

</div>

yes I just embed font family file into exe.  
I refer this blog

> <https://stackoverflow.com/questions/45802537/how-to-embed-font-and-other-image-files-when-using-graphic-libraries-like-sfml>

Here is my code.  
firstly,we need get our resource.

```auto
#include "simsun.h"
FILE* tempfile = fopen("simsun.ttc", "wb");
fwrite(simsun_ttc, sizeof(char), simsun_ttc_len, tempfile);
fclose(tempfile);

```

And then read resource.

```auto
fstream fontfil;
fontfile.open(fontfilepath,ios::in);
if (!fontfile)
{
	cout << "Wrong path!" << endl;
	return;
}

```

Finally apply it into textactor

```auto
this->text_->GetTextProperty()->SetFontFamily(VTK_FONT_FILE);
this->text_->GetTextProperty()->SetFontFile(fontfilepath.c_str());

```

It’s works for me.
