LayoutFarm/Typography

Documentation on building and how to run the demos?

solstice333 opened this issue ยท 21 comments

I'm working on OSX 10.11.6 with Visual Studio Community 7.7.3 and Mono 5.16. I just recently cloned this and am having a little trouble figuring out how to build the project so I can get the demos to run. Can someone point me towards any documentation or give any advice on this? Ultimately my goal is to extract the contour/outline points of glyphs contained within a .ttf and then also (separately) extract triangulation vertex points of those same glyphs. I'm presuming all of this is possible with this library.

I started out by new Typography.OpenFont.OpenFontReader().Read(stream) then exploring the APIs by myself. Although it is named like only OTFs are supported, OTF is actually an extension of TTFs so you can read TTFs too.

Do you recommend building any dll assemblies prior? Or is the Typography.* namespace source, in its current state, meant to be used directly? I'm assuming the latter.

I created a project and did "add solution folder" at the top-level and called it Typography. I did "add existing project" for each of the Typography.* and Unpack_SH .shproj files, and nested them under the Typography solution folder that I just created. For my main project references (edit references), I added all the references to all the Typography namespaces. I guess this is one way to organize a project to use the Typography lib. AFAIK, there's no dll's to be built unless you're trying to run the demos b.c. I think at least one of the demos is dependent on the N20 (.Net 2.0) compilation which seem to be buildable as dlls.

@solstice333,

You can open 'Typography.sln' with VS2017,
I provide it at root of the repo here =>

https://github.com/LayoutFarm/Typography/blob/master/Typography.sln

Did you open it?

@prepare yeah, I opened Typography.sln first to sort of play around with the repo and try to get the demos to run. I figured ok I'll build the entire solution and run the demos but ran into build errors b.c. it seems like certain projects need to be built in a certain order, particularly for the Typography sln's that are named Typography_Build, which I guess are to ensure backwards compatibility for older .NET. Are you saying that the repo is meant to be a sln template or a project starting point?

Well I tried opening a ttf via FileStream passed to OpenFontReader.Read(). Ran into build errors where one of them was in Typography.Contours/GlyphAnalysis/0_GlyphTriangle.cs. The import of the Poly2Tri namespace could not be resolved so I did a search for where that's defined. According to the solution structure, looks like it's under Demo/PixelFarm/Triangulation/Delaunay/*.cs. In the filesystem structure, however, PixelFarm isn't nested underneath Demo, so I guess it's actually part of the core library. Am I right to presume that it's part of the core library and not just part of the demo?

When you build from a Typography.sln file

All the examples should be compiled successfully.

for PixelFarm, Typography should use a snapshot
in the folder name => *https://github.com/LayoutFarm/Typography/tree/master/PixelFarm

eg. Poly2Tri namespace should be here
https://github.com/LayoutFarm/Typography/tree/master/PixelFarm/BackEnd.Tesselate


If you create a new sln project => It would be hard for the first time. ( for me too)

@solstice333 ,

I'll build the entire solution and run the demos but ran into build errors b.c. it seems like certain projects need to be built in a certain orde

The solution file has a correct order of how to build, please build it from
solution first.

Could you provide the error msg?

Ok, I'm getting closer. So far what I've done was

  1. Add (almost) all .shproj's except the PaintFx.Shared.shproj one
  2. Add references to all .shproj's added above
  3. Add OpenTK through NuGet. Add references to OpenTK
  4. Add references to System.Numerics
  5. Add System.Runtime.CompilerServices.Unsafe through NuGet. Add references to System.Runtime.CompilerServices.Unsafe

Which results in...

screen shot 2019-02-08 at 2 43 14 am

So I'm pretty much just doing the below. Nothing too crazy yet...

screen shot 2019-02-08 at 1 42 31 am

When I compile, I get...

screen shot 2019-02-08 at 2 46 45 am

Hitting f12 navigates me to TessTool.TessPolygon(float[], int[]) where flattenPoints and endContours are valid arguments. There is no third out parameter in the signature. There are no overloads. Any advice on this? nTessElems is used immediately on the next line so I guess it needs to be initialized somehow.

Ultimately my goal is to extract the contour/outline points of glyphs contained within a .ttf and then also (separately) extract triangulation vertex points of those same glyphs.

Not related to the building issue you are facing. But I can ensure you that Typopgraphy is able to offer all the functions you want. I have used a earlier version of Typography in one of my projects and all these features do work.

@solstice333 ,

I'll build the entire solution and run the demos but ran into build errors b.c. it seems like certain projects need to be built in a certain orde

The solution file has a correct order of how to build, please build it from
solution first.

Could you provide the error msg?

Just saw this post. Here's what I get when building the Typography solution (368c50e). Prior to building I confirmed that git status reported "working tree clean".

screen shot 2019-02-08 at 3 30 15 am

Ultimately my goal is to extract the contour/outline points of glyphs contained within a .ttf and then also (separately) extract triangulation vertex points of those same glyphs.

Not related to the building issue you are facing. But I can ensure you that Typopgraphy is able to offer all the functions you want. I have used a earlier version of Typography in one of my projects and all these features do work.

I appreciate the confirmation. Which SHA is this? I'll give it a shot.

I switch back to test the 'master' branch again,
It still ok.

typo_master1
pic 1: still ok, on master branch


typo_master2
pic 2: I notice this


typo_master3
pic 3: simple tesselation


from your err screen
It look like it can't build some project(s).
How to find it?

In this case,
start at project that has least asm reference =>
build it first=> do the same ...
then check if project can't be built.

eg build in the following order

typo_master4

pic 4: eg build in the following order


typo_master5

pic 5: and tess lib still ok too


Wait ...

I know, I build on Win7, WinForms
and I think I skip building DrawingGL.Common example.
Let me test it too, because I see you want to use

                //do tess  
                int[] endContours;
                float[] flattenPoints = _curveFlattener.Flatten(writablePath._points, out endContours);
                int nTessElems;

@solstice333
OK , I see the same error when build with Android example
please wait for the fix

@solstice333

Thank you for your report :)

I fix the errors on Android and iOS , now all build pass,
and push to master branch => ba450a2


I test on Android Emu, here is the screenshot of the latest master.

android
Android Emu, on Win10, VS2017


(on iOS example => build pass but not test yet).

please note that
Android and iOS version are just examples.

I don't use the optimum methods for
render a text.

I'm working on the better method (Gpu-based).
It will finish soon.

Oh, sorry. I meant to point out that I'm developing for OSX and not mobile. Regardless, I think I'm getting used to how to navigate around and use this library. Part of the problem was that I'm a total noob and thought command + enter was the keybindings to build and run w/ debugging for an individual project, but it was actually building whole solutions which made things harder to debug dependency issues.

Anyway, it seems the easiest way to use this library is to know which demo you need, try to build it individually as a project, and add references as needed. In other words, what worked for me (on ba450a2) is...

For Demo/Windows/GlyphTess.WinForms

  1. Build -> General -> TargetFramework: 4.7.1
  2. Build -> General -> Allow 'unsafe' code
  3. References -> Edit -> Add System.Numerics
  4. Click on GlyphTess.WinForms -> command + k to build project
  5. Right click on GlyphTess.WinForms -> Start Debugging Item

And the GUI renders fine. Modifying the "Single Char" field causes a crash throwing an IO.FileNotFoundException. Looks like a Windows path is being concatenated to a Unix path which isn't bad:

System.IO.FileNotFoundException: Could not find file "/.../Typography/Demo/Windows/GlyphTess.WinForms/bin/Debug/d:\WImageTest\Alfa_Slab.ttf"
File name: '/.../Typography/Demo/Windows/GlyphTess.WinForms/bin/Debug/d:\WImageTest\Alfa_Slab.ttf'

I think this demo project and its dependencies are mostly what I need.

Doing the same for GdiPlusSample.WinForms results in a NullReferenceException being thrown at...

Typography.TextServices.InstalledFontCollection.AddFont(Typography.TextServices.FontFileStreamProvider src) in /.../Typography/Demo/Shared/DevTextPrinter/FontManagement.cs:246
Typography.TextServices.InstalledFontCollectionExtension.LoadFontsFromFolder(Typography.TextServices.InstalledFontCollection fontCollection, string folder) in /.../Typography/Demo/Shared/DevTextPrinter/FontManagement.cs:450
SampleWinForms.Form1..ctor() in /.../Typography/Demo/Windows/GdiPlusSample.WinForms/Form1.cs:58
SampleWinForms.Program.Main() in /.../Typography/Demo/Windows/GdiPlusSample.WinForms/Program.cs:17

With a locals snapshot of...

screen shot 2019-02-08 at 4 43 05 pm

Alright, this should give me enough to chew on for awhile. Hopefully this helps someone else who is working in a similar environment. Thanks everyone for your patience and support.

From latest error,
the GdiPlusSample.WinForms demo try to read woff2 (Roboto-Regular)

but that Demo I did not provide the Woff2 decode handler

if you want to read Woff, Woff2
please see read this

Woff/Woff2 here #27 (comment)

I provide Woff2 example in another demo
here https://github.com/LayoutFarm/Typography/blob/master/Demo/Windows/PixelFarmSample.WinForms/Form1.cs#L49

If you don't want to use Woff2, => just skip reading that file

@prepare Ah, got it. Ok, I think that's pretty much it. Closing the thread now. Thanks again.