Пример #1
0
/*
void MathPrintout::RecalculateSize()
{
  wxConfig *config = (wxConfig *)wxConfig::Get();
  int fontsize = 12;
  config->Read(wxT("fontSize"), &fontsize);
  GroupCell* tmp = m_tree;
  double scale = GetPPIScale();

  wxDC *dc = GetDC();
  CellParser parser(*dc, scale);
  int marginX, marginY;
  GetPageMargins(&marginX, &marginY);
  marginX += SCALE_PX(MC_BASE_INDENT, scale);
  parser.SetIndent(marginX);

  while (tmp != NULL)
  {
    tmp->RecalculateSize(parser, fontsize, false);
    tmp = tmp->m_next;
  }
}
*/
void MathPrintout::Recalculate()
{
  wxConfig *config = (wxConfig *)wxConfig::Get();
  int fontsize = 12;
  config->Read(wxT("fontSize"), &fontsize);
  int mfontsize = fontsize;
  config->Read(wxT("mathfontsize"), &mfontsize);
  GroupCell* tmp = (GroupCell *)m_tree;
  double scale = GetPPIScale();

  wxDC *dc = GetDC();
  CellParser parser(*dc, scale);

  int marginX, marginY;
  GetPageMargins(&marginX, &marginY);
  int pageWidth, pageHeight;
  GetPageSizePixels(&pageWidth, &pageHeight);

  parser.SetClientWidth(pageWidth - marginX - marginY
                        - SCALE_PX(MC_BASE_INDENT, scale));

  marginX += SCALE_PX(MC_BASE_INDENT, scale);
  parser.SetIndent(marginX);

  while (tmp != NULL)
  {
    tmp->Recalculate(parser, fontsize, mfontsize);
    tmp = (GroupCell *)tmp->m_next;
  }
}
Пример #2
0
void MathPrintout::GetPageMargins(int* horizontal, int* vertical)
{
  double scale = GetPPIScale();

  *horizontal = (int)(SCALE_PX(PRINT_MARGIN_HORIZONTAL, scale) * 10);
  *vertical = (int)(SCALE_PX(PRINT_MARGIN_VERTICAL, scale) * 10);
}
Пример #3
0
int MathPrintout::GetHeaderHeight()
{
  wxDC *dc = GetDC();
  double ppiScale = GetPPIScale();
  int width, height;

  dc->SetFont(wxFont(SCALE_PX(10, ppiScale), wxMODERN, wxNORMAL, wxNORMAL));
  dc->GetTextExtent(GetTitle(), &width, &height);
  return height + SCALE_PX(12, ppiScale);
}
Пример #4
0
void MathPrintout::BreakPages()
{
  if (m_tree == NULL)
    return ;

  int pageWidth, pageHeight;
  int marginX, marginY;
  int headerHeight = GetHeaderHeight();
  double scale = GetPPIScale();

  GetPageMargins(&marginX, &marginY);
  GetPageSizePixels(&pageWidth, &pageHeight);

  int currentHeight = marginY;
  int skip = SCALE_PX(MC_GROUP_SKIP, scale);;

  GroupCell* tmp = (GroupCell *)m_tree;
  m_pages.push_back(tmp);

  m_numberOfPages = 1;
  while (tmp != NULL)
  {
    tmp->BreakPage(false);

    if (currentHeight + tmp->GetMaxHeight() + skip >= pageHeight - marginY ||
        tmp->GetGroupType() == GC_TYPE_PAGEBREAK)
    {
      if (tmp->GetGroupType() != GC_TYPE_PAGEBREAK)
        currentHeight = marginY + tmp->GetMaxHeight() + headerHeight;
      tmp->BreakPage(true);
      m_pages.push_back(tmp);
      m_numberOfPages++;
    }
    else
      currentHeight += tmp->GetMaxHeight() + skip;

    tmp = (GroupCell *)tmp->m_next;
  }
}
Пример #5
0
bool MathPrintout::OnPrintPage(int num)
{
  double screenScaleX, screenScaleY;
  double ppiScale;
  GroupCell* tmp;
  wxDC* dc = GetDC();

  int marginX, marginY;
  GetPageMargins(&marginX, &marginY);


  ppiScale = GetPPIScale();
  GetScreenScale(&screenScaleX, &screenScaleY);

  marginX += SCALE_PX(MC_BASE_INDENT, ppiScale);

  dc->SetUserScale(screenScaleX, screenScaleY);

  // Go to current page
  tmp = (GroupCell *)m_pages[num - 1];

  // Print page
  if (tmp != NULL)
  {
    if (tmp->GetGroupType() == GC_TYPE_PAGEBREAK)
      tmp = (GroupCell *)tmp->m_next;
    if (tmp == NULL)
      return true;

    wxPoint point;
    point.x = marginX;
    point.y = marginY + tmp->GetMaxCenter() + GetHeaderHeight();
    wxConfigBase* config = wxConfig::Get();
    int fontsize = 12;
    int drop = tmp->GetMaxDrop();

    config->Read(wxT("fontsize"), &fontsize);

    PrintHeader(num, dc, ppiScale);
    CellParser parser(*dc, ppiScale);

    parser.SetIndent(marginX);

    while (tmp != NULL && tmp->GetGroupType() != GC_TYPE_PAGEBREAK)
    {
      tmp->Draw(parser, point, fontsize, false);
      if (tmp->m_next != NULL) {
        point.x = marginX;
        point.y += drop + tmp->m_next->GetMaxCenter();
        point.y += SCALE_PX(MC_GROUP_SKIP, ppiScale);
        drop = tmp->m_next->GetMaxDrop();
      }

      tmp = (GroupCell *)tmp->m_next;
      if (tmp == NULL || tmp->BreakPageHere())
        break;
    }
    return true;
  }
  return false;
}
Пример #6
0
bool MathPrintout::OnPrintPage(int num)
{
  double screenScaleX, screenScaleY;
  double ppiScale;
  GroupCell* tmp;
  wxDC* dc = GetDC();

  int marginX, marginY;
  GetPageMargins(&marginX, &marginY);

  ppiScale = GetPPIScale();
  GetScreenScale(&screenScaleX, &screenScaleY);

  marginX += SCALE_PX(MC_BASE_INDENT, ppiScale);

  dc->SetUserScale(screenScaleX, screenScaleY);

  // Go to current page
  tmp = (GroupCell *)m_pages[num - 1];

  // Print page
  if (tmp != NULL)
  {
    if (tmp->GetGroupType() == GC_TYPE_PAGEBREAK)
      tmp = (GroupCell *)tmp->m_next;
    if (tmp == NULL)
      return true;

    wxPoint point;
    point.x = marginX;
    point.y = marginY + tmp->GetMaxCenter() + GetHeaderHeight();
    wxConfigBase* config = wxConfig::Get();
    int fontsize = 12;
    int drop = tmp->GetMaxDrop();

    config->Read(wxT("fontsize"), &fontsize);

    PrintHeader(num, dc, ppiScale);
    CellParser parser(*dc, ppiScale);

    parser.SetIndent(marginX);
    // Inform the output routines that we are printing
    parser.SetPrinter(true);
    // Make sure that during print nothing is outside the crop rectangle
    MathCell::ClipToDrawRegion(true);
    
    while (tmp != NULL && tmp->GetGroupType() != GC_TYPE_PAGEBREAK)
    {
      // The following line seems to misteriously fix the "subsequent text
      // cells aren't printed" problem on linux.
      // No Idea why, though.
      dc->SetPen(wxPen(wxT("light grey"), 1, wxPENSTYLE_SOLID));
      tmp->Draw(point, fontsize);
      if (tmp->m_next != NULL) {
        point.x = marginX;
        point.y += drop + tmp->m_next->GetMaxCenter();
        point.y += SCALE_PX(MC_GROUP_SKIP, ppiScale);
        drop = tmp->m_next->GetMaxDrop();
      }

      tmp = (GroupCell *)tmp->m_next;
      if (tmp == NULL || tmp->BreakPageHere())
        break;
    }
    MathCell::ClipToDrawRegion(false);
    return true;
  }
  MathCell::ClipToDrawRegion(false);
  return false;
}