# TextRenderer

**URL:** <https://discuss.avogadro.cc/t/textrenderer/1675>\
**Category:** Development\
**Created:** [November 24, 2009, 12:36pm UTC](https://discuss.avogadro.cc/t/textrenderer/1675 "2009-11-24T12:36:25Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Konstantin\_Tokarev](https://discuss.avogadro.cc/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Konstantin\_Tokarev](https://discuss.avogadro.cc/u/Konstantin_Tokarev)\
**Post date:** [November 24, 2009, 12:36pm UTC](https://discuss.avogadro.cc/t/textrenderer/1675/1 "2009-11-24T12:36:25Z")

</div>

> Hi,  
> (argh, could you set a reply-to field to the list?)  
> 2009/11/23 Geoffrey Hutchison :
> 
> > > Avogadro::Painter have no interface to set fonts. I’ve looked inside text renderer, and my first wish was to overload draw() to accept QFont.
> > 
> > I’d add methods to TextRenderer to set the font and/or size explicitly. This way, the existing calls to draw() can remain the same – I think this approach is more in keeping with Qt API as well.  
> > Just one note about the TextRenderer, assuming that didnt change since  
> > my days: it assumes a single font/size to be used throughout, in the  
> > following sense: the hash-table where textrenderer stores glyphs, is  
> > indexed by QChar’s, so it is not aware of font and font size. So if  
> > you render a ‘Z’ with size 12, then afterwards when you want to print  
> > ‘Zorro’ in size 14, it will use the cached ‘Z’ of size 12.  
> > So if you want TextRenderer to be aware of multiple fonts/sizes, you  
> > need to make that part of the indexes used in the Hash table.  
> > Not sure what the best way to do this is; either you find an efficient  
> > way of getting a single hash value for a (QFont,QChar) pair, or  
> > perhaps instead it’s better to have a “hash table of hash tables”, the  
> > big table indexed by QFont, the small tables are like the existing one  
> > indexed by QChar …?  
> > Oh and you could discuss that with kgllib / Gluon people who are using  
> > a variant of TextRenderer.

I think it would be rather ineffective to store all chars of all fonts in hash. Maybe it’s possible to change them dynamicaly? There will be no more then two fonts and two font sizes simultaniously in the view (atom and bond labels\_

–  
Regards,  
Konstantin

---

<div class="post-metadata">

**Author:** ![Konstantin\_Tokarev](https://discuss.avogadro.cc/letter_avatar_proxy/v4/letter/k/ecd19e/32.png) [@Konstantin\_Tokarev](https://discuss.avogadro.cc/u/Konstantin_Tokarev)\
**Post date:** [November 23, 2009, 1:51pm UTC](https://discuss.avogadro.cc/t/textrenderer/1675/2 "2009-11-23T13:51:43Z")

</div>

New code I’ve recently submitted to my Git allows user to change color of atom and bond labels. But when I tried to change fonts, I’ve faced with problem Avogadro::Painter have no interface to set fonts. I’ve looked inside text renderer, and my first wish was to overload draw() to accept QFont. But than I’ve found in sources some tricks dependent on font size. Also I’ve found issue [https://sourceforge.net/tracker/?func=detail&aid=2902472&group\_id=165310&atid=835077](https://sourceforge.net/tracker/?func=detail&aid=2902472&group_id=165310&atid=835077)

Will change of font work?

–  
Regards,  
Konstantin

---

<div class="post-metadata">

**Author:** ![ghutchis](https://discuss.avogadro.cc/user_avatar/discuss.avogadro.cc/ghutchis/32/456_2.png) [@ghutchis](https://discuss.avogadro.cc/u/ghutchis)\
**Post date:** [November 23, 2009, 2:30pm UTC](https://discuss.avogadro.cc/t/textrenderer/1675/3 "2009-11-23T14:30:04Z")

</div>

> Avogadro::Painter have no interface to set fonts. I’ve looked inside text renderer, and my first wish was to overload draw() to accept QFont.

I’d add methods to TextRenderer to set the font and/or size explicitly. This way, the existing calls to draw() can remain the same – I think this approach is more in keeping with Qt API as well.

Just my $0.02,  
-Geoff

---

<div class="post-metadata">

**Author:** ![Benoit\_Jacob1](https://discuss.avogadro.cc/letter_avatar_proxy/v4/letter/b/b5ac83/32.png) [@Benoit\_Jacob1](https://discuss.avogadro.cc/u/Benoit_Jacob1)\
**Post date:** [November 24, 2009, 11:32am UTC](https://discuss.avogadro.cc/t/textrenderer/1675/4 "2009-11-24T11:32:52Z")

</div>

Hi,

(argh, could you set a reply-to field to the list?)

2009/11/23 Geoffrey Hutchison [geoff.hutchison@gmail.com](mailto:geoff.hutchison@gmail.com):

> > Avogadro::Painter have no interface to set fonts. I’ve looked inside text renderer, and my first wish was to overload draw() to accept QFont.
> 
> I’d add methods to TextRenderer to set the font and/or size explicitly. This way, the existing calls to draw() can remain the same – I think this approach is more in keeping with Qt API as well.

Just one note about the TextRenderer, assuming that didnt change since  
my days: it assumes a single font/size to be used throughout, in the  
following sense: the hash-table where textrenderer stores glyphs, is  
indexed by QChar’s, so it is not aware of font and font size. So if  
you render a ‘Z’ with size 12, then afterwards when you want to print  
‘Zorro’ in size 14, it will use the cached ‘Z’ of size 12.

So if you want TextRenderer to be aware of multiple fonts/sizes, you  
need to make that part of the indexes used in the Hash table.

Not sure what the best way to do this is; either you find an efficient  
way of getting a single hash value for a (QFont,QChar) pair, or  
perhaps instead it’s better to have a “hash table of hash tables”, the  
big table indexed by QFont, the small tables are like the existing one  
indexed by QChar …?

Oh and you could discuss that with kgllib / Gluon people who are using  
a variant of TextRenderer.

Benoit

> Just my $0.02,  
> -Geoff
> 
> * * *
> 
> Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day  
> trial. Simplify your report design, integration and deployment - and focus on  
> what you do best, core application coding. Discover what’s new with  
> Crystal Reports now. [http://p.sf.net/sfu/bobj-july](http://p.sf.net/sfu/bobj-july)
> 
> * * *
> 
> Avogadro-devel mailing list  
> [Avogadro-devel@lists.sourceforge.net](mailto:Avogadro-devel@lists.sourceforge.net)  
> [avogadro-devel List Signup and Options](https://lists.sourceforge.net/lists/listinfo/avogadro-devel)
