PageRenderTime 52ms CodeModel.GetById 30ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/groff/src/preproc/eqn/mark.cpp

https://bitbucket.org/freebsd/freebsd-head/
C++ | 121 lines | 84 code | 16 blank | 21 comment | 6 complexity | 7b01d151e67306bc7e92fc0d92b6ed71 MD5 | raw file
  1// -*- C++ -*-
  2/* Copyright (C) 1989, 1990, 1991, 1992 Free Software Foundation, Inc.
  3     Written by James Clark (jjc@jclark.com)
  4
  5This file is part of groff.
  6
  7groff is free software; you can redistribute it and/or modify it under
  8the terms of the GNU General Public License as published by the Free
  9Software Foundation; either version 2, or (at your option) any later
 10version.
 11
 12groff is distributed in the hope that it will be useful, but WITHOUT ANY
 13WARRANTY; without even the implied warranty of MERCHANTABILITY or
 14FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 15for more details.
 16
 17You should have received a copy of the GNU General Public License along
 18with groff; see the file COPYING.  If not, write to the Free Software
 19Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA. */
 20
 21#include "eqn.h"
 22#include "pbox.h"
 23
 24class mark_box : public pointer_box {
 25public:
 26  mark_box(box *);
 27  int compute_metrics(int);
 28  void output();
 29  void debug_print();
 30};
 31
 32// we push down marks so that they don't interfere with spacing
 33
 34box *make_mark_box(box *p)
 35{
 36  list_box *b = p->to_list_box();
 37  if (b != 0) {
 38    b->list.p[0] = make_mark_box(b->list.p[0]);
 39    return b;
 40  }
 41  else
 42    return new mark_box(p);
 43}
 44
 45mark_box::mark_box(box *pp) : pointer_box(pp)
 46{
 47}
 48
 49void mark_box::output()
 50{
 51  p->output();
 52}
 53
 54int mark_box::compute_metrics(int style)
 55{
 56  int res = p->compute_metrics(style);
 57  if (res)
 58    error("multiple marks and lineups");
 59  printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
 60  printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
 61  printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
 62  printf(".nr " MARK_REG " 0\n");
 63  return FOUND_MARK;
 64}
 65
 66void mark_box::debug_print()
 67{
 68  fprintf(stderr, "mark { ");
 69  p->debug_print();
 70  fprintf(stderr, " }");
 71}
 72
 73
 74class lineup_box : public pointer_box {
 75public:
 76  lineup_box(box *);
 77  void output();
 78  int compute_metrics(int style);
 79  void debug_print();
 80};
 81
 82// we push down lineups so that they don't interfere with spacing
 83
 84box *make_lineup_box(box *p)
 85{
 86  list_box *b = p->to_list_box();
 87  if (b != 0) {
 88    b->list.p[0] = make_lineup_box(b->list.p[0]);
 89    return b;
 90  }
 91  else
 92    return new lineup_box(p);
 93}
 94
 95lineup_box::lineup_box(box *pp) : pointer_box(pp)
 96{
 97}
 98
 99void lineup_box::output()
100{
101  p->output();
102}
103
104int lineup_box::compute_metrics(int style)
105{
106  int res = p->compute_metrics(style);
107  if (res)
108    error("multiple marks and lineups");
109  printf(".nr " WIDTH_FORMAT " 0\\n[" WIDTH_FORMAT "]\n", uid, p->uid);
110  printf(".nr " HEIGHT_FORMAT " \\n[" HEIGHT_FORMAT "]\n", uid, p->uid);
111  printf(".nr " DEPTH_FORMAT " \\n[" DEPTH_FORMAT "]\n", uid, p->uid);
112  printf(".nr " MARK_REG " 0\n");
113  return FOUND_LINEUP;
114}
115
116void lineup_box::debug_print()
117{
118  fprintf(stderr, "lineup { ");
119  p->debug_print();
120  fprintf(stderr, " }");
121}