path text_box_rep::find_box_path (SI x, SI y, SI delta, bool force, bool& found) { (void) y; (void) force; found= true; STACK_NEW_ARRAY (xpos, SI, N(str)+1); if (is_nil (xk)) fn->get_xpositions (str, xpos); else { fn->get_xpositions (str, xpos, xk->padding); x += (xk->padding - xk->left); } int prev_i, prev_x=0, i=0; while (i<N(str)) { prev_i= i; if (str[i]=='<') while ((i<N(str)) && (str[i]!='>')) i++; i++; int m= (prev_x + xpos[i]) >> 1; if ((x<m) || ((x==m) && (delta<0))) { STACK_DELETE_ARRAY (xpos); return path (prev_i); } prev_x= xpos[i]; } STACK_DELETE_ARRAY (xpos); return path (i); }
void smart_font_rep::get_xpositions (string s, SI* xpos, SI xk) { SI x= 0; int i=0, n= N(s); xpos[0]= x; while (i < n) { int nr; string r= s; int start= i; advance (s, i, r, nr); if (nr >= 0) { if (r == s (start, i)) { fn[nr]->get_xpositions (r, xpos+start, xk); for (int j=0; j<=N(r); j++) xpos[start+j] += x; } else { STACK_NEW_ARRAY (tmp, SI, N(r)+1); fn[nr]->get_xpositions (r, tmp, xk); for (int j=start; j<i; j++) xpos[j]= x; xpos[i]= x + tmp[N(r)]; STACK_DELETE_ARRAY (tmp); } x= xpos[i]; } else for (int j=start; j<=i; j++) xpos[j]= x; } }
void poor_distorted_font_rep::draw_fixed (renderer ren, string s, SI x, SI y) { STACK_NEW_ARRAY (xpos, SI, N(s)+1); get_xpositions (s, xpos); draw_fixed (ren, s, x, y, xpos); STACK_DELETE_ARRAY (xpos); }
selection text_box_rep::find_selection (path lbp, path rbp) { SI x1, y1, x2, y2; metric ex; fn->get_extents (str (0, lbp->item), ex); x1= ex->x2; fn->get_extents (str (0, rbp->item), ex); x2= ex->x2; if (!is_nil (xk) && N(str) != 0) { STACK_NEW_ARRAY (xpos, SI, N(str)+1); fn->get_xpositions (str, xpos, xk->padding); SI d= xk->padding - xk->left; x1= xpos[lbp->item] - d; x2= xpos[rbp->item] - d; if (lbp->item == 0) x1 += d; if (rbp->item == 0) x2 += d; if (lbp->item == N(str)) x1 += xk->right; if (rbp->item == N(str)) x2 += xk->right; STACK_DELETE_ARRAY (xpos); } fn->get_extents (str (lbp->item, rbp->item), ex); y1= ex->y1; y2= ex->y2; return selection (rectangle (x1, y1, x2, y2), find_tree_path (lbp), find_tree_path (rbp)); }
cursor text_box_rep::find_cursor (path bp) { metric ex; cursor cu (0, 0); int l= min (bp->item, N(str)); fn->get_extents (str (0, l), ex); cu->ox= ex->x2; if (!is_nil (xk) && N(str) != 0) { STACK_NEW_ARRAY (xpos, SI, N(str)+1); fn->get_xpositions (str, xpos, xk->padding); SI d= xk->padding - xk->left; cu->ox= xpos[l] - d; if (l == 0) cu->ox += d; if (l == N(str)) cu->ox += xk->right; STACK_DELETE_ARRAY (xpos); } if (l != 0) { int k= l; tm_char_backwards (str, k); fn->get_extents (str (k, l), ex); } cu->y1= min (ex->y1, 0); cu->y2= max (ex->y2, fn->yx); cu->slope= fn->get_right_slope (str); return cu; }
void poor_bbb_font_rep::get_extents (string s, metric& ex) { base->get_extents (s, ex); if (N(s) == 0) return; STACK_NEW_ARRAY (xpos, SI, N(s)+1); get_xpositions (s, xpos); ex->x4 += xpos[N(s)] - ex->x2; ex->x2= xpos[N(s)]; STACK_DELETE_ARRAY (xpos); }
box typeset_as_atomic (edit_env env, tree t, path ip) { if (is_func (t, WITH)) { int i, n= N(t), k= (n-1)>>1; // is k=0 allowed ? if ((n&1) != 1) return empty_box (ip); STACK_NEW_ARRAY(vars,string,k); STACK_NEW_ARRAY(oldv,tree,k); STACK_NEW_ARRAY(newv,tree,k); for (i=0; i<k; i++) { tree var_t= env->exec (t[i<<1]); if (is_atomic (var_t)) { string var= var_t->label; vars[i]= var; oldv[i]= env->read (var); newv[i]= env->exec (t[(i<<1)+1]); } else { STACK_DELETE_ARRAY(vars); STACK_DELETE_ARRAY(oldv); STACK_DELETE_ARRAY(newv); return empty_box (ip); } } // for (i=0; i<k; i++) env->monitored_write_update (vars[i], newv[i]); for (i=0; i<k; i++) env->write_update (vars[i], newv[i]); box b= typeset_as_atomic (env, t[n-1], descend (ip, n-1)); for (i=k-1; i>=0; i--) env->write_update (vars[i], oldv[i]); STACK_DELETE_ARRAY(vars); STACK_DELETE_ARRAY(oldv); STACK_DELETE_ARRAY(newv); return b; } else if (is_func (t, LOCUS) && N(t) != 0) {
static int get_position (font fn, string s, SI x) { int prev_i, prev_x=0, i=0, n=N(s); STACK_NEW_ARRAY (xpos, SI, n+1); fn->get_xpositions (s, xpos); while (i<n) { prev_i= i; if (s[i]=='<') { while ((i<n) && (s[i]!='>')) i++; if (i<n) i++; } else i++; int m= (prev_x + xpos[i]) >> 1; if (x<m) { STACK_DELETE_ARRAY (xpos); return prev_i; } prev_x= xpos[i]; } STACK_DELETE_ARRAY (xpos); return i; }
void poor_stretched_font_rep::draw_fixed (renderer ren, string s, SI x, SI y, SI xk) { if (ren->is_screen) { STACK_NEW_ARRAY (xpos, SI, N(s)+1); get_xpositions (s, xpos, xk); draw_fixed (ren, s, x, y, xpos); STACK_DELETE_ARRAY (xpos); } else { ren->set_transformation (scaling (point (1.0, factor), point (0.0, 0.0))); base->draw_fixed (ren, s, x, y, xk); ren->reset_transformation (); } }
void x_drawable_rep::lines (array<SI> x, array<SI> y) { int i, n= N(x); if ((N(y) != n) || (n<1)) return; STACK_NEW_ARRAY (pnt, XPoint, n); for (i=0; i<n; i++) { SI xx= x[i], yy= y[i]; decode (xx, yy); pnt[i].x= xx; pnt[i].y= yy; } XDrawLines (dpy, win, gc, pnt, n, CoordModeOrigin); STACK_DELETE_ARRAY (pnt); }
text_box_rep::text_box_rep (path ip, int pos2, string s, font fn2, pencil p2, xkerning xk2): box_rep (ip), pos (pos2), str (s), fn (fn2), pen (p2), xk (xk2) { metric ex; fn->get_extents (str, ex); x1= ex->x1; y1= ex->y1; x2= ex->x2; y2= ex->y2; x3= ex->x3; y3= ex->y3; x4= ex->x4; y4= ex->y4; if (!is_nil (xk)) { STACK_NEW_ARRAY (xpos, SI, N(str)+1); fn->get_xpositions (str, xpos, xk->padding); x1= 0; x2= xpos[N(str)] + xk->right + xk->left; x3= x3 + xk->left + xk->padding; x4= x4 + (xpos[N(str)] - ex->x2) + xk->left - xk->padding; STACK_DELETE_ARRAY (xpos); } }