static string get_wide (string s, font fn, SI width) { ASSERT (N(s) >= 2 && s[0] == '<' && s[N(s)-1] == '>', "invalid rubber character"); string radical= s (0, N(s)-1) * "-"; string first = radical * "0>"; metric ex; fn->get_extents (first, ex); if ((ex->x2- ex->x1) >= width) return first; string second = radical * "1>"; metric ey; fn->get_extents (second, ey); SI w1= ex->x2- ex->x1; SI w2= ey->x2- ey->x1; if ((w2 <= w1) || (w2 > width)) return first; SI d= w2- w1; int n= (width-w1) / (d+1); int credit= 20; while (true) { string test= radical * as_string (n+1) * ">"; fn->get_extents (test, ey); if (ey->x2- ey->x1 > width || credit <= 0) return radical * as_string (n) * ">"; n++; credit--; } }
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_stretched_font_rep::get_extents (string s, metric& ex) { base->get_extents (s, ex); ex->y1= (SI) floor (factor * ex->y1 + 0.5); ex->y2= (SI) floor (factor * ex->y2 + 0.5); ex->y3= (SI) floor (factor * ex->y3); ex->y4= (SI) ceil (factor * ex->y4); }
SI text_box_rep::get_leaf_offset (string search) { int pos= search_forwards (search, 0, str); if (pos == -1) return w(); metric ex; fn->get_extents (str (0, pos), ex); return ex->x2- ex->x1; }
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); }
static string get_wide_stix (string s, font fn, SI width) { ASSERT (N(s) >= 2 && s[0] == '<' && s[N(s)-1] == '>', "invalid rubber character"); string radical= s (0, N(s)-1) * "-"; metric ex; int n= 0; while (true) { string test= radical * as_string (n) * ">"; fn->get_extents (test, ex); if (ex->x2- ex->x1 > width || n >= 6) return radical * as_string (n) * ">"; n++; } }
void poor_distorted_font_rep::get_extents (string s, metric& ex) { base->get_extents (s, ex); }
static string get_delimiter (string s, font fn, SI height) { int ns= N(s); ASSERT (ns >= 2 && s[0] == '<' && s[ns-1] == '>', "invalid rubber character"); if (s[ns-2] >= '0' && s[ns-2] <= '9') { int pos; int plus= get_number (s, pos); if (pos > 0) { string s2= s (0, pos) * ">"; string r2= get_delimiter (s2, fn, height); int pos2; int nr2= get_number (r2, pos2); if (pos2 > 0) { int nr= max (nr2 + plus, 0); return r2 (0, pos2) * "-" * as_string (nr) * ">"; } } } height -= PIXEL; string radical= s (0, N(s)-1) * "-"; string best= radical * "0>"; SI best_h= 0; int n= 0; SI last= 0; int credit= 20; while (credit > 0) { metric ex; string test= radical * as_string (n) * ">"; fn->get_extents (test, ex); SI h= ex->y2 - ex->y1; if (h >= (height - (n==1? PIXEL: 0))) return test; if (h > best_h) { best_h= h; best= test; } int d= h - last; if (last > 0 && d > 0) { int plus= (height - h - 1) / d; if (plus <= 1 || n <= 4) { n++; last= h; } else { int n2= n + plus; metric ex2; string test2= radical * as_string (n2) * ">"; fn->get_extents (test2, ex2); SI h2= ex2->y2 - ex2->y1; if (h2 >= height || h2 < h) { n++; last= h; } else { n= n2; last= 0; } } } else if (last <= 0 || n < 10) { n++; last= h; } else return best; credit--; } return best; }