diff options
author | Context Git Mirror Bot <phg42.2a@gmail.com> | 2015-06-12 10:15:04 +0200 |
---|---|---|
committer | Context Git Mirror Bot <phg42.2a@gmail.com> | 2015-06-12 10:15:04 +0200 |
commit | c727ed7331960718681fa4222bec81fb577b56fb (patch) | |
tree | e90818d7ead83f08561f6c89396e1f5f1074b157 /metapost/context/base/mp-grph.mpiv | |
parent | 3e816646efde05d34564646800299790d32a2607 (diff) | |
download | context-c727ed7331960718681fa4222bec81fb577b56fb.tar.gz |
2015-06-12 10:08:00
Diffstat (limited to 'metapost/context/base/mp-grph.mpiv')
-rw-r--r-- | metapost/context/base/mp-grph.mpiv | 177 |
1 files changed, 131 insertions, 46 deletions
diff --git a/metapost/context/base/mp-grph.mpiv b/metapost/context/base/mp-grph.mpiv index a3c057a98..5938b9f02 100644 --- a/metapost/context/base/mp-grph.mpiv +++ b/metapost/context/base/mp-grph.mpiv @@ -118,7 +118,18 @@ def doloadfigure (expr filename) text figureattributes = endgroup ; enddef ; -def graphictext primary t = +% shared between old and new + +boolean mfun_gt_color_fill ; +boolean mfun_gt_color_draw ; +boolean mfun_gt_shade_fill ; +boolean mfun_gt_reverse_fill ; +boolean mfun_gt_outline_fill ; +picture mfun_gt_picture ; + +% this is the old version: + +def old_graphictext primary t = hide ( if mfun_trial_run : let mfun_graphic_text = mfun_no_graphic_text ; @@ -146,7 +157,7 @@ def mfun_no_graphic_text (expr t) text rest = withpostscript t enddef ; -def mfun_finish_graphic_text text x_op_x = +def mfun_finish_graphic_text text rest = protectgraphicmacros ; % resets currentpicture interim linecap := butt ; % normally rounded interim linejoin := mitered ; % normally rounded @@ -166,84 +177,158 @@ def mfun_finish_graphic_text text x_op_x = def fill expr p = addto scratchpicture contour p withpen currentpen ; enddef ; - def f_op_f = enddef ; boolean f_color ; f_color := false ; - def d_op_d = enddef ; boolean d_color ; d_color := false ; - def s_op_s = enddef ; boolean s_color ; s_color := false ; - boolean reverse_fill ; reverse_fill := false ; - boolean outline_fill ; outline_fill := false ; + def mfun_gt_fill = enddef ; boolean mfun_gt_color_fill ; mfun_gt_color_fill := false ; + def mfun_gt_draw = enddef ; boolean mfun_gt_color_draw ; mfun_gt_color_draw := false ; + def mfun_gt_shade = enddef ; boolean mfun_gt_shade_fill ; mfun_gt_shade_fill := false ; + boolean mfun_gt_reverse_fill ; mfun_gt_reverse_fill := false ; + boolean mfun_gt_outline_fill ; mfun_gt_outline_fill := false ; def reversefill = - hide(reverse_fill := true ) + hide(mfun_gt_reverse_fill := true ) enddef ; def outlinefill = - hide(outline_fill := true ) + hide(mfun_gt_outline_fill := true ) enddef ; def withshade primary c = - hide(def s_op_s = normalwithshade c enddef ; s_color := true ) + hide(def mfun_gt_shade = normalwithshade c enddef ; mfun_gt_shade_fill := true ) enddef ; def withfillcolor primary c = - hide(def f_op_f = withcolor c enddef ; f_color := true ) + hide(def mfun_gt_fill = withcolor c enddef ; mfun_gt_color_fill := true ) enddef ; def withdrawcolor primary c = - hide(def d_op_d = withcolor c enddef ; d_color := true ) + hide(def mfun_gt_draw = withcolor c enddef ; mfun_gt_color_draw := true ) enddef ; scratchpicture := nullpicture ; - addto scratchpicture doublepath origin x_op_x ; % pre-roll + addto scratchpicture doublepath origin rest ; % pre-roll for i within scratchpicture : % Below here is a dirty tricky test! if (urcorner dashpart i) = origin : - outline_fill := false ; + mfun_gt_outline_fill := false ; fi ; endfor ; scratchpicture := nullpicture ; readfile(data_mpy_file) ; scratchpicture := (scratchpicture shifted -llcorner scratchpicture) scaled (1/10) ; - if not d_color and not f_color : - d_color := true ; + if not mfun_gt_color_draw and not mfun_gt_color_fill : + mfun_gt_color_draw := true ; fi - if s_color : - d_color := false ; - f_color := false ; + if mfun_gt_shade_fill : + mfun_gt_color_draw := false ; + mfun_gt_color_fill := false ; fi ; currentpicture := figurepicture ; - if d_color and not reverse_fill : + if mfun_gt_shade_fill : for i within scratchpicture : - if f_color and outline_fill : - addto currentpicture doublepath pathpart i _op_ x_op_x f_op_f dashed nullpicture ; - fi ; if filled i : - addto currentpicture doublepath pathpart i _op_ x_op_x d_op_d ; - fi ; - endfor ; - fi ; - if f_color : - for i within scratchpicture : - if filled i : - addto currentpicture contour pathpart i _op_ x_op_x f_op_f withpen pencircle scaled 0 ; - fi ; - endfor ; - fi ; - if d_color and reverse_fill : - for i within scratchpicture : - if filled i : - addto currentpicture doublepath pathpart i _op_ x_op_x d_op_d ; - fi ; - endfor ; - fi ; - if s_color : - for i within scratchpicture : - if filled i : - addto currentpicture contour pathpart i _op_ x_op_x s_op_s ; + addto currentpicture contour pathpart i _op_ rest mfun_gt_shade ; fi ; endfor ; else : + if mfun_gt_color_draw and not mfun_gt_reverse_fill : + for i within scratchpicture : + if mfun_gt_color_fill and mfun_gt_outline_fill : + addto currentpicture doublepath pathpart i _op_ rest mfun_gt_fill dashed nullpicture ; + fi ; + if filled i : + addto currentpicture doublepath pathpart i _op_ rest mfun_gt_draw ; + fi ; + endfor ; + fi ; + if mfun_gt_color_fill : + for i within scratchpicture : + if filled i : + addto currentpicture contour pathpart i _op_ rest mfun_gt_fill withpen pencircle scaled 0 ; + fi ; + endfor ; + fi ; + if mfun_gt_color_draw and mfun_gt_reverse_fill : + for i within scratchpicture : + if filled i : + addto currentpicture doublepath pathpart i _op_ rest mfun_gt_draw ; + fi ; + endfor ; + fi ; for i within scratchpicture : if stroked i : - addto currentpicture doublepath pathpart i _op_ x_op_x d_op_d ; + addto currentpicture doublepath pathpart i _op_ rest mfun_gt_draw ; fi ; endfor ; fi ; endgroup ; enddef ; +% and this is the new one: + +% boolean mfun_gt_color_fill ; +% boolean mfun_gt_color_draw ; +% boolean mfun_gt_shade_fill ; +% boolean mfun_gt_reverse_fill ; +% picture mfun_gt_picture ; + +def mfun_gt_default = % somewhat compatible + scaled 11.5 + withpen pencircle scaled .1 +enddef ; + +def new_graphictext primary t = % use outlinetext instead + begingroup ; + mfun_graphic_text_indeed(t) +enddef ; + +def mfun_graphic_text_indeed(expr t) text rest = + interim linecap := butt ; % normally rounded + interim linejoin := mitered ; % normally rounded + % interim miterlimit := 10 ; % todo + % + let normalwithshade = withshade ; + % + save reversefill, outlinefill, withshade, withfillcolor, withdrawcolor ; + % + def mfun_gt_fill = enddef ; + def mfun_gt_draw = enddef ; + def mfun_gt_shade = enddef ; + % + mfun_gt_color_fill := false ; + mfun_gt_color_draw := false ; + mfun_gt_shade_fill := false ; + mfun_gt_reverse_fill := false ; + % + def reversefill = hide(mfun_gt_reverse_fill := true) enddef ; + def outlinefill = enddef ; + def withshade primary c = hide(mfun_gt_shade_fill := true; def mfun_gt_shade = normalwithshade c enddef ;) enddef ; + def withfillcolor primary c = hide(mfun_gt_color_fill := true; def mfun_gt_fill = withcolor c enddef ;) enddef ; + def withdrawcolor primary c = hide(mfun_gt_color_draw := true; def mfun_gt_draw = withcolor c enddef ;) enddef ; + % + mfun_gt_picture := nullpicture ; + addto mfun_gt_picture doublepath origin rest ; % preroll + mfun_gt_picture := nullpicture ; + % + def reversefill = enddef ; + def outlinefill = enddef ; + def withshade primary c = enddef ; + def withfillcolor primary c = enddef ; + def withdrawcolor primary c = enddef ; + % + if mfun_gt_shade_fill : + draw outlinetext.f(t)(mfun_gt_shade) rest; + elseif mfun_gt_color_fill and mfun_gt_color_draw : + if mfun_gt_reverse_fill : + draw outlinetext.r(t)(mfun_gt_default mfun_gt_fill rest)(mfun_gt_default mfun_gt_draw rest) ; + else : + draw outlinetext.b(t)(mfun_gt_default mfun_gt_draw rest)(mfun_gt_default mfun_gt_fill rest); + fi ; + elseif mfun_gt_color_fill : + draw outlinetext.f(t)(mfun_gt_default mfun_gt_fill rest) ; + elseif mfun_gt_color_draw : + draw outlinetext.d(t)(mfun_gt_default mfun_gt_draw rest) ; + else : + draw outlinetext.d(t)(mfun_gt_default rest) ; + fi ; + % + endgroup ; +enddef ; + +let graphictext = old_graphictext ; +%%% graphictext = new_graphictext ; % more than 10 times faster + % example % % beginfig (1) ; |