⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dvirenderer_draw.cpp

📁 okular
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// -*- Mode: C++; c-basic-offset: 2; indent-tabs-mode: nil; c-brace-offset: 0; -*-/* * Copyright (c) 1994 Paul Vojta.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * NOTE: *        xdvi is based on prior work as noted in the modification history, below. *//* * DVI previewer for X. * * Eric Cooper, CMU, September 1985. * * Code derived from dvi-imagen.c. * * Modification history: * 1/1986        Modified for X.10        --Bob Scheifler, MIT LCS. * 7/1988        Modified for X.11        --Mark Eichin, MIT * 12/1988        Added 'R' option, toolkit, magnifying glass *                                        --Paul Vojta, UC Berkeley. * 2/1989        Added tpic support       --Jeffrey Lee, U of Toronto * 4/1989        Modified for System V    --Donald Richardson, Clarkson Univ. * 3/1990        Added VMS support        --Scott Allendorf, U of Iowa * 7/1990        Added reflection mode    --Michael Pak, Hebrew U of Jerusalem * 1/1992        Added greyscale code     --Till Brychcy, Techn. Univ. Muenchen *                                          and Lee Hetherington, MIT * 4/1994        Added DPS support, bounding box *                                        --Ricardo Telichevesky *                                          and Luis Miguel Silveira, MIT RLE. *///#define DEBUG_RENDER 0#include <config.h>#include "dviRenderer.h"#include "dvi.h"#include "dviFile.h"#include "hyperlink.h"#include "kvs_debug.h"#include "psgs.h"//#include "renderedDviPagePixmap.h"#include "TeXFont.h"#include "textBox.h"#include "xdvi.h"#include <klocale.h>#include <QPainter>extern QPainter *foreGroundPainter;/** Routine to print characters.  */void dviRenderer::set_char(unsigned int cmd, unsigned int ch){#ifdef DEBUG_RENDER  kDebug(kvs::dvi) << "set_char #" << ch << endl;#endif  glyph *g;  if (colorStack.isEmpty())    g = ((TeXFont *)(currinf.fontp->font))->getGlyph(ch, true, globalColor);  else    g = ((TeXFont *)(currinf.fontp->font))->getGlyph(ch, true, colorStack.top());  if (g == NULL)    return;  long dvi_h_sav = currinf.data.dvi_h;  QImage pix = g->shrunkenCharacter;  int x = ((int) ((currinf.data.dvi_h) / (shrinkfactor * 65536))) - g->x2;  int y = currinf.data.pxl_v - g->y2;  // Draw the character.  foreGroundPainter->drawImage(x, y, pix);  // Are we drawing text for a hyperlink? And are hyperlinks  // enabled?  if (HTML_href != NULL) {    // Now set up a rectangle which is checked against every mouse    // event.    if (line_boundary_encountered == true) {      // Set up hyperlink      Hyperlink dhl;      dhl.baseline = currinf.data.pxl_v;      dhl.box.setRect(x, y, pix.width(), pix.height());      dhl.linkText = *HTML_href;      currentlyDrawnPage->hyperLinkList.push_back(dhl);    } else {      QRect dshunion = currentlyDrawnPage->hyperLinkList[currentlyDrawnPage->hyperLinkList.size()-1].box.unite(QRect(x, y, pix.width(), pix.height())) ;      currentlyDrawnPage->hyperLinkList[currentlyDrawnPage->hyperLinkList.size()-1].box = dshunion;    }  }  // Are we drawing text for a source hyperlink? And are source  // hyperlinks enabled?  // If we are printing source hyperlinks are irrelevant, otherwise we  // actually got a pointer to a RenderedDviPagePixmap.  RenderedDviPagePixmap* currentDVIPage = dynamic_cast<RenderedDviPagePixmap*>(currentlyDrawnPage);  if (source_href != 0 && currentDVIPage) {    // Now set up a rectangle which is checked against every mouse    // event.    if (line_boundary_encountered == true) {      // Set up source hyperlinks      Hyperlink dhl;      dhl.baseline = currinf.data.pxl_v;      dhl.box.setRect(x, y, pix.width(), pix.height());      if (source_href != NULL)        dhl.linkText = *source_href;      else        dhl.linkText = "";      currentDVIPage->sourceHyperLinkList.push_back(dhl);    } else {      QRect dshunion = currentDVIPage->sourceHyperLinkList[currentDVIPage->sourceHyperLinkList.size()-1].box.unite(QRect(x, y, pix.width(), pix.height())) ;      currentDVIPage->sourceHyperLinkList[currentDVIPage->sourceHyperLinkList.size()-1].box = dshunion;    }  }  // Code for DVI -> text functions (e.g. marking of text, full text  // search, etc.). Set up the currentlyDrawnPage->textBoxList.  TextBox link;  link.box.setRect(x, y, pix.width(), pix.height());  link.text = "";  currentlyDrawnPage->textBoxList.push_back(link);  switch(ch) {  case 0x0b:    currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += "ff";    break;  case 0x0c:    currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += "fi";    break;  case 0x0d:    currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += "fl";    break;  case 0x0e:    currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += "ffi";    break;  case 0x0f:    currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += "ffl";    break;  case 0x7b:    currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += "-";    break;  case 0x7c:    currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += "---";    break;  case 0x7d:    currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += "\"";    break;  case 0x7e:    currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += "~";    break;  case 0x7f:    currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += "@@"; // @@@ check!    break;  default:    if ((ch >= 0x21) && (ch <= 0x7a))      currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += QChar(ch);    else      currentlyDrawnPage->textBoxList[currentlyDrawnPage->textBoxList.size()-1].text += "?";    break;  }  if (cmd == PUT1)    currinf.data.dvi_h = dvi_h_sav;  else    currinf.data.dvi_h += (int)(currinf.fontp->scaled_size_in_DVI_units * dviFile->getCmPerDVIunit() *                                (1200.0 / 2.54)/16.0 * g->dvi_advance_in_units_of_design_size_by_2e20 + 0.5);  word_boundary_encountered = false;  line_boundary_encountered = false;}void dviRenderer::set_empty_char(unsigned int, unsigned int){  return;}void dviRenderer::set_vf_char(unsigned int cmd, unsigned int ch){#ifdef DEBUG_RENDER  kDebug(kvs::dvi) << "dviRenderer::set_vf_char( cmd=" << cmd << ", ch=" << ch << " )" << endl;#endif  static unsigned char   c;  macro *m = &currinf.fontp->macrotable[ch];  if (m->pos == NULL) {    kError(kvs::dvi) << "Character " << ch << " not defined in font " << currinf.fontp->fontname << endl;    m->pos = m->end = &c;    return;  }  long dvi_h_sav = currinf.data.dvi_h;  struct drawinf oldinfo = currinf;  currinf.data.w         = 0;  currinf.data.x         = 0;  currinf.data.y         = 0;  currinf.data.z         = 0;  currinf.fonttable         = &(currinf.fontp->vf_table);  currinf._virtual          = currinf.fontp;  quint8 *command_ptr_sav  = command_pointer;  quint8 *end_ptr_sav      = end_pointer;  command_pointer           = m->pos;  end_pointer               = m->end;  draw_part(currinf.fontp->scaled_size_in_DVI_units*(dviFile->getCmPerDVIunit() * 1200.0 / 2.54)/16.0, true);  command_pointer           = command_ptr_sav;  end_pointer               = end_ptr_sav;  currinf = oldinfo;  if (cmd == PUT1)    currinf.data.dvi_h = dvi_h_sav;  else    currinf.data.dvi_h += (int)(currinf.fontp->scaled_size_in_DVI_units * dviFile->getCmPerDVIunit() *                                (1200.0 / 2.54)/16.0 * m->dvi_advance_in_units_of_design_size_by_2e20 + 0.5);}void dviRenderer::set_no_char(unsigned int cmd, unsigned int ch){#ifdef DEBUG_RENDER  kDebug(kvs::dvi) << "dviRenderer::set_no_char( cmd=" << cmd << ", ch =" << ch << " )"  << endl;#endif  if (currinf._virtual) {    currinf.fontp = currinf._virtual->first_font;    if (currinf.fontp != NULL) {      currinf.set_char_p = currinf.fontp->set_char_p;      (this->*currinf.set_char_p)(cmd, ch);      return;    }  }  errorMsg = i18n("The DVI code set a character of an unknown font.");  return;}void dviRenderer::draw_part(double current_dimconv, bool is_vfmacro){#ifdef DEBUG_RENDER  kDebug(kvs::dvi) << "draw_part" << endl;#endif  qint32 RRtmp=0, WWtmp=0, XXtmp=0, YYtmp=0, ZZtmp=0;  quint8 ch;  currinf.fontp        = NULL;  currinf.set_char_p   = &dviRenderer::set_no_char;  for (;;) {    ch = readUINT8();    if (ch <= (unsigned char) (SETCHAR0 + 127)) {      (this->*currinf.set_char_p)(ch, ch);    } else      if (FNTNUM0 <= ch && ch <= (unsigned char) (FNTNUM0 + 63)) {        currinf.fontp = currinf.fonttable->find(ch - FNTNUM0);        if (currinf.fontp == NULL) {          errorMsg = i18n("The DVI code referred to font #%1, which was not previously defined.", ch - FNTNUM0);          return;        }        currinf.set_char_p = currinf.fontp->set_char_p;      } else {        qint32 a, b;        switch (ch) {        case SET1:        case PUT1:          (this->*currinf.set_char_p)(ch, readUINT8());          break;        case SETRULE:          if (is_vfmacro == false) {            word_boundary_encountered = true;            line_boundary_encountered = true;          }          /* Be careful, dvicopy outputs rules with height =             0x80000000. We don't want any SIGFPE here. */          a = readUINT32();          b = readUINT32();          b = ((long) (b *  current_dimconv));          if (a > 0 && b > 0) {            int h = ((int) ROUNDUP(((long) (a *  current_dimconv)), shrinkfactor * 65536));            int w =  ((int) ROUNDUP(b, shrinkfactor * 65536));            if (colorStack.isEmpty())              foreGroundPainter->fillRect( ((int) ((currinf.data.dvi_h) / (shrinkfactor * 65536))),                                         currinf.data.pxl_v - h + 1, w?w:1, h?h:1, globalColor );            else              foreGroundPainter->fillRect( ((int) ((currinf.data.dvi_h) / (shrinkfactor * 65536))),                                        currinf.data.pxl_v - h + 1, w?w:1, h?h:1, colorStack.top() );          }          currinf.data.dvi_h += b;          break;        case PUTRULE:          if (is_vfmacro == false) {            word_boundary_encountered = true;            line_boundary_encountered = true;          }          a = readUINT32();          b = readUINT32();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -