Drawing formulas with Quartz 2d

£可爱£侵袭症+ 提交于 2019-11-26 14:33:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!