Giter Club home page Giter Club logo

typography's Introduction

Hello !

nearly acid1

pic 1: HtmlRenderer, Gdi+, see test file

seems promising ?, NEARLY pass ACID1 test :)


Work In Progrss ... : Cross Platform HtmlRenderer

The HtmlRenderer example!

gles_html pic 2: HtmlRenderer on GLES2 surface, text are renderered with the Typography

gles_html pic 3: HtmlRenderer on GLES2 surface

also, please note the text selection on the Html Surface.

(HtmlRender => https://github.com/LayoutFarm/HtmlRenderer,

Typography => https://github.com/LayoutFarm/Typography)


How to build it

see https://github.com/LayoutFarm/HtmlRenderer.Build


Work In Progrss ... : Html-input

Html input elements are built with 'html-fragment (sub dom)'

see more at #18

2019-03-31_21-55-37

pic3 : HtmlRenderer on GLES2 surface,developing Html-input, click to view full size img


The classic image. html_renderer_s01

pic 4: HtmlRenderer's Classic, Gdi+

MORE info / screen capture imgs -> see wiki

Build Note -> see wiki


I forked this project from https://github.com/ArthurHub/HTML-Renderer (thank you so much)

I added some features

such as

  1. dynamic html dom

  2. decoupling, dependency analysis

  3. optimizing the html,css parser. see: HtmlKit v1.0(https://github.com/jstedfast/HtmlKit)

  4. add svg/canvas support (not complete)

  5. abstract canvas backend (GDI+, OpenGL) also not complete for Linux (for the canvas backend, I used it from another project ->https://github.com/prepare/PixelFarm-dev)

  6. Javascript (v8) binding (https://github.com/prepare/Espresso)

  7. debug view

  8. more layout support eg. inline-block,relative, absolute ,fixed, flex etc

  9. added custom controls eg. text editer control, scrollbar, gridbox etc.

  10. some events (eg. mouse /keyboard events)

.. BUT not complete :(

feel free to fork/ comment/ suggest /pull request


Plan

  1. always permissive license (MIT,BSD, Apache2)

  2. bind some features from Blink engine

  3. add more html5/css3/js support

  4. convert to C++ code with some transpiler tools so users can build a final native code web browser

  5. to make this runs on .NetCore


Licenses

The project is based on multiple open-sourced projects (listed below) all using permissive licenses.

A license for a whole project is MIT.

but if you use some part of the code please check each source file's header for the licensing info.

Html Engine

BSD, 2009, José Manuel Menéndez Poo, https://www.codeproject.com/Articles/32376/A-Professional-HTML-Renderer-You-Will-Use

BSD, 2013-2014, Arthur Teplitzki, from https://github.com/ArthurHub/HTML-Renderer

MIT, 2015, Jeffrey Stedfastm, from HtmlKit https://github.com/jstedfast/HtmlKit

Javascript Engine

MIT, 2013, Federico Di Gregorio, from https://github.com/Daniel15/vroomjs

MIT, 2015-present, WinterDev, from https://github.com/prepare/Espresso

Geometry

BSD, 2002-2005, Maxim Shemanarev, from http://www.antigrain.com , Anti-Grain Geometry - Version 2.4,

BSD, 2007-2014, Lars Brubaker, agg-sharp, from https://github.com/MatterHackers/agg-sharp

ZLIB, 2015, burningmine, CurveUtils.

Boost, 2010-2014, Angus Johnson, Clipper.

BSD, 2009-2010, Poly2Tri Contributors, from https://github.com/PaintLab/poly2tri-cs

SGI, 2000, Eric Veach, Tesselate.

Image Processing

BSD, 2002-2005, Maxim Shemanarev, from http://www.antigrain.com , Anti-Grain Geometry - Version 2.4,

MIT, 2009-2015, Bill Reiss, Rene Schulte and WriteableBitmapEx Contributors, https://github.com/teichgraf/WriteableBitmapEx

MIT, 2008, dotPDN LLC, Rick Brewster, Chris Crosetto, Tom Jackson, Michael Kelsey, Brandon Ortiz, Craig Taylor, Chris Trevino, and Luke Walker., from OpenPDN v 3.36 (Paint.NET), https://github.com/rivy/OpenPDN

Font

MIT, 2016-present, WinterDev, Samuel Carlsson, Sam Hocevar and others, from https://github.com/LayoutFarm/Typography

Apache2, 2014-2016, Samuel Carlsson, from https://github.com/vidstige/NRasterizer

MIT, 2015, Michael Popoloski, from https://github.com/MikePopoloski/SharpFont

The FreeType Project LICENSE (3-clauses BSD style),2003-2016, David Turner, Robert Wilhelm, and Werner Lemberg and others, from https://www.freetype.org/

MIT, 2016, Viktor Chlumsky, from https://github.com/Chlumsky/msdfgen

Platforms

MIT, 2015-2015, Xamarin, Inc., from https://github.com/mono/SkiaSharp

MIT, 2006-2009, Stefanos Apostolopoulos and other Open Tool Kit Contributors, from https://github.com/opentk/opentk

MIT, 2013, Antonie Blom, from https://github.com/andykorth/Pencil.Gaming

MIT, 2004,2007, Novell Inc., for System.Drawing


Long Live Our Beloved C#

WinterDev :)

typography's People

Contributors

brezza92 avatar happypig375 avatar maheshpanthi11 avatar prepare avatar rachamimyaakobov avatar samhocevar avatar taleinat avatar vidstige avatar virzak avatar zwcloud avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

typography's Issues

Implement Bi-directional text

How to get the line height of a layouted text?

For example,

class MyTextPrinter : DevTextPrinterBase { ... }
//...
MyTextPrinter printer = new MyTextPrinter();
printer.FontFilename= "D:\msjh.ttf";
printer.FontSizeInPoints = 12;
printer.DrawString(new []{'A', 'B', 'C', '啊'}, 0, 0);

How to get the actual line height of the layouted and printed text? Is it just printer.FontSizeInPoints?
(I know the function of GlyphLayout is quite limited and can only layout text characters in one line.)

Demo not working for GdiPlus

Hi,

I have an issue on the demo. On my environment the GdiPlus demo is drawing characters at wrong positions. Though not familiar with the library, I tried to dig a little bit, and it seems that the DoGlyphPosition methods do nothing. The positions are not updated at all and remain at (0, 0).

I am using VS2017 and upgraded solution, but the build is successful (with a lot of warnings). Not sure whether this is the reason.

Thanks in advance.

Will this become the C# version DirectWrite or pango?

I desperately need a text-layout engine written in raw C#. DirectWrite is windows-only. And pango is almost impossible to be compiled on mobile platforms. ( I'm exhausted with cross-compiling, makefiles and defines. It has taken me almost two month to learn and try to achieve that but completely get nothing. )

Will Typography become the C# version DirectWrite or pango? I was searching for papers and algorithms for creating a text-layout engine myself before I ran into this project. It really amazed me when I saw Glyph Layout in ReadMe.

I'm really looking forward to your reply! @prepare

Documentation Project

First I'm not a native English speaking person.
so you can correct it where it is wrong grammar/ wrong intention or not proper.

You CAN HELP ME create the topics that you want to know.
so I will create a description for it

:)

Add ScriptLang ComboBox

ScriptLang plays an important role on Glyph Shaping

for example, Thai Script is a 'complex' script (need GSUB, GPOS)

script_01

pic 1: Thai glyphs with incorrect ScriptLang (in red box, latin), shows abnormal result

script_02
pic 2: Thai glyphs with correct ScriptLang (in red box, Thai), shows NORMAL result


Now, How about your 'Script' ?, Dose Typography present the text correct or not?

:)

Discussing the use of NotImplementedException

For the moment, NotImplementedException is thrown about whenever an unknown table format is encountered. For instance GPOS.cs has 12 such occurrences, GSUB.cs has 7, and GDEF.cs has 1. But all these three tables are optional in the standard. My understanding is that a client should just ignore the features it does not know about instead of throwing.

How would you feel about replacing those throws with safe fallbacks instead? I can try to do the work but I wanted your thoughts about it first.

(Context: I’m currently writing my own parser for a subset of OpenType for Emoji.Wpf and I thought it might be interesting to use Typography.OpenFont instead, and contribute some of my code.)

How to get a glyph from character directly?

For example, for character 'D', the glyph index for msjh.ttf and Helvetica.ttf are both 39. But for unifont-9.0.06.ttf, the glyph index is 71.

The only way to get a Glyph I found is Typeface.GetGlyphByIndex(). I want to know whether we can get the glyph from the character D directly?

Incorrect RGB ordering

If I set canvasPainter.FillColor = new Color(255, 0, 0); in VcxTextPrinter.cs I would expect that the text is rendered in red, but instead it is rendered in blue (using the PixelFarmSample.WinForms sample).

Swapping R and B in ColorOrder.cs results in the correct color being used, but I don’t know where the actual bug is.

As a result, the code in CPAL.cs is incorrect with regards to RGB ordering. The buffer is in BGRA format and the GetColor code should be as follows:

b = colorBGRABuffer[startAt];
g = colorBGRABuffer[startAt + 1];
r = colorBGRABuffer[startAt + 2];
a = colorBGRABuffer[startAt + 3];

Bad rendering method in the OpenGLES based demo.

From this, we can see each GlyphRun uses a drawcall and it harms performance badly when rendering a string containing many characters.

I think we should apply the offset when we fill the vertex buffer. I mean, bake the offset into vertex instead of offset every glyph in vertex shader, just like what I have done before in my original OpenGLES demo.

Update:
No, my soultion is incorrect partially. The mesh should only be moved after it is built. Otherwise we can not re-use the old mesh when the position of text is changed but its content and style remains the same. But I think the offset of each glyph should be applied to built vertices.


@prepare's note:

  • add VBO version for GLES glyph rendering

Possible Bug of Typography.OpenFont.IO.ByteOrderSwappingBinaryReader

When I'm testing a ttf file with Typography, Typography.OpenFont.IO.ByteOrderSwappingBinaryReader.ReadInt16 throw an System.IO.EndOfStreamException: 'Unable to read beyond the end of the stream.'

Stack:

Typography.OpenFont.IO.ByteOrderSwappingBinaryReader.ReadInt16() Line 59	C#
Typography.OpenFont.Tables.GPOS.ValueRecord.ReadFrom(System.IO.BinaryReader reader, ushort valueFormat) Line 107	C#
Typography.OpenFont.Tables.GPOS.ValueRecord.CreateFrom(System.IO.BinaryReader reader, ushort valueFormat) Line 158	C#
Typography.OpenFont.Tables.GPOS.PairSetTable.ReadFrom(System.IO.BinaryReader reader, ushort v1format, ushort v2format) Line 49	C#
Typography.OpenFont.Tables.GPOS.LookupTable.ReadLookupType2(System.IO.BinaryReader reader) Line 468	C#
Typography.OpenFont.Tables.GPOS.LookupTable.ReadRecordContent(System.IO.BinaryReader reader) Line 245	C#
Typography.OpenFont.Tables.GPOS.ReadLookupListTable(System.IO.BinaryReader reader, long lookupListBeginAt) Line 170	C#
Typography.OpenFont.Tables.GPOS.ReadContentFrom(System.IO.BinaryReader reader) Line 69	C#
Typography.OpenFont.Tables.TableEntry.LoadDataFrom(System.IO.BinaryReader reader) Line 22	C#
Typography.OpenFont.OpenFontReader.ReadTableIfExists<Typography.OpenFont.Tables.GPOS>(Typography.OpenFont.Tables.TableEntryCollection tables, System.IO.BinaryReader reader, Typography.OpenFont.Tables.GPOS resultTable) Line 162	C#
Typography.OpenFont.OpenFontReader.Read(System.IO.Stream stream, Typography.OpenFont.ReadFlags readFlags) Line 91	C#

The ttf font file I'm using:
DroidSans.zip. I forgot where it is from. But it can be opened by the Windows Font Viewer so it should be valid.

implement other essentail tables

@vidstige , please comment about this how-to-build-each-table

OpenType Layout
(https://www.microsoft.com/typography/otspec/ttochap1.htm)

  1. Name: created (https://github.com/prepare/FontRasterizer/blob/master/OpenTypeReader/Tables/NameEntry.cs)
  2. Kern: created (https://github.com/prepare/FontRasterizer/blob/master/OpenTypeReader/Tables/Kern.cs)
  3. Glyph Substitution table (GSUB) :developing ...
  4. the Glyph Positioning table (GPOS): developing ...
  5. the Baseline table (BASE): developing ...
  6. the Justification table (JSTF), and
  7. the Glyph Definition table (GDEF): developing ...

I've changed how to create each table.
see
https://github.com/prepare/FontRasterizer/blob/master/OpenTypeReader/OpenTypeReader.cs#L46

  1. All tables are subclass of TableEntry (https://github.com/prepare/FontRasterizer/blob/master/OpenTypeReader/Tables/TableEntry.cs)
  2. First, Load all as UnreadTableEntry
    ((https://github.com/prepare/FontRasterizer/blob/master/OpenTypeReader/OpenTypeReader.cs#L58)
  3. and substitute some of them with actual table
    (https://github.com/prepare/FontRasterizer/blob/master/OpenTypeReader/OpenTypeReader.cs#L63)
  4. I have created a Kern table and Name table

Suggest renaming the .sln file

I know it’s not a big deal, but when I Alt-Tab through my windows, the VS instance I use for Typography appears as “MainDev”, which is not really descriptive. Any problem with renaming it to Typography.sln?

image

Using Typography in my GUI lib.

Hi, @prepare

I don't know how to get in touch with you so I created this issue. It seems you are not on gitter yet. Would you mind joining this gitter group? We can discuss about further development of Typography together.

I have published my GUI lib. A former version of Typography is included.

You can see how Typography is used in TypographyTextContext.

Currently the text size and postion got from TypographyTextContext is not accurate. I will look into this issue later.

PS: Don't worry about the LGPL license. I'll grant you a permissive license for codes that directly related to Typography.

Vertical Metrics?

Any idea when you'll be implementing Vertical Metrics support in OpenFont?

Problem in GlyphIndexList.Replace()

At line 114 in GlyphIndexList.cs, _tmpGlypIndexBackup may be empty if the whole string was replaced with a ligature, so the code crashes there when accessing _tmpGlypIndexBackup[0].

I might be able to fix this later, but I do not really understand GlyphIndexToUserChar yet. Maybe you know what’s going on and can fix it more quickly than me :-)

implement Typography.TextService

we can cache this

key value
font+ small_word output glyph-plan

for faster glyph-sub/pos,

Implement as optional service (not in a core)
user can use it or not.

Differences in the MSDF generation results...

I've encountered some differences in the generation of MSDF bitmaps between this Typography library, and the original C++ MSDFGen implementation from which it is adapted.

With certain fonts (hand made ones, using FontForge) - certain glyphs are producing different MSDF maps - but it is only certain glyphs... the majority appear to be OK.

For example...

LayoutFarm - layoutfarm_b MSDFGen - msdfgen_b

Look pretty much equivalent (apart from the page size, but that's fine)

However, the same code generating glyph:

LayoutFarm - layoutfarm_a MSDFGen - msdfgen_a

Any idea what could be going on?

Font --- shardailes.zip

Add essential functions to GlyphLayout.

The current one is quite limited. I think as a text layout engine, at least the following functions should be added:

  1. layout text characters as one or multiple lines inside a rectangle, including alignment (nine position)
  2. given a point, get a index of the nearest character (hit-test)
  3. given an index of character, get the position of the caret/cursor
  4. reading direction-some languages reads from right to left
  5. calculate the exact size of specified text without rendering them-in this case, the user only cares about how much space the layouted glyphs will occupy, so no contours need to be exacted and only the size of each glyph is required. In the following picture, the size of dashed rectangle printed glyphs is the exact size of 啊rAbc.
  6. font family
  7. font style/stretch/weight

Also many basic conceptions need to be documented, including

  • coordinate system
  • text position definition
  • the scaling matters-I think it is related to dpi and the internal unit used in TrueType or OpenType.

textlayout

How others design the text-layout API:


@prepare's note
I make the tasks here ...

  • 1) layout text characters as one or multiple lines inside a rectangle, including alignment (nine position)
  • 2) given a point, get a index of the nearest character (hit-test) (see below)
  • 3) given an index of character, get the position of the caret/cursor (see below)
  • 4) reading direction-some languages reads from right to left
  • 5) calculate the exact size of specified text without rendering them (see #23)
  • 6) font family below...
  • 7) font style, font weight below...

Upgrade to VS2017

I think the project should be upgraded to VS2017 since it has been released.

The most important thing is that the support for .NET Standard(including .NET core) is greatly improved in VS2017. Also some project structures are changed. For example, project.json and *.xproj are no longer used. Instead, *.csproj is used for all C# projects in VS2017.

VS2017 can easily upgrade VS2015 solution and projects automatically. And I have done that on my machine.

I have been using VS2017 RC and RTM for several months. It provides more flexible installation and is smaller and quicker than the big VS2015. BTW, the android projects using Typography is written with VS2017--I can't install VS2015 on my machine because the remaining disk space is not enough.

TypeReader parts as NuGet package

I think it would be best to try to move out the ttf loader parts into a library, then you can just add a dependency from PixelFarm on that.

GPOS's PairPosFormat2 is not implemented

My artists have given me a new font that kills the importer - it appears to hit an NotImplementedException in GPOS.cs - at line 581.

The font has been authored in FontForge -- I'm not sure what to look for, or ask them to change to prevent the unsupported table format from being included.

Any suggestions?

MSDF Glyph Generation doesn't match Chlumsky's MSDFGen output

How up to date is your C# implementation to Chlumsky's MSDFGen tool (on which it is based)?
Glyph generation from your implementation does not match, and results in very blocky curves.

I modified the edgeColoringSimple function to match the MSDFGen implementation.
I also modified the ConvertToIntBmp in MsdfGen.cs to write out the color channels in the correct order (argb) (Although BMP stores the bytes in ABGR order, Intel ordering when the uint32_t is written out, changes that order - so we write out a uint32_t of argb, so that when BMP reads it in byte-by-byte, it comes in a ABGR)

I also wrote a little function that converts a contour list to a MSDFGen shape definition, to test the possibility that your contour list was somehow causing the problem. So I use Typography.OpenFont to generate the shape definition, and then cut/paste the output into the commandline of MSDFGen.
Unfortunately, MSDFGen works just fine with that shape, so that confirms that the problem is with your C# implementation of MSDFGen.

I've compared the .cpp and .cs files, but I can't see where the divergence might be (admittedly, it was very very late at night)

(I've attached the DumpContours.cs for anyone that might find it useful)

I've also attached a couple of screenshots of the resultant MSDF glyph generated from both MSDFGen and Typeography.MSDFGen when run through the MSDF pixel shader.

contours.txt

msdfgen msdf screenshot
msdfgen output
typeography msdf screenshot
typeography output

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.