dotgnu-general
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [DotGNU]DrawString / Performence


From: Neil Cawse
Subject: RE: [DotGNU]DrawString / Performence
Date: Mon, 22 Sep 2003 15:06:22 -0400

> http://www.noto.de/dotgnu/DrawString.png

Good job.

> The other problem is about the MeasureCharacterRanges method. I
extracted
> parts of the current implementation to use it also for the DrawString
> method.
> But I think I should rewrite this methods, because it pinvoke the
system
> string measure feature very often and this could be one of the
performence
> problems of the current SWF implementation. What do you think?

Definitely! Rhys and I discussed this. The way that I originally did it
is slow. There are two options:
1) Cache each request to the toolkit for each font size/style/letter.
2) Use a smart approach to actually measuring a word at a time and going
down to letters where needed.

Some of this is background..

There are essentially 3 System.Graphics methods and a separate
requirement for drawing the textbox that we need to cater for
(RichTextBox later):

MeasureCharacterRanges - here you define a collection of a range of the
characters in a string that you want to measure eg. 1 to 5 and 6 to 10.
MeasureString - measure the entire string
DrawString - render the string
For textbox, we need to be able to specify the character range that is
highlighted.

We want to support all the StringFormat options for these methods, these
include:
* Alignments vertically and horizontally
* DigitSubstitution for characters that cant be displayed
* DirectionRightToLeft
* DirectionVertical for vertical text
* DisplayFormatControl options 
* NoWrap/Word wrapping
* Hotkeys
* StringTrimming:
        Character - Specifies that the text is trimmed to the nearest
character. 
        EllipsisCharacter - Specifies that the text is trimmed to the
nearest character, and an ellipsis is inserted at the end of a trimmed
line. 
        EllipsisPath - The center is removed from trimmed lines and
replaced by an ellipsis. The algorithm keeps as much of the last
slash-delimited segment of the line as possible. 
        EllipsisWord - Specifies that text is trimmed to the nearest
word, and an ellipsis is inserted at the end of a trimmed line. 
        Word - Specifies that text is trimmed to the nearest word.
* Graphics clipping/layout rectangle

These need to obviously be supported whether we are drawing a string or
measuring a string.

The other important point is that most calls to Xsharp will result in an
X request - these are slow and must be minimized as much as possible.

We want to share the code between all the requirements as much as
possible.

Now in order to draw the string, we need to measure it first to know if
we must for example wrap the word, put in the ellipse etc. For the very
simple case of no StringFormat, we could get away with no measuring.
Once the string is measured, we would then draw the biggest chunks of
text we could for eg. Vertical would be 1, a string with one hotkey
would require 3 calls etc.

Now back to measuring, we could do that by trying to measure the whole
string and guessing by ratioing to the number of characters, guess the
line breaks. Then measure again to confirm etc.

Thomas, I will leave this up to your ingenuity - if you need or want to
bounce some ideas, mail. Or if any DotGNU'ers have some smart ideas??

This stuff is very core and very important. We need to get it slick and
fast. I did already take a look at the api's in wine the implementation
that do this and I put my tail between my legs and left ;)


> 
> 
> On my system I have a poor performence of the SWF-Samples, but my CPU
load
> is near 0!! So this could only be because the system is waiting for
I/O or
> something like that. With strace I see that there are a lot of calls
for
> the system rtc-time? Is this something for the event control?

I think is because of the number of X requests.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]