Re: Fwd: Drawing vertical text glyphs

2021-05-06 Thread Mark Hung
Hi Lubos,

Luboš Luňák  於 2021年5月6日 週四 上午12:05寫道:

>
>  Is there a testcase for that


>
I think you can take sample file from tdf#106295. It contains the set of
fullwidth punctuations that worth testing.
Also I find it useful, drawing the glyph bounding box together with the
glyph. Based on my tests, Skia and DWrite
text renderer ( with my patches on gerrit ) render consistently inside the
bounding box.

BTW, I've reported glyph positioning of windows built-in Chinese font
DFKai-SB issue to Harfbuzz -
i.e either we rely on Harfbuzz to fix the ot font functions, or we have to
use Freetype for font functions
to fix the problem.

https://github.com/harfbuzz/harfbuzz/issues/2974

-- 
Mark Hung
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: Fwd: Drawing vertical text glyphs

2021-05-05 Thread Luboš Luňák
On Thursday 29 of April 2021, Mark Hung wrote:
> To be honest, I can only verify from the point of view of a user who can
> read Chinese.

 I can use any other document as the testcase if it helps, I used that one 
simply because it seemed suitable to me. E.g. 
qadevOOo/testdocs/vertical-testcase.odt mentioned by Caolan seems better (but 
it's also Chinese if I'm getting it right).

> The cursor which overlaps the position doesn't seem right. It's not a big
> problem
> as long as it does not strike through the glyph in the middle. But the
> inconsistence among
> platforms might be a problem.
> I would have tested fullwidth punctuations.
> It went wrong in vertical writing before.

 Is there a testcase for that?

On Monday 03 of May 2021, Mark Hung wrote:
> ./hb-view -O png -o ~/output.png \
> --shapers=ot,fallback \
> --direction ttb \
> --font-funcs=ot \
> ~/下載/kaiu.ttf "「風調,雨順」"

 Thank you, this should be useful.

> [2]https://gerrit.libreoffice.org/c/core/+/115014
> [3]https://gerrit.libreoffice.org/c/core/+/115018
> [4]https://gerrit.libreoffice.org/c/core/+/115016
> [5]https://gerrit.libreoffice.org/c/core/+/115017

 I'm currently testing Skia with these and it seems these help a lot with the 
problems. tdf#137907 seems fixed, tdf#105650 seems to get fixed with your 
https://gerrit.libreoffice.org/c/core/+/115015, I have a Skia-specific fix 
for tdf#136081 and even qadevOOo/testdocs/vertical-testcase.odt works for me 
now locally. I'll try to create unittests for these problems, and then I'll 
verify this all works.

>  llunak Is Skia used for all the platofrm as default text renderer 
right now?

 No. Skia is the default on Windows. It can also be used on Linux with 
the 'gen' VCL backend.

-- 
 Luboš Luňák
 l.lu...@collabora.com
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: Fwd: Drawing vertical text glyphs

2021-05-02 Thread Mark Hung
Hi Lubos,

I investigate a little bit more in last few days.

Since Libreoffice unified all the text layout to use Harfbuzz, it would be
best to achieve the result consistent with output generated from Harfbuzz
utilities. Binaries can be downloaded from [1]. Here are some examples I
use to verify:

./hb-view -O png -o ~/output.png \
--shapers=ot,fallback \
--direction ttb \
--font-funcs=ot \
~/下載/kaiu.ttf "「風調,雨順」"

./hb-shape -O text \
--shapers=ot,fallback \
--direction ttb \
--font-funcs=ot \
~/下載/kaiu.ttf "「風調,雨順」"

You can check if it is a text renderer's problem this way when something
goes wrong.
Note that LibreOffice use default font function implementation from
Harfbuzz (opentype, --font-funcs=ot ), while the utility use  Freetype
library ( --font-funcs=ft ) by default. I find that an
important Windows built-in font (Kaiu.ttf) doesn't work well with Harfbuzz
ot font functions.

Skia text renderer works with [2], but it means that other text renderers
are broken.
Since Harfbuzz utilities also use Cairo, I believe we must be able to
achieve consistent results
at least with Cairo.  My fix there seems to work[3].

For Windows, I think it's not possible to make old ExTextOutW API correct
for vertical writing. It is possible to use DWriteTextRenderer for vertical
writing[4][5]. There are still some clipping issues, though.

I don't have a Mac so someone needs to fix that if it's broken.

[1]https://github.com/harfbuzz/harfbuzz/releases
[2]https://gerrit.libreoffice.org/c/core/+/115014
[3]https://gerrit.libreoffice.org/c/core/+/115018
[4]https://gerrit.libreoffice.org/c/core/+/115016
[5]https://gerrit.libreoffice.org/c/core/+/115017




-- 
Mark Hung
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: Fwd: Drawing vertical text glyphs

2021-04-29 Thread Mark Hung
Hi Lubos,

Luboš Luňák  於 2021年4月29日 週四 上午1:19寫道:

> On Wednesday 28 of April 2021, Mark Hung wrote:
> > Anyway, if you need someone to verify text layout results with vertical
> > writing or
> > , don't hesitate to ask.
> >
> > I can definitely help. I can also verify patches on Windows.
> > There is also a telegram group of TDF members from the CJK area if you
> > prefer.
>
>  The Skia VCL backend code for text drawing is
> SkiaSalGraphicsImpl::drawGenericLayout(). For non-vertical glyphs, the
> code
> is easy, just iterate over all glyphs and pass them to Skia with their
> positions, possibly rotated. That approach doesn't work well for vertical
> glyphs, for the tdf#103785 document I get [1], with the glyphs being
> positioned too high. If I apply the attached patch that moves all vertical
> glyphs down based on the glyph height, then I get [2], which appears to be
> at
> least roughly acceptable, although it doesn't look to be completely
> correct.
>
>  And I don't know how to make it correct. First of all, I don't know how
> to
> visually identify what is correct. At [3] I've uploaded screenshots of the
> document rendered by LO/Cairo, LO/GDI and Word2013. They are all
> different,
> both in X and Y positioning. Cairo draws them slightly to the left of the
> latin alphabet characters, GDI is roughly centered, Word draws them to the
> right. Vertically they also differ, I made sure to include cursor in all
> the
> screenshots and e.g. with the first glyph (中) the cursor doesn't touch the
> glyph with Word, it touches it with GDI and it overlaps the glyph with
> Cairo
> (the image may need zooming to see it clearly). Which of those are correct?
>
>
To be honest, I can only verify from the point of view of a user who can
read Chinese.

The cursor which overlaps the position doesn't seem right. It's not a big
problem
as long as it does not strike through the glyph in the middle. But the
inconsistence among
platforms might be a problem.
I would have tested fullwidth punctuations.
It went wrong in vertical writing before.


>  Second, I would need to express the correct positioning in the code. Do
> you
> know how to do that? I copied the glyph-size change in the attached patch
> from Cairo, it also moves in X direction by the font descent, but I'd
> prefer
> not to do random modifications without understanding them.
>
>
I tried to make a patch to highlight the relative positions, and find out
something that I added
to fix the issue - of course it can not complete fix the problem, but it
may make more sense.

https://gerrit.libreoffice.org/c/core/+/114887
( the image of the test of the patch is also attached. )

Vertical positioning there is more correct to me. It also doesn't overlap
with the cursor. It introduce
horizontal offset issue unfortunately.

Hope that helps.



> [1] https://people.collabora.com/~llunak/skia/skia_current.png
> [2] https://people.collabora.com/~llunak/skia/skia_vert1.png
> [3] https://people.collabora.com/~llunak/skia/
>
> --
>  Luboš Luňák
>  l.lu...@collabora.com
>


-- 
Mark Hung
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: Fwd: Drawing vertical text glyphs

2021-04-28 Thread Luboš Luňák
On Wednesday 28 of April 2021, Mark Hung wrote:
> Anyway, if you need someone to verify text layout results with vertical
> writing or
> , don't hesitate to ask.
>
> I can definitely help. I can also verify patches on Windows.
> There is also a telegram group of TDF members from the CJK area if you
> prefer.

 The Skia VCL backend code for text drawing is 
SkiaSalGraphicsImpl::drawGenericLayout(). For non-vertical glyphs, the code 
is easy, just iterate over all glyphs and pass them to Skia with their 
positions, possibly rotated. That approach doesn't work well for vertical 
glyphs, for the tdf#103785 document I get [1], with the glyphs being 
positioned too high. If I apply the attached patch that moves all vertical 
glyphs down based on the glyph height, then I get [2], which appears to be at 
least roughly acceptable, although it doesn't look to be completely correct.

 And I don't know how to make it correct. First of all, I don't know how to 
visually identify what is correct. At [3] I've uploaded screenshots of the 
document rendered by LO/Cairo, LO/GDI and Word2013. They are all different, 
both in X and Y positioning. Cairo draws them slightly to the left of the 
latin alphabet characters, GDI is roughly centered, Word draws them to the 
right. Vertically they also differ, I made sure to include cursor in all the 
screenshots and e.g. with the first glyph (中) the cursor doesn't touch the 
glyph with Word, it touches it with GDI and it overlaps the glyph with Cairo 
(the image may need zooming to see it clearly). Which of those are correct?

 Second, I would need to express the correct positioning in the code. Do you 
know how to do that? I copied the glyph-size change in the attached patch 
from Cairo, it also moves in X direction by the font descent, but I'd prefer 
not to do random modifications without understanding them.

[1] https://people.collabora.com/~llunak/skia/skia_current.png
[2] https://people.collabora.com/~llunak/skia/skia_vert1.png
[3] https://people.collabora.com/~llunak/skia/

-- 
 Luboš Luňák
 l.lu...@collabora.com
diff --git a/vcl/skia/gdiimpl.cxx b/vcl/skia/gdiimpl.cxx
index 003c761542ff..9fb51868baf5 100644
--- a/vcl/skia/gdiimpl.cxx
+++ b/vcl/skia/gdiimpl.cxx
@@ -2084,9 +2084,19 @@ void SkiaSalGraphicsImpl::drawGenericLayout(const GenericSalLayout& layout, Colo
 {
 angle = layout.GetOrientation();
 if (pGlyph->IsVertical())
-angle += 900_deg10; // 90 degree
+//angle += 900_deg10; // 90 degree
+angle = 0_deg10;
 }
-SkRSXform form = SkRSXform::Make(toCos(angle), toSin(angle), aPos.X(), aPos.Y());
+SkRSXform form;
+if(pGlyph->IsVertical())
+{
+tools::Rectangle rect;
+bool b = pGlyph->GetGlyphBoundRect(rect);
+assert(b);
+form = SkRSXform::Make(toCos(angle), toSin(angle), aPos.X(), aPos.Y() + rect.GetHeight());
+}
+else
+form = SkRSXform::Make(toCos(angle), toSin(angle), aPos.X(), aPos.Y());
 glyphForms.emplace_back(std::move(form));
 }
 if (glyphIds.empty())
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice


Fwd: Drawing vertical text glyphs

2021-04-28 Thread Mark Hung
Hi,

I just found that I didn't send to the list.

-- Forwarded message -
寄件者: Mark Hung 
Date: 2021年4月28日 週三 上午12:46
Subject: Re: Drawing vertical text glyphs
To: Luboš Luňák 


Hi Lubos,

Maybe it's after I commited 51b9042efea0, that
I started to feel that vertical writing just worked by coincidence.

I tried to start from what we get from Harfbuzz. In theory, if the
sample code with Cairo there works, then we can expect the correct result
in LibreOffice.

We rotate things at many places. I'd prefer to get rid of those rotations
if possible.
For example in SalLayout::GetDrawPosition called by
GenericSalLayout::GetNextGlyph

And underlying platform code rotate them again, like calling
cairo_matrix_rotate
in CairoTextRender::DrawTextLayout.

I wonder where the center is when rotation is applied.
And how GetNextGlyph() returns a position that is unified among all the
underlying text render API on all platforms.
Do all of them have the same offset from reference point to the origin of a
glyph?


These are unanswered questions to myself.

Anyway, if you need someone to verify text layout results with vertical
writing or
, don't hesitate to ask.

I can definitely help. I can also verify patches on Windows.
There is also a telegram group of TDF members from the CJK area if you
prefer.



Luboš Luňák  於 2021年4月26日 週一 下午6:30寫道:

>
>  Hello,
>
>  is here somebody who understands drawing vertical (asian etc.) texts? I
> need
> help in that area for the Skia backend.
>
>  Specifically, the problems are tdf#137907, tdf#136081 and tdf#105650,
> which
> all stem from the same problem of positioning vertical glyphs.
> Positioning "normal" horizontal glyphs works fine, even in rotated text.
> I've
> looked at other VCL backends, and most of them handle vertical glyphs
> specially[*], and each of them in a different way. And the visual results
> are
> also different for those that I can check, and even that is different from
> what I can see if I check e.g. tdf#103785 in MS Office.
>
>  Given that I don't have that deep understanding of font rendering and I'm
> also not familiar with languages that need vertical glyphs, I have no idea
> what the correct way to do this should be. Is there somebody who
> understands
> this and could help me (preferably with knowledge of how it works, but
> even
> just being able to visually tell what's correct could do).
>
> [*] AquaSalGraphics::DrawTextLayout(), CairoTextRender::DrawTextLayout(),
> PrinterGfx::DrawGlyph(), ExTextOutRenderer::operator() , make your pick
>
> --
>  Luboš Luňák
>  l.lu...@collabora.com
> ___
> LibreOffice mailing list
> LibreOffice@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/libreoffice
>


-- 
Mark Hung


-- 
Mark Hung
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice