问题
In my iPhone App I'd like to draw a few formulas. How can I manage that with quartz 2d? Is there a way to build formulas like for example in latex? Or are there any existing frameworks? Thanks.
回答1:
As the developer of an iPhone application which does just that, trust me when I say typesetting equations is not a trivial undertaking. In my case, I used Core Animation layers to construct the sub-elements of a parsed equation. The equations are constructed hierarchically, and the operations that compose them are laid out as such. Each operation is contained within its parent operation's layer, and laid out following the rules of that particular operation.
For rendering the visual elements of the operations within an equation, I used Quartz to draw lines, symbols, etc., but most of the drawing was simply text drawn within a CALayer using the NSString text drawing extensions.
I did override the standard CALayer rendering architecture for the generation of PDFs from these equations, because CALayers don't render as vector elements by default. For an example of how this rendering works in my application, see the open source Core Plot project, which does the same thing at its base level.
I do output to LaTeX from the equations, which is pretty simple once you've parsed them into a hierarchical data structure, but parsing them from LaTeX into that structure is proving a little trickier.
For simple text equation input and evaluation, you might find Graham Cox's GCMathParser to be of use.
回答2:
There's no real Tex engine implemented for Cocoa touch that I have heard of, but there is a lightweight Javascript formulae-layout engine: jsMath.
来源:https://stackoverflow.com/questions/2907045/drawing-formulas-with-quartz-2d