Discussion:
Direct2D and DirectWrite experimental Windows code
(too old to reply)
Neil Hodgson
2011-08-01 10:21:06 UTC
Permalink
The recent Scintilla 2.28 release is starting to drop support for
some older APIs on OS X and GTK+. But removing old support isn't that
interesting. Adding support for newer APIs may be.

Windows 7 introduced new APIs Direct2D for 2 dimensional vector
graphics and DirectWrite for text layout and drawing. They are also
available for Vista but not for XP.

These APIs can produce higher quality output and can be accelerated
by hardware.

I have reimplemented most of the Windows platform layer using
Direct2D and DirectWrite and this is available from a temporary Hg
repository
https://bitbucket.org/nyamatongwe/directsci/overview
and from
http://www.scintilla.org/scite.zip Source
http://www.scintilla.org/wscite.zip Windows executable

All drawing to the main Scintilla window and calltip windows is
through Direct2D and DirectWrite. Since Direct2D buffers drawing,
Scintilla's own buffered drawing can be turned off with the SciTE
setting buffered.draw=0. Autocompletion hasn't been converted - it
runs but looks poor.

Text is drawn differently. It looks good but is a bit lighter than
GDI and with slightly duller colours. The duller colours appear due to
colour management: the colours now match Internet Explorer and Firefox
which are colour managed whereas GDI Scintilla has similar colours to
Chrome which is not colour managed. When using buffered drawing the
colours are back to being similar to GDI and antialiasing does not
take advantage of LCD sub-pixels.

Drawing may be a little slower than GDI overall. While I was
hopeful that these APIs would be faster, it is quite usable and there
may be improvements possible with more experience. During development,
it was much slower: Direct2D allows quite a lot of interoperation with
GDI but if you swap between the two often then Direct2D has to flush
and rebuild state which slows it down.

Direct2D does not support printing so it is not a complete
replacement for GDI. Microsoft does not intend to ever port Direct2D
to Windows XP which is still in wide use. For these two reasons, it is
unreasonable to move completely to Direct2D. It may be possible to
support both Direct2D/DirectWrite and GDI in one Scintilla DLL but
that would require more work.

https://secure.wikimedia.org/wikipedia/en/wiki/Direct2D
https://secure.wikimedia.org/wikipedia/en/wiki/DirectWrite

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Philippe Lhoste
2011-08-01 10:53:38 UTC
Permalink
Post by Neil Hodgson
I have reimplemented most of the Windows platform layer using
Direct2D and DirectWrite and this is available from a temporary Hg
repository
Interesting. Thanks for sharing the conclusions of your research.
It might be useful in the future, but as I still use a lot SciTE at work
where we have old XP boxes, I am not overly interested by a switch (as
you point out!), even less as it doesn't appear to have a real
performance gain (drawing performance of Scintilla is already very good,
anyway).
Worse, I still prefer crisp fonts, with very light antialiasing and very
dark/black main outline. I routinely test new fixed-width fonts (as they
are still better for C-like languages, IMO) and still reject fonts like
Consolas or Inconsolata as they look too bold and/or too dim (depending
on size), particularly on XP boxes.

Just giving my opinion on readability topic, of course other developers
will have different tastes/needs/opinions.
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
KHMan
2011-08-01 12:04:16 UTC
Permalink
Post by Neil Hodgson
I have reimplemented most of the Windows platform layer using
Direct2D and DirectWrite and this is available from a temporary Hg
repository
[snip]
Worse, I still prefer crisp fonts, with very light antialiasing
and very dark/black main outline. I routinely test new fixed-width
fonts (as they are still better for C-like languages, IMO) and
still reject fonts like Consolas or Inconsolata as they look too
bold and/or too dim (depending on size), particularly on XP boxes.
This gets my vote too -- I stick to traditional hinted glyphs.
I've tried font smoothing many times, but each time I switch back.
They look okay in PDF files if lines are thick, but when lines are
thin and fonts small, it's not comfortable viewing for me -- I
guess my eyeballs are continually trying to resolve the crisp
pixels so craved by the pesky neurons it feeds data to. :-)
--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Anthony
2011-08-01 10:59:12 UTC
Permalink
Hi Neil,

This works on my large project without any problems (on Win7) - text looks much smoother when zoomed. Colours seem only slightly different. No big speed difference, if anything maybe slightly faster.

Do Vista owners have to get an update or will this work ok on Vista as it arrives in a box?

Will the library fail to open if Direct2D is unavailable, so I can fallback to the other version without having to check OS versions (for XP)?

-Anthony
Post by Neil Hodgson
The recent Scintilla 2.28 release is starting to drop support for
some older APIs on OS X and GTK+. But removing old support isn't that
interesting. Adding support for newer APIs may be.
Windows 7 introduced new APIs Direct2D for 2 dimensional vector
graphics and DirectWrite for text layout and drawing. They are also
available for Vista but not for XP.
These APIs can produce higher quality output and can be accelerated
by hardware.
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Neil Hodgson
2011-08-01 11:45:19 UTC
Permalink
Post by Anthony
Do Vista owners have to get an update or will this work ok on Vista as it arrives in a box?
The Wikipedia articles mention some updates needed for it to work on Vista.
Post by Anthony
Will the library fail to open if Direct2D is unavailable, so I can fallback
to the other version without having to check OS versions (for XP)?
It will probably just fail to load on XP.

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Anthony
2011-08-01 12:02:43 UTC
Permalink
Hi Neil,

Thanks for the info. I'll do some tests and report back with what I find out.

- Anthony
Post by Neil Hodgson
Post by Anthony
Do Vista owners have to get an update or will this work ok on Vista as it
arrives in a box?
The Wikipedia articles mention some updates needed for it to work on Vista.
Post by Anthony
Will the library fail to open if Direct2D is unavailable, so I can fallback
to the other version without having to check OS versions (for XP)?
It will probably just fail to load on XP.
Neil
--
Best regards,
Anthony mailto:***@doubledutchdesigns.com
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Anthony
2011-08-02 08:53:16 UTC
Permalink
Hi Neil,
Post by Neil Hodgson
Post by Anthony
Will the library fail to open if Direct2D is unavailable, so I can fallback
to the other version without having to check OS versions (for XP)?
It will probably just fail to load on XP.
It does report a fail, but there is a visual message just before - "Failed because d2d1.dll" not found.

Can this message be skipped as it visually looks bad or should I try open d2d1.dll first to see if it exists?

-Anthony
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Neil Hodgson
2011-08-02 09:08:29 UTC
Permalink
Post by Anthony
It does report a fail, but there is a visual message just before - "Failed
because d2d1.dll" not found.
Can this message be skipped as it visually looks bad or should I try open
d2d1.dll first to see if it exists?
Try to LoadLibrary d2d1.dll and you should get a nice failure status.

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Anthony
2011-08-02 09:55:32 UTC
Permalink
Hi Neil,

Argh! You are right - how annoying...

I will have to try locate the normal path of the dll and check if it physically exists before loading the proper lib.

-Anthony
Post by Neil Hodgson
Post by Anthony
It does report a fail, but there is a visual message just before - "Failed
because d2d1.dll" not found.
Can this message be skipped as it visually looks bad or should I try open
d2d1.dll first to see if it exists?
Try to LoadLibrary d2d1.dll and you should get a nice failure status.
Neil
--
Best regards,
Anthony mailto:***@doubledutchdesigns.com
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Anthony
2011-08-02 14:46:01 UTC
Permalink
Hi Neil,

I checked for d2d1.dll at CSIDL_SYSTEMX86 and if present load the direct2d version, else the normal version. This works fine with no messages...

:)

-Anthony
Post by Neil Hodgson
Post by Anthony
It does report a fail, but there is a visual message just before - "Failed
because d2d1.dll" not found.
Can this message be skipped as it visually looks bad or should I try open
d2d1.dll first to see if it exists?
Try to LoadLibrary d2d1.dll and you should get a nice failure status.
Neil
--
Best regards,
Anthony mailto:***@doubledutchdesigns.com
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Neil Hodgson
2011-08-02 05:19:00 UTC
Permalink
More recent text drawing APIs like DirectWrite, Pango, and Core
Text handle text positioning and measurement with sub-pixel precision.
Older APIs like GDI on Windows work in whole pixels. Scintilla has
previously converted to whole pixels when measuring text. This led to
some poor visuals with uneven spaces between tokens of up to 1 pixel,
and was most noticeable with small font sizes when text and operators
were mixed. Text could also move back and forth slightly while being
selected which was a motivation for the 2 phase drawing approach (all
background colours drawn then all text drawn) which is now the
default.

There is an implementation of fractional character positioning in
the directSci repository. It should work on Windows using DirectWrite
and OS X using Core Text.
https://bitbucket.org/nyamatongwe/directsci/overview

Reporting fractional measurements from the platform layer requires
changing the platform layer interface. This can be a compile time
choice with older platforms continuing to use integer coordinates. The
'XYPOSITION' typedef is either 'float' or 'int'. This is hard-coded
for experimentation but may later be defined in the makefile or
automatically for each platform. XYPOSITION is used for each API where
fractional character positions may be used. While XYPOSITION is used
for both x and y, vertical positions are rounded to integers so that
each line is still an independent block of pixels. To ensure
rectangles like the caret and selection are drawn crisply to pixel
boundaries, these calls round their argument x positions.

There are font settings, such as fractional sizes, that have not
been changeable with Scintilla before. Later a better API will be
provided but, for now, sizes larger than 2000 are treated as if they
were multiplied by 1000 by the Scintilla platform layer for
DirectWrite. Thus, a 9.4 point font can be set with
font.base=font:Segoe UI,size:9400,bold
Some fonts support different levels of bold like light, normal,
semi-bold, bold instead of Scintilla's binary choice. these choices
should be exposed as an API. The current build for DirectWrite maps
Scintilla's bold attribute to semi-bold which works well for Segoe UI.

There is a memory cost to choosing float for XYPOSITION as
Scintilla caches text measurements which is important for the
performance of wrapping. With integer widths, a 2 byte short was used
for positions and this will now require 4 byte floats. There are also
approaches that could greatly reduce storage used with integer widths
such as storing 2 character widths per byte in many cases (characters
are rarely wider than 16 pixels). This may have made storing all
character positions for the whole document practical even for large
documents which would have simplified and sped up word wrap.

Code can also be downloaded from
http://www.scintilla.org/scite.zip  Source
http://www.scintilla.org/wscite.zip Windows executable

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Neil Hodgson
2011-08-12 14:11:59 UTC
Permalink
This code has been improved some more and the changes are available
from Hg repositories
https://bitbucket.org/nyamatongwe/directsci Scintilla
https://bitbucket.org/nyamatongwe/scited2d SciTE

The fractional font sizes should work on Cocoa, GTK+, and
Windows+DirectWrite by calling SCI_STYLESETSIZEFRACTIONAL with the
size multiplied by 100. It is now possible to choose different weights
instead of just normal and bold by calling SCI_STYLESETWEIGHT with a
weight between 1 and 999 with 100 being light, 400 normal, and 700
bold. The particular values that will produce a different appearance
depend on the platform and font.

It is now possible on Windows to choose between the old GDI code
and Direct2D+DirectWrite by calling SCI_SETTECHNOLOGY with either
SC_TECHNOLOGY_DEFAULT or SC_TECHNOLOGY_DIRECTWRITE. This was the most
problematic aspect of this feature since its easiest to use resources
created with an API within that API. Its possible, for example to use
a GDI bitmap from Direct2D but that would multiply out the code paths.
Thus, using Direct2D for a Scintilla window implies using it for
calltips and autocompletion as well. Each Scintilla window may,
however have a different 'technology' setting. Later, there could be
more choices for this setting. The DLL should work on Windows XP but
only with GDI.

The 'technology' option disrupted the code quite a bit as it has to
be copied around and provided when creating font or surface objects.
This has caused more changes to the platform interface.

The SciTE modifications are minor: on Windows Direct2D /
DirectWrite can be turned on (technology=1) or off (technology=0).
Font size can be set with fractions and weight can be set to a level
between 1 and 999. For example:
technology=1
font.base=font:Segoe UI,size:9.4,weight:500

GTK+/Cairo/Pango was the first platform used by Scintilla with an
API that was capable of representing fractional positioning but it
turns out this is still not active. I was surprised but it is also
confirmed by the list of issues on a paper by Behdad Esfahbod
(responsible for HarfBuzz text shaping library): "Fix subpixel issues
and implement subpixel positioning API in cairo, and revamp gnome
appearance applet to reflect this. "
http://behdad.org/text/
However, fractional text sizes works on GTK+ and so do various weights.

This code is still experimental. I am not aiming at integration
into Scintilla mainline for months so it is still something that can
be changed a lot if more issues are found or features needed.

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Anthony
2011-08-12 15:36:01 UTC
Permalink
Hi Neil,
Post by Neil Hodgson
It is now possible on Windows to choose between the old GDI code
and Direct2D+DirectWrite by calling SCI_SETTECHNOLOGY with either
SC_TECHNOLOGY_DEFAULT or SC_TECHNOLOGY_DIRECTWRITE.
Great stuff. :) Hopefully this can be in the main code as soon as possible. I've been checking the previous Direct2D version in a large project and can find no problems at all on a variety of machines (all Win7 x86 or x64).
Post by Neil Hodgson
The DLL should work on Windows XP but only with GDI.
Do we have to check first to see if 'd2d1.dll' is present before attempting to call this? ('cause on the older version if you don't then a message appears saying something like it isn't present on XP)...

- Anthony
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Neil Hodgson
2011-08-13 01:40:30 UTC
Permalink
Great stuff. :)  Hopefully this can be in the main code as soon as possible.
Its a big change to the platform interface and I'm thinking that,
since the platforms will all have to be updated, this would be a good
opportunity for cleaning up the interface.
Do we have to check first to see if 'd2d1.dll' is present before attempting
to call this?  ('cause on the older version if you don't then a message
appears saying something like it isn't present on XP)...
It should work on XP when the D2D DLL isn't present but I haven't checked.

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Philippe Lhoste
2011-08-12 12:44:29 UTC
Permalink
An interesting article (although I haven't read it fully yet) on the topic:
http://blog.mozilla.com/nattokirai/2011/08/11/directwrite-text-rendering-in-firefox-6/
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Neil Hodgson
2011-08-12 14:13:44 UTC
Permalink
Post by Philippe Lhoste
http://blog.mozilla.com/nattokirai/2011/08/11/directwrite-text-rendering-in-firefox-6/
Yes, it is interesting. Firefox is offering some choices (like
GDI-style drawing by DirectWrite) that I can't see how to program.

Neil
--
You received this message because you are subscribed to the Google Groups "scintilla-interest" group.
To post to this group, send email to scintilla-***@googlegroups.com.
To unsubscribe from this group, send email to scintilla-interest+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/scintilla-interest?hl=en.
Continue reading on narkive:
Loading...