summaryrefslogtreecommitdiff
path: root/metapost
diff options
context:
space:
mode:
Diffstat (limited to 'metapost')
-rw-r--r--metapost/context/mp-core.mp180
-rw-r--r--metapost/context/mp-page.mp144
-rw-r--r--metapost/context/mp-spec.mp10
3 files changed, 324 insertions, 10 deletions
diff --git a/metapost/context/mp-core.mp b/metapost/context/mp-core.mp
index 0c409264f..918838e33 100644
--- a/metapost/context/mp-core.mp
+++ b/metapost/context/mp-core.mp
@@ -316,6 +316,154 @@ def do_initialize_par (expr fpos, tpos, mpos, ppos, rw,rl,rr,rh,ra,ri) =
enddef ;
+if unknown TopSkip : TopSkip := 0 fi ;
+if unknown StrutHeight : StrutHeight := 0 fi ;
+
+pair last_multi_par_shift ; last_multi_par_shift := origin ;
+
+def relocate_multipars (expr xy) =
+ last_multi_par_shift := xy ;
+ for i=1 upto nofmultipars :
+ multipars[i] := multipars[i] shifted last_multi_par_shift ;
+ endfor ;
+enddef ;
+
+boolean compensate_multi_par_topskip ;
+compensate_multi_par_topskip := true ;
+
+boolean span_multi_column_pars ;
+span_multi_column_pars := false ;
+
+vardef multi_par_at_top (expr i) =
+ (round (ypart ulcorner multipars[i]) = round (ypart ulcorner
+ (TextAreas[multirefs[i]] shifted last_multi_par_shift)))
+enddef ;
+
+def prepare_multi_pars (expr fn,fx,fy,fw,fh,fd,
+ tn,tx,ty,tw,th,td,
+ wn,wx,wy,ww,wh,wd,
+ pn,px,py,pw,ph,pd,
+ rw,rl,rr,rh,ra,ri) =
+
+ if span_multi_column_pars :
+ begingroup ;
+ save TextAreas ; path TextAreas[] ;
+ save NOfTextAreas ; numeric NOfTextAreas ;
+ for i=1 upto NOfTextColumns :
+ TextAreas[i] := TextColumns[i] ;
+ endfor ;
+ NOfTextAreas := NOfTextColumns ;
+ fi ;
+
+ last_multi_par_shift := origin ;
+
+ % rh/ra/ri not yet supported
+
+ numeric fpos ; fpos := 1 ; initialize_box_pos(fpos,fn,fx,fy,fw,fh,fd) ;
+ numeric tpos ; tpos := 2 ; initialize_box_pos(tpos,tn,tx,ty,tw,th,td) ;
+ numeric wpos ; wpos := 3 ; initialize_box_pos(wpos,wn,wx,wy,ww,wh,wd) ;
+ numeric ppos ; ppos := 4 ; initialize_box_pos(ppos,pn,px,py,pw,ph,pd) ;
+
+ numeric par_strut_height, par_strut_depth, par_line_height ;
+
+ par_strut_height := ph ;
+ par_strut_depth := pd ;
+ par_line_height := ph + pd ;
+
+ if wxy[wpos]>0 :
+ left_skip := rl + xpart llxy[wpos] - xpart llxy[ppos] ;
+ right_skip := rw - left_skip - ww ;
+ else :
+ left_skip := rl ;
+ right_skip := rr ;
+ fi ;
+
+ path multipar, multipars[] ;
+ numeric multiref, multirefs[] ;
+ numeric multiloc, multilocs[] ; % 1=begin 2=between 3=end
+
+ ii := 0 ; nn := NOfTextAreas+1 ; nofmultipars := 0 ;
+
+ def set_multipar (expr i) =
+ ((TextAreas[i] leftenlarged -left_skip) rightenlarged -right_skip)
+ enddef ;
+
+ def save_multipar (expr i, l, p) =
+ nofmultipars := nofmultipars + 1 ;
+ multirefs[nofmultipars] := i ;
+ multilocs[nofmultipars] := l ;
+ multipars[nofmultipars] := unspiked simplified p ;
+ enddef ;
+
+ for i=1 upto NOfTextAreas :
+ multipar := set_multipar(i) ;
+ if (nxy[fpos]=RealPageNumber) and (InsideTextArea(i,llxy[fpos])) :
+ % first one in chain
+ ii := i ;
+ if (nxy[tpos]=RealPageNumber) and (InsideTextArea(i,llxy[tpos])) :
+ nn := i ;
+
+ if compensate_multi_par_topskip :
+ TopSkipCorrection := TopSkip - StrutHeight ;
+
+ if round(ypart ulxy[fpos] + TopSkipCorrection) =
+ round(ypart ulcorner TextAreas[i]) :
+ ulxy[fpos] := ulxy[fpos] shifted (0,TopSkipCorrection) ;
+ urxy[fpos] := urxy[fpos] shifted (0,TopSkipCorrection) ;
+ fi ;
+ fi ;
+
+ if ypart llxy[fpos] = ypart llxy[tpos] :
+ multipar := llxy[fpos] --
+ lrxy[tpos] --
+ urxy[tpos] --
+ ulxy[fpos] --
+ cycle ;
+ else :
+ multipar := (xpart llcorner multipar, ypart llxy[tpos]) --
+ llxy[tpos] --
+ ulxy[tpos] --
+ (xpart lrcorner multipar, ypart ulxy[tpos]) --
+ (xpart urcorner multipar, ypart urxy[fpos]) --
+ urxy[fpos] --
+ lrxy[fpos] --
+ (xpart ulcorner multipar, ypart lrxy[fpos])--
+ cycle ;
+ fi ;
+ else :
+ multipar := llcorner multipar --
+ lrcorner multipar --
+ (xpart lrcorner multipar, ypart urxy[fpos]) --
+ urxy[fpos] --
+ lrxy[fpos] --
+ (xpart ulcorner multipar, ypart lrxy[fpos])-- cycle ;
+ fi ;
+ save_multipar (i,1,multipar) ;
+ elseif (nxy[tpos]=RealPageNumber) and (InsideTextArea(i,llxy[tpos])) :
+ % last one in chain
+ nn := i ;
+ multipar := ulcorner multipar --
+ urcorner multipar --
+ (xpart lrcorner multipar, ypart urxy[tpos]) --
+ ulxy[tpos] --
+ llxy[tpos] --
+ (xpart llcorner multipar, ypart llxy[tpos]) --
+ cycle ;
+ save_multipar (i,3,multipar) ;
+ fi ;
+ endfor ;
+
+ for i=ii+1 upto nn-1 :
+ % rest of chain
+ save_multipar(i,2,set_multipar(i)) ;
+ endfor ;
+
+ if span_multi_column_pars :
+ endgroup ;
+ fi ;
+
+enddef ;
+
color boxgridcolor ; boxgridcolor := .8red ;
color boxlinecolor ; boxlinecolor := .8blue ;
color boxfillcolor ; boxfillcolor := .8white ;
@@ -347,13 +495,14 @@ def draw_par = % 1 2 11
endfor ;
enddef ;
+def do_show_par (expr p, r, c) =
+ if length(p) > 2 : for i=0 upto length(p) :
+ draw fullcircle scaled r shifted point i of p
+ withpen pencircle scaled .5pt withcolor c ;
+ endfor ; fi ;
+enddef ;
+
def show_par =
- def do_show_par (expr p, r, c) =
- if length(p) > 2 : for i=0 upto length(p) :
- draw fullcircle scaled r shifted point i of p
- withpen pencircle scaled .5pt withcolor c ;
- endfor ; fi ;
- enddef ;
if length(mxy) > 2 :
draw mxy dashed evenly
withpen pencircle scaled .5pt withcolor .5white ;
@@ -364,6 +513,25 @@ def show_par =
draw pref withpen pencircle scaled 2pt ;
enddef ;
+def draw_multi_pars =
+ for i=1 upto nofmultipars :
+ do_draw_par(multipars[i]) ;
+ if boxgridtype= 1 :
+ draw baseline_grid (multipars[i],boxgriddirection,true ) withcolor boxgridcolor ;
+ elseif boxgridtype= 2 :
+ draw baseline_grid (multipars[i],boxgriddirection,false) withcolor boxgridcolor ;
+ elseif boxgridtype=11 :
+ draw graphic_grid(multipars[i],distance,distance,distance/2,distance/2) ;
+ fi ;
+ endfor ;
+enddef ;
+
+def show_multi_pars =
+ for i=1 upto nofmultipars :
+ do_show_par(multipars[i], 6pt, .5blue) ;
+ endfor ;
+enddef ;
+
vardef do_draw_par (expr p) =
if (length p>2) and (bbwidth(p)>1) and (bbheight(p)>1) :
save pp ; path pp ;
diff --git a/metapost/context/mp-page.mp b/metapost/context/mp-page.mp
index 4dfdb1634..035b65bd6 100644
--- a/metapost/context/mp-page.mp
+++ b/metapost/context/mp-page.mp
@@ -31,6 +31,150 @@ if unknown InPageBody :
boolean InPageBody ; InPageBody := false ;
fi ;
+def SaveTextAreas =
+ path SavedTextAreas [] ;
+ path SavedTextColumns[] ;
+ numeric NOfSavedTextAreas ;
+ numeric NOfSavedTextColumns ;
+ for i=1 upto NOfTextAreas :
+ SavedTextAreas[i] := TextAreas[i] ;
+ endfor ;
+ for i=1 upto NOfTextColumns :
+ SavedTextColumns[i] := TextColumns[i] ;
+ endfor ;
+ NOfSavedTextAreas := NOfTextAreas ;
+ NOfSavedTextColumns := NOfTextColumns ;
+enddef ;
+
+def ResetTextAreas =
+ path TextAreas[], TextColumns[];
+ numeric NOfTextAreas ; NOfTextAreas := 0 ;
+ numeric NOfTextColumns ; NOfTextColumns := 0 ;
+enddef ;
+
+ResetTextAreas ; SaveTextAreas ;
+
+def RegisterTextArea (expr x, y, w, h, d) =
+ begingroup ; save p ; path p ;
+ p := unitsquare xyscaled(w,h+d) shifted (x,y-d) ;
+ if NOfTextAreas>0 :
+ % if needed, concatenate areas
+ if (round(llcorner TextAreas[NOfTextAreas]) = round(ulcorner p)) and
+ (round(lrcorner TextAreas[NOfTextAreas]) = round(urcorner p)) :
+ p := ulcorner TextAreas[NOfTextAreas] --
+ urcorner TextAreas[NOfTextAreas] --
+ lrcorner p --
+ llcorner p --
+ cycle ;
+ else :
+ NOfTextAreas := NOfTextAreas + 1 ;
+ fi ;
+ else :
+ NOfTextAreas := NOfTextAreas + 1 ;
+ fi ;
+ TextAreas[NOfTextAreas] := p ;
+ if NOfTextColumns>0 :
+ if (round(xpart llcorner TextColumns[NOfTextColumns]) = round(xpart ulcorner p)) and
+ (round(xpart lrcorner TextColumns[NOfTextColumns]) = round(xpart urcorner p)) :
+ p := ulcorner TextColumns[NOfTextColumns] --
+ urcorner TextColumns[NOfTextColumns] --
+ lrcorner p --
+ llcorner p --
+ cycle ;
+ else :
+ NOfTextColumns := NOfTextColumns + 1 ;
+ fi ;
+ else :
+ NOfTextColumns := NOfTextColumns + 1 ;
+ fi ;
+ TextColumns[NOfTextColumns] := p ;
+ endgroup ;
+enddef ;
+
+vardef InsideTextArea (expr _i_, _xy_) =
+ ( (round(xpart _xy_) >= round(xpart llcorner TextAreas[_i_])) and
+ (round(xpart _xy_) <= round(xpart lrcorner TextAreas[_i_])) and
+ (round(ypart _xy_) >= round(ypart llcorner TextAreas[_i_])) and
+ (round(ypart _xy_) <= round(ypart urcorner TextAreas[_i_])) )
+enddef ;
+
+vardef InsideSavedTextArea (expr _i_, _xy_) =
+ ( (round(xpart _xy_) >= round(xpart llcorner SavedTextAreas[_i_])) and
+ (round(xpart _xy_) <= round(xpart lrcorner SavedTextAreas[_i_])) and
+ (round(ypart _xy_) >= round(ypart llcorner SavedTextAreas[_i_])) and
+ (round(ypart _xy_) <= round(ypart urcorner SavedTextAreas[_i_])) )
+enddef ;
+
+vardef TextAreaX (expr x) =
+ numeric _TextAreaX_ ; _TextAreaX_ := 0 ;
+ for i := 1 upto NOfTextAreas :
+ if (round(x) >= round(xpart llcorner TextAreas[i])) and
+ (round(x) <= round(xpart lrcorner TextAreas[i])) :
+ _TextAreaX_ := xpart llcorner TextAreas[i] ;
+ fi ;
+ endfor ;
+ _TextAreaX_
+enddef ;
+
+vardef TextAreaY (expr y) =
+ numeric _TextAreaY_ ; _TextAreaY_ := 0 ;
+ for i := 1 upto NOfTextAreas :
+ if (round(y) >= round(ypart llcorner TextAreas[NOfTextAreas])) and
+ (round(y) <= round(ypart ulcorner TextAreas[NOfTextAreas])) :
+ _TextAreaY_ := ypart llcorner TextAreas[NOfTextAreas] ;
+ fi ;
+ endfor ;
+ _TextAreaY_
+enddef ;
+
+vardef TextAreaXY (expr x, y) =
+ pair _TextAreaXY_ ; _TextAreaXY_ := origin ;
+ for i := 1 upto NOfTextAreas :
+ if (round(x) >= round(xpart llcorner TextAreas[i])) and
+ (round(x) <= round(xpart lrcorner TextAreas[i])) and
+ (round(y) >= round(ypart llcorner TextAreas[i])) and
+ (round(y) <= round(ypart ulcorner TextAreas[i])) :
+ _TextAreaXY_ := llconer TextAreas[i] ;
+ fi ;
+ endfor ;
+ _TextAreaXY_
+enddef ;
+
+vardef TextAreaW (expr x) =
+ numeric _TextAreaW_ ; _TextAreaW_ := 0 ;
+ for i := 1 upto NOfTextAreas :
+ if (round(x) >= round(xpart llcorner TextAreas[i])) and
+ (round(x) <= round(xpart lrcorner TextAreas[i])) :
+ _TextAreaW_ := bbwidth(TextAreas[i]) ;
+ fi ;
+ endfor ;
+ _TextAreaW_
+enddef ;
+
+vardef TextAreaH (expr y) =
+ numeric _TextAreaH_ ; _TextAreaH_ := 0 ;
+ for i := 1 upto NOfTextAreas :
+ if (round(y) >= round(ypart llcorner TextAreas[i])) and
+ (round(y) <= round(ypart ulcorner TextAreas[i])) :
+ _TextAreaH_ := bbheight(TextAreas[i]) ;
+ fi ;
+ endfor ;
+ _TextAreaH_
+enddef ;
+
+vardef TextAreaWH (expr x, y) =
+ pair _TextAreaWH_ ; _TextAreaWH_ := origin ;
+ for i := 1 upto NOfTextAreas :
+ if (round(x) >= round(xpart llcorner TextAreas[i])) and
+ (round(x) <= round(xpart lrcorner TextAreas[i])) and
+ (round(y) >= round(ypart llcorner TextAreas[i])) and
+ (round(y) <= round(ypart ulcorner TextAreas[i])) :
+ _TextAreaWH_ := (bbwidth(TextAreas[i]),bbheight(TextAreas[i])) ;
+ fi ;
+ endfor ;
+ _TextAreaWH_
+enddef ;
+
PageNumber := 0 ;
PaperHeight := 845.04684pt ;
PaperWidth := 597.50787pt ;
diff --git a/metapost/context/mp-spec.mp b/metapost/context/mp-spec.mp
index 93a36a4eb..05f5cecad 100644
--- a/metapost/context/mp-spec.mp
+++ b/metapost/context/mp-spec.mp
@@ -158,17 +158,19 @@ fi ;
newinternal shadefactor ; shadefactor := 1 ;
+pair shadeoffset ; shadeoffset := origin ;
+
vardef define_linear_shade (expr a, b, ca, cb) =
flush_special(30, 15, "0 1 " & decimal shadefactor & " " &
- dddecimal ca & ddecimal a &
- dddecimal cb & ddecimal b ) ;
+ dddecimal ca & ddecimal (a shifted shadeoffset) &
+ dddecimal cb & ddecimal (b shifted shadeoffset) ) ;
_special_counter_
enddef ;
vardef define_circular_shade (expr a, b, ra, rb, ca, cb) =
flush_special(31, 17, "0 1 " & decimal shadefactor & " " &
- dddecimal ca & ddecimal a & " " & decimal ra &
- dddecimal cb & ddecimal b & " " & decimal rb ) ;
+ dddecimal ca & ddecimal (a shifted shadeoffset) & " " & decimal ra &
+ dddecimal cb & ddecimal (b shifted shadeoffset) & " " & decimal rb ) ;
_special_counter_
enddef ;