Back to index

Classes | Defines | Functions
line_breaker.cpp File Reference
#include "Boxes/construct.hpp"
#include "Format/line_item.hpp"
#include "hashmap.hpp"

Go to the source code of this file.


struct  lb_info_rep
struct  lb_info
struct  line_breaker_rep


#define PEN   DI


 CONCRETE_CODE (lb_info)
tm_ostreamoperator<< (tm_ostream &out, lb_info hi)
static int get_position (font fn, string s, SI x)
void hyphenate (line_item item, int pos, line_item &item1, line_item &item2)
PEN square (PEN i)
array< pathline_breaks (array< line_item > a, int start, int end, SI line_width, SI first_spc, SI last_spc, bool ragged)

Define Documentation

#define PEN   DI

Definition at line 14 of file line_breaker.cpp.

Function Documentation

static int get_position ( font  fn,
string  s,
SI  x 
) [static]

Definition at line 89 of file line_breaker.cpp.

  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];
  return i;

Here is the call graph for this function:

void hyphenate ( line_item  item,
int  pos,
line_item item1,
line_item item2 

Definition at line 112 of file line_breaker.cpp.

  path ip= item->b->ip;
  int  x1= is_accessible (ip)? item->b->get_leaf_left_pos (): 0;
  int  x2= is_accessible (ip)? x1+ pos+ 1: 0;

  box b= item->b;
  string s  = b->get_leaf_string ();
  font   fn = b->get_leaf_font ();
  color  col= b->get_leaf_color ();

  string s1, s2;
  array<int> hp= item->lan->get_hyphens (s);
  item->lan->hyphenate (s, pos, s1, s2);
  item1= line_item (STRING_ITEM, OP_SKIP,
                  shorter_box (ip, text_box (ip, x1, s1, fn, col), pos+ 1),
                  hp[pos], item->lan);
  item2= line_item (STRING_ITEM, item->op_type,
                    text_box (ip, x2, s2, fn, col),
                  item->penalty, item->lan);
  item2->spc= item->spc;
  // cout << s << " ---> " << s1 << " " << s2 << "\n";

Here is the call graph for this function:

Here is the caller graph for this function:

array<path> line_breaks ( array< line_item a,
int  start,
int  end,
SI  line_width,
SI  first_spc,
SI  last_spc,
bool  ragged 

Definition at line 451 of file line_breaker.cpp.

  int tol= 5;         // extra tolerance of 5tmpt avoid rounding errors when
  line_width += tol;  // the widths of the boxes sum up to precisely 1par
  line_breaker_rep* H=
    tm_new<line_breaker_rep> (a, start, end, line_width, first_spc, last_spc);
  array<path> ap= ragged? H->compute_ragged_breaks (): H->compute_breaks ();
  tm_delete (H);
  return ap;

Here is the call graph for this function:

Here is the caller graph for this function:

tm_ostream& operator<< ( tm_ostream out,
lb_info  hi 

Definition at line 39 of file line_breaker.cpp.

  return out << "[ " << hi->prev << ", "
            << hi->pen << ", " << hi->pen_spc << " ]";
PEN square ( PEN  i) [inline]

Definition at line 273 of file line_breaker.cpp.

{ return i*i; }