MathCell* MathParser::ParseSupTag(wxXmlNode* node) { ExptCell *expt = new ExptCell; #if wxCHECK_VERSION(2,9,0) if (node->GetAttributes() != NULL) #else if (node->GetProperties() != NULL) #endif expt->IsMatrix(true); wxXmlNode* child = node->GetChildren(); if (child) { expt->SetBase(ParseTag(child, false)); child = child->GetNext(); if (child) { MathCell* power = ParseTag(child, false); power->SetExponentFlag(); expt->SetPower(power); expt->SetType(m_ParserStyle); expt->SetStyle(TS_VARIABLE); return expt; } } delete expt; return NULL; }
wxString IntCell::ToString(bool all) { wxString s = wxT("integrate("); s += m_base->ToString(true); MathCell* tmp = m_var; wxString var; tmp = tmp->m_next; if (tmp != NULL) { var = tmp->ToString(true); } wxString to = m_over->ToString(true); wxString from = m_under->ToString(true); s += wxT(",") + var; if (m_intStyle == INT_DEF) s += wxT(",") + from + wxT(",") + to; s += wxT(")"); s += MathCell::ToString(all); return s; }
void Bitmap::GetMaxPoint(int* width, int* height) { MathCell* tmp = m_tree; int currentHeight = 0; int currentWidth = 0; *width = 0; *height = 0; bool bigSkip = false; bool firstCell = true; while (tmp != NULL) { if (!tmp->m_isBroken) { if (tmp->BreakLineHere() || firstCell) { firstCell = false; currentHeight += tmp->GetMaxHeight(); if (bigSkip) currentHeight += MC_LINE_SKIP; *height = currentHeight; currentWidth = tmp->GetWidth(); *width = MAX(currentWidth, *width); } else { currentWidth += (tmp->GetWidth() + MC_CELL_SKIP); *width = MAX(currentWidth - MC_CELL_SKIP, *width); } bigSkip = tmp->m_bigSkip; } tmp = tmp->m_nextToDraw; } }
MathCell* MathParser::ParseSubSupTag(wxXmlNode* node) { SubSupCell *subsup = new SubSupCell; wxXmlNode* child = node->GetChildren(); if (child) { subsup->SetBase(ParseTag(child, false)); child = child->GetNext(); if (child) { MathCell* index = ParseTag(child, false); index->SetExponentFlag(); subsup->SetIndex(index); child = child->GetNext(); if (child) { MathCell* power = ParseTag(child, false); power->SetExponentFlag(); subsup->SetExponent(power); subsup->SetType(m_ParserStyle); subsup->SetStyle(TS_VARIABLE); return subsup; } } } delete subsup; return NULL; }
void GroupCell::AppendOutput(MathCell *cell) { if (m_output == NULL) { m_output = cell; if (m_groupType == GC_TYPE_CODE && m_input->m_next != NULL) ((EditorCell *)(m_input->m_next))->ContainsChanges(false); m_lastInOutput = m_output; while (m_lastInOutput->m_next != NULL) m_lastInOutput = m_lastInOutput->m_next; } else { MathCell *tmp = m_lastInOutput; if (tmp == NULL) tmp = m_output; while (tmp->m_next != NULL) tmp = tmp->m_next; tmp->AppendCell(cell); while (m_lastInOutput->m_next != NULL) m_lastInOutput = m_lastInOutput->m_next; } if (m_appendedCells == NULL) m_appendedCells = cell; }
wxString DiffCell::ToString() { MathCell* tmp = m_baseCell->m_next; wxString s = wxT("'diff("); if (tmp != NULL) s += tmp->ListToString(); s += m_diffCell->ListToString(); s += wxT(")"); return s; }
void MathCell::ClearCacheList() { MathCell *tmp = this; while(tmp != NULL) { tmp->ClearCache(); tmp = tmp->m_next; } }
void GroupCell::UnBreakUpCells() { MathCell *tmp = m_output; while (tmp != NULL) { if (tmp->m_isBroken) { tmp->Unbreak(); } tmp = tmp->m_next; } }
void GroupCell::SetParent(MathCell *parent, bool all) { if (m_input != NULL) m_input->SetParent(parent, true); MathCell *tmp = m_output; while (tmp != NULL) { tmp->SetParent(parent, false); tmp = tmp->m_next; } }
wxString DiffCell::ToString() { if (m_isBroken) return wxEmptyString; MathCell* tmp = m_baseCell->m_next; wxString s = wxT("'diff("); if (tmp != NULL) s += tmp->ListToString(); s += m_diffCell->ListToString(); s += wxT(")"); return s; }
/*! Set the parent of this group cell \todo: Is the while loop a simple m_output->SetParentList(parent)? */ void GroupCell::SetParent(MathCell *parent) { //m_group = parent; if (m_input != NULL) m_input->SetParentList(parent); MathCell *tmp = m_output; while (tmp != NULL) { tmp->SetParent(parent); tmp = tmp->m_next; } }
void Bitmap::BreakLines() { int fullWidth = BM_FULL_WIDTH; int currentWidth = 0; MathCell* tmp = m_tree; while (tmp != NULL) { if (!tmp->m_isBroken) { tmp->BreakLine(false); tmp->ResetData(); if (tmp->BreakLineHere() || (currentWidth + tmp->GetWidth() >= fullWidth)) { currentWidth = tmp->GetWidth(); tmp->BreakLine(true); } else currentWidth += (tmp->GetWidth() + MC_CELL_SKIP); } tmp = tmp->m_nextToDraw; } }
MathCell *MathCell::CopyList() { MathCell *dest = Copy(); MathCell *src = this->m_next; MathCell *ret = dest; while(src != NULL) { dest->AppendCell(src->Copy()); src = src->m_next; dest = dest->m_next; } return ret; }
wxString GroupCell::ToString() { wxString str; if (GetEditable()) { str = m_input->ListToString(); if (m_output != NULL && !m_hide) { MathCell *tmp = m_output; while (tmp != NULL) { if (tmp->ForceBreakLineHere() && str.Length()>0) str += wxT("\n"); str += tmp->ToString(); tmp = tmp->m_nextToDraw; } } } return str; }
wxString MathCell::ListToString() { wxString retval; MathCell *tmp = this; bool firstline = true; while(tmp!=NULL) { retval+=tmp->ToString(); if((!firstline)&&(tmp->m_forceBreakLine)) retval+=wxT("\n"); firstline = false; tmp=tmp->m_next; } return retval; }
void Bitmap::RecalculateSize() { int fontsize = 12; wxConfig::Get()->Read(wxT("fontSize"), &fontsize); int mfontsize = fontsize; wxConfig::Get()->Read(wxT("mathfontsize"), &mfontsize); MathCell* tmp = m_tree; wxMemoryDC dc; dc.SelectObject(m_bmp); CellParser parser(dc); while (tmp != NULL) { tmp->RecalculateSize(parser, tmp->IsMath() ? mfontsize : fontsize, false); tmp = tmp->m_next; } }
wxString FracCell::ToString(bool all) { wxString s; if (!m_isBroken) { if (m_fracStyle == FC_NORMAL) { if (m_num->IsCompound()) s += wxT("(") + m_num->ToString(true) + wxT(")/"); else s += m_num->ToString(true) + wxT("/"); if (m_denom->IsCompound()) s += wxT("(") + m_denom->ToString(true) + wxT(")"); else s += m_denom->ToString(true); } else if (m_fracStyle == FC_CHOOSE) { s = wxT("binomial(") + m_num->ToString(true) + wxT(",") + m_denom->ToString(true) + wxT(")"); } else { MathCell* tmp = m_denom; while (tmp != NULL) { tmp = tmp->m_next; // Skip the d if (tmp == NULL) break; tmp = tmp->m_next; // Skip the * if (tmp == NULL) break; s += tmp->GetDiffPart(); tmp = tmp->m_next; // Skip the * if (tmp == NULL) break; tmp = tmp->m_next; } } } if (m_fracStyle == FC_NORMAL) s += MathCell::ToString(all); return s; }
// We assume that appended cells will be in a new line! void GroupCell::RecalculateAppended(CellParser& parser) { if (m_appendedCells == NULL) return; MathCell *tmp = m_appendedCells; int fontsize = m_fontSize; double scale = parser.GetScale(); // Recalculate widths of cells while (tmp != NULL) { tmp->RecalculateWidths(parser, tmp->IsMath() ? m_mathFontSize : m_fontSize); tmp = tmp->m_next; } // Breakup cells and break lines BreakUpCells(m_appendedCells, parser, fontsize, parser.GetClientWidth()); BreakLines(m_appendedCells, parser.GetClientWidth()); // Recalculate size of cells tmp = m_appendedCells; while (tmp != NULL) { tmp->RecalculateSize(parser, tmp->IsMath() ? m_mathFontSize : m_fontSize); tmp = tmp->m_next; } // Update widths tmp = m_appendedCells; while (tmp != NULL) { if (tmp->BreakLineHere() || tmp == m_appendedCells) { m_width = MAX(m_width, tmp->GetLineWidth(scale)); m_outputRect.width = MAX(m_outputRect.width, tmp->GetLineWidth(scale)); m_height += tmp->GetMaxHeight(); if (tmp->m_bigSkip) m_height += MC_LINE_SKIP; m_outputRect.height += tmp->GetMaxHeight() + MC_LINE_SKIP; } tmp = tmp->m_nextToDraw; } m_appendedCells = NULL; }
void GroupCell::RecalculateWidths(CellParser& parser, int fontsize) { if (m_width == -1 || m_height == -1 || parser.ForceUpdate()) { // special case of 'line cell' if (m_groupType == GC_TYPE_PAGEBREAK) { m_width = 10; m_height = 2; ResetData(); return; } UnBreakUpCells(); double scale = parser.GetScale(); m_input->RecalculateWidthsList(parser, fontsize); // recalculate the position of input in ReEvaluateSelection! if (m_input->m_next != NULL) { m_input->m_next->m_currentPoint.x = m_currentPoint.x + m_input->GetWidth() + MC_CELL_SKIP; } if (m_output == NULL || m_hide) { m_width = m_input->GetFullWidth(scale); } else { MathCell *tmp = m_output; while (tmp != NULL) { tmp->RecalculateWidths(parser, tmp->IsMath() ? m_mathFontSize : m_fontSize); tmp = tmp->m_next; } // This is not correct, m_width will be computed correctly in RecalculateSize! m_width = m_input->GetFullWidth(scale); } BreakUpCells(parser, m_fontSize, parser.GetClientWidth()); BreakLines(parser.GetClientWidth()); } ResetData(); }
void GroupCell::RecalculateSize(CellParser& parser, int fontsize) { if (m_width == -1 || m_height == -1 || parser.ForceUpdate()) { // special case if (m_groupType == GC_TYPE_PAGEBREAK) { m_width = 10; m_height = 2; m_center = 0; m_indent = 0; MathCell::RecalculateWidthsList(parser, fontsize); return; } double scale = parser.GetScale(); m_input->RecalculateSizeList(parser, fontsize); m_center = m_input->GetMaxCenter(); m_height = m_input->GetMaxHeight(); m_indent = parser.GetIndent(); if (m_output != NULL && !m_hide) { MathCell *tmp = m_output; while (tmp != NULL) { tmp->RecalculateSize(parser, tmp->IsMath() ? m_mathFontSize : m_fontSize); tmp = tmp->m_next; } m_outputRect.x = m_currentPoint.x; m_outputRect.y = m_currentPoint.y - m_output->GetMaxCenter(); m_outputRect.width = 0; m_outputRect.height = 0; m_height = m_input->GetMaxHeight(); m_width = m_input->GetFullWidth(scale); tmp = m_output; while (tmp != NULL) { if (tmp->BreakLineHere() || tmp == m_output) { m_width = MAX(m_width, tmp->GetLineWidth(scale)); m_outputRect.width = MAX(m_outputRect.width, tmp->GetLineWidth(scale)); m_height += tmp->GetMaxHeight(); if (tmp->m_bigSkip) m_height += MC_LINE_SKIP; m_outputRect.height += tmp->GetMaxHeight() + MC_LINE_SKIP; } tmp = tmp->m_nextToDraw; } } } m_appendedCells = NULL; }
wxString IntCell::ToXML() { MathCell* tmp = m_base; wxString base = _T("<r>") + tmp->ListToXML() + _T("</r>"); tmp = m_var; wxString var = ( tmp == NULL )? wxEmptyString : _T("<r>"); var += tmp->ListToXML(); var += ( var == wxEmptyString )? wxEmptyString : _T("</r>"); tmp = m_under; wxString from = _T("<r>") + tmp->ListToXML() + _T("</r>"); tmp = m_over; wxString to = _T("<r>") + tmp->ListToXML() + _T("</r>"); if (m_intStyle == INT_DEF) return wxT("<in>") + from + to + base + var + wxT("</in>"); else return wxT("<in def=\"false\">") + base + var + wxT("</in>"); }
void Bitmap::Draw() { MathCell* tmp = m_tree; wxMemoryDC dc; dc.SelectObject(m_bmp); wxString bgColStr = wxT("white"); wxConfig::Get()->Read(wxT("Style/Background/color"), &bgColStr); dc.SetBackground(*(wxTheBrushList->FindOrCreateBrush(bgColStr, wxBRUSHSTYLE_SOLID))); dc.Clear(); if (tmp != NULL) { wxPoint point; point.x = 0; point.y = tmp->GetMaxCenter(); int fontsize = 12; int drop = tmp->GetMaxDrop(); wxConfig::Get()->Read(wxT("fontSize"), &fontsize); int mfontsize = fontsize; wxConfig::Get()->Read(wxT("mathfontsize"), &mfontsize); CellParser parser(dc); while (tmp != NULL) { if (!tmp->m_isBroken) { tmp->Draw(parser, point, tmp->IsMath() ? mfontsize : fontsize, false); if (tmp->m_next != NULL && tmp->m_next->BreakLineHere()) { point.x = 0; point.y += drop + tmp->m_next->GetMaxCenter(); if (tmp->m_bigSkip) point.y += MC_LINE_SKIP; drop = tmp->m_next->GetMaxDrop(); } else point.x += (tmp->GetWidth() + MC_CELL_SKIP); } else { if (tmp->m_next != NULL && tmp->m_next->BreakLineHere()) { point.x = 0; point.y += drop + tmp->m_next->GetMaxCenter(); if (tmp->m_bigSkip) point.y += MC_LINE_SKIP; drop = tmp->m_next->GetMaxDrop(); } } tmp = tmp->m_nextToDraw; } } dc.SelectObject(wxNullBitmap); }
void GroupCell::BreakUpCells(MathCell *cell, CellParser parser, int fontsize, int clientWidth) { MathCell *tmp = cell; while (tmp != NULL && !m_hide) { if (tmp->GetWidth() > clientWidth) { if (tmp->BreakUp()) { tmp->RecalculateWidths(parser, tmp->IsMath() ? m_mathFontSize : m_fontSize); tmp->RecalculateSize(parser, tmp->IsMath() ? m_mathFontSize : m_fontSize); } } tmp = tmp->m_nextToDraw; } }
void GroupCell::BreakLines(MathCell *cell, int fullWidth) { int currentWidth = m_indent; MathCell *tmp = cell; while (tmp != NULL && !m_hide) { tmp->ResetData(); tmp->BreakLine(false); if (!tmp->m_isBroken) { if (tmp->BreakLineHere() || (currentWidth + tmp->GetWidth() >= fullWidth)) { currentWidth = m_indent + tmp->GetWidth(); tmp->BreakLine(true); } else currentWidth += (tmp->GetWidth() + MC_CELL_SKIP); } tmp = tmp->m_nextToDraw; } }
void Bitmap::BreakUpCells() { MathCell *tmp = m_tree; int fontsize = 12; wxConfig::Get()->Read(wxT("fontSize"), &fontsize); int mfontsize = fontsize; wxConfig::Get()->Read(wxT("mathfontsize"), &mfontsize); wxMemoryDC dc; CellParser parser(dc); while (tmp != NULL) { if (tmp->GetWidth() > BM_FULL_WIDTH) { if (tmp->BreakUp()) { tmp->RecalculateWidths(parser, tmp->IsMath() ? mfontsize : fontsize, false); tmp->RecalculateSize(parser, tmp->IsMath() ? mfontsize : fontsize, false); } } tmp = tmp->m_nextToDraw; } }
void GroupCell::Draw(CellParser& parser, wxPoint point, int fontsize) { double scale = parser.GetScale(); wxDC& dc = parser.GetDC(); if (m_width == -1 || m_height == -1) { RecalculateWidths(parser, fontsize); RecalculateSize(parser, fontsize); } if (DrawThisCell(parser, point)) { // draw a thick line for 'page break' // and return if (m_groupType == GC_TYPE_PAGEBREAK) { wxRect rect = GetRect(false); int y = rect.GetY(); wxPen pen(parser.GetColor(TS_CURSOR), 1, wxPENSTYLE_DOT); dc.SetPen(pen); dc.DrawLine(0, y , 10000, y); MathCell::Draw(parser, point, fontsize); return; } // // Paint background if we have a text cell // if (m_groupType == GC_TYPE_TEXT) { wxRect rect = GetRect(false); int y = rect.GetY(); if (m_height > 0 && m_width > 0 && y>=0) { wxBrush br(parser.GetColor(TS_TEXT_BACKGROUND)); dc.SetBrush(br); wxPen pen(parser.GetColor(TS_TEXT_BACKGROUND)); dc.SetPen(pen); dc.DrawRectangle(0, y , 10000, rect.GetHeight()); } } // // Draw input and output // SetPen(parser); wxPoint in(point); parser.Outdated(false); m_input->DrawList(parser, in, fontsize); if (m_groupType == GC_TYPE_CODE && m_input->m_next) parser.Outdated(((EditorCell *)(m_input->m_next))->ContainsChanges()); if (m_output != NULL && !m_hide) { MathCell *tmp = m_output; int drop = tmp->GetMaxDrop(); in.y += m_input->GetMaxDrop() + m_output->GetMaxCenter(); m_outputRect.y = in.y - m_output->GetMaxCenter(); m_outputRect.x = in.x; while (tmp != NULL) { if (!tmp->m_isBroken) { tmp->m_currentPoint.x = in.x; tmp->m_currentPoint.y = in.y; if (tmp->DrawThisCell(parser, in)) tmp->Draw(parser, in, MAX(tmp->IsMath() ? m_mathFontSize : m_fontSize, MC_MIN_SIZE)); if (tmp->m_nextToDraw != NULL) { if (tmp->m_nextToDraw->BreakLineHere()) { in.x = m_indent; in.y += drop + tmp->m_nextToDraw->GetMaxCenter(); if (tmp->m_bigSkip) in.y += MC_LINE_SKIP; drop = tmp->m_nextToDraw->GetMaxDrop(); } else in.x += (tmp->GetWidth() + MC_CELL_SKIP); } } else { if (tmp->m_nextToDraw != NULL && tmp->m_nextToDraw->BreakLineHere()) { in.x = m_indent; in.y += drop + tmp->m_nextToDraw->GetMaxCenter(); if (tmp->m_bigSkip) in.y += MC_LINE_SKIP; drop = tmp->m_nextToDraw->GetMaxDrop(); } } tmp = tmp->m_nextToDraw; } } parser.Outdated(false); MathCell *editable = GetEditable(); if (editable != NULL && editable->IsActive()) { dc.SetPen( *(wxThePenList->FindOrCreatePen(parser.GetColor(TS_ACTIVE_CELL_BRACKET), 2, wxPENSTYLE_SOLID))); // window linux, set a pen dc.SetBrush( *(wxTheBrushList->FindOrCreateBrush(parser.GetColor(TS_ACTIVE_CELL_BRACKET)))); //highlight c. } else { dc.SetPen( *(wxThePenList->FindOrCreatePen(parser.GetColor(TS_CELL_BRACKET), 1, wxPENSTYLE_SOLID))); // window linux, set a pen dc.SetBrush( *(wxTheBrushList->FindOrCreateBrush(parser.GetColor(TS_CELL_BRACKET)))); //highlight c. } if ((!m_hide) && (!m_hiddenTree)) { dc.SetBrush(*wxTRANSPARENT_BRUSH); } if (IsFoldable()) { // draw a square wxPoint *points = new wxPoint[4]; points[0].x = point.x - SCALE_PX(10, scale); points[0].y = point.y - m_center; points[1].x = point.x - SCALE_PX(10, scale); points[1].y = point.y - m_center + SCALE_PX(10, scale); points[2].x = point.x; points[2].y = point.y - m_center + SCALE_PX(10, scale); points[3].x = point.x; points[3].y = point.y - m_center; dc.DrawPolygon(4, points); delete [] points; } else { // draw a triangle and line wxPoint *points = new wxPoint[3]; points[0].x = point.x - SCALE_PX(10, scale); points[0].y = point.y - m_center; points[1].x = point.x - SCALE_PX(10, scale); points[1].y = point.y - m_center + SCALE_PX(10, scale); points[2].x = point.x; points[2].y = point.y - m_center; dc.DrawPolygon(3, points); delete [] points; // vertical dc.DrawLine(point.x - SCALE_PX(10, scale), point.y - m_center, point.x - SCALE_PX(10, scale), point.y - m_center + m_height); // bottom horizontal dc.DrawLine(point.x - SCALE_PX(10, scale), point.y - m_center + m_height, point.x - SCALE_PX(2, scale) , point.y - m_center + m_height); // middle horizontal if (m_groupType == GC_TYPE_CODE && m_output != NULL && !m_hide) { dc.DrawLine(point.x - SCALE_PX(6, scale), point.y - m_center + m_input->GetMaxHeight(), point.x - SCALE_PX(10, scale), point.y - m_center + m_input->GetMaxHeight()); } } UnsetPen(parser); } MathCell::Draw(parser, point, fontsize); }
wxString GroupCell::ToTeX(wxString imgDir, wxString filename, int *imgCounter) { wxString str; bool SuppressLeadingNewlines = true; // Now we might want to introduce some markdown: MarkDownTeX MarkDownParser; bool exportInput = true; wxConfig::Get()->Read(wxT("exportInput"), &exportInput); // pagebreak if (m_groupType == GC_TYPE_PAGEBREAK) { str = wxT("\\pagebreak\n"); SuppressLeadingNewlines = true; } // IMAGE CELLS else if (m_groupType == GC_TYPE_IMAGE && imgDir != wxEmptyString) { MathCell *copy = m_output->Copy(); (*imgCounter)++; wxString image = filename + wxString::Format(wxT("_%d"), *imgCounter); wxString file = imgDir + wxT("/") + image + wxT(".png"); Bitmap bmp; bmp.SetData(copy); if (!wxDirExists(imgDir)) wxMkdir(imgDir); if (bmp.ToFile(file).x>=0) { str << wxT("\\begin{figure}[htb]\n") << wxT(" \\begin{center}\n") << wxT(" \\includeimage{") << filename << wxT("_img/") << image << wxT("}\n") << wxT(" \\caption{") << PrepareForTeX(m_input->m_next->GetValue()) << wxT("}\n") << wxT(" \\end{center}\n") << wxT("\\end{figure}"); } } else if (m_groupType == GC_TYPE_IMAGE) str << wxT("\n\\vert|<<GRAPHICS>>|\n"); // CODE CELLS else if (m_groupType == GC_TYPE_CODE) { // Input cells if(exportInput) { str = wxT("\n\\noindent\n%%%%%%%%%%%%%%%\n") wxT("%%% INPUT:\n") wxT("\\begin{minipage}[t]{8ex}{\\color{red}\\bf\n") wxT("\\begin{verbatim}\n") + m_input->ToString() + wxT("\n\\end{verbatim}}\n\\end{minipage}"); if (m_input->m_next!=NULL) { wxString input = m_input->m_next->ToString(); #if wxUSE_UNICODE input.Replace(wxT("\x2212"), wxT("-")); // unicode minus sign input.Replace(wxT("\xDCB6"), wxT(" ")); // Some weird unicode space character #endif str += wxT("\n\\begin{minipage}[t]{\\textwidth}{\\color{blue}\n\\begin{verbatim}\n") + input + wxT("\n\\end{verbatim}}\n\\end{minipage}"); } str += wxT("\n"); } else str = wxEmptyString; if (m_output != NULL) { str += wxT("%%% OUTPUT:\n"); // Need to define labelcolor if this is Copy as LaTeX! if (imgCounter == NULL) str += wxT("\\definecolor{labelcolor}{RGB}{100,0,0}\n"); MathCell *tmp = m_output; bool mathMode = false; while (tmp != NULL) { if (tmp->GetType() == MC_TYPE_IMAGE || tmp->GetType() == MC_TYPE_SLIDE) { if (imgDir != wxEmptyString) { MathCell *copy = tmp->Copy(); (*imgCounter)++; wxString image = filename + wxString::Format(wxT("_%d"), *imgCounter); if (!wxDirExists(imgDir)) if (!wxMkdir(imgDir)) continue; // Do we want to output LaTeX animations? bool AnimateLaTeX=true; wxConfig::Get()->Read(wxT("AnimateLaTeX"), &AnimateLaTeX); if((tmp->GetType() == MC_TYPE_SLIDE)&&(AnimateLaTeX)) { SlideShow* src=(SlideShow *)tmp; str << wxT("\\begin{animateinline}{")+wxString::Format(wxT("%i"), src->GetFrameRate())+wxT("}\n"); for(int i=0;i<src->Length();i++) { wxString Frame = imgDir + wxT("/") + image + wxString::Format(wxT("_%i"), i); if((src->GetBitmap(i)).SaveFile(Frame+wxT(".png"))) str << wxT("\\includegraphics[width=.95\\linewidth,height=.80\\textheight,keepaspectratio]{")+Frame+wxT("}\n"); else str << wxT("\n\\verb|<<GRAPHICS>>|\n"); if(i<src->Length()-1) str << wxT("\\newframe"); } str << wxT("\\end{animateinline}"); } else { wxString file = imgDir + wxT("/") + image + wxT(".png"); Bitmap bmp; bmp.SetData(copy); if (bmp.ToFile(file).x>=0) str += wxT("\\includegraphics[width=.95\\linewidth,height=.80\\textheight,keepaspectratio]{") + filename + wxT("_img/") + image + wxT("}"); else str << wxT("\n\\verb|<<GRAPHICS>>|\n"); } } } else if (tmp->GetStyle() == TS_LABEL) { if(mathMode) str += wxT("\\end{math}\n\n\\begin{math}\\displaystyle\n"); else { str += wxT("\n\n\\begin{math}\\displaystyle\n"); mathMode=true; } str += wxT("\\parbox{8ex}{\\color{labelcolor}") + tmp->ToTeX() + wxT("}\n"); } else { if((tmp->GetStyle() == TS_DEFAULT)||(tmp->GetStyle() == TS_STRING)) { // We either got a bracket or a parenthesis or regular Text // that shouldn't be displayed as math. if((mathMode)&&(tmp->ToString().Length()>2)) { str += wxT("\\mbox{}"); str += wxT("\n\\end{math}\n"); mathMode = false; } } else { if(!mathMode) { str += wxT("\n\n\\begin{math}\\displaystyle\n"); mathMode = true; } } str += TexEscapeOutputCell(tmp->ToTeX()); } tmp = tmp->m_nextToDraw; } if(mathMode) { // Some invisible dummy content that keeps TeX happy if there really is // no output to display. str += wxT("\\mbox{}"); str += wxT("\n\\end{math}\n%%%%%%%%%%%%%%%\n"); } } } // TITLES, SECTIONS, SUBSECTIONS, SUBSUBSECTIONS, TEXT else if (GetEditable() != NULL && !m_hide) { str = GetEditable()->ListToTeX(); switch (GetEditable()->GetStyle()) { case TS_TITLE: str = wxT("\n\\pagebreak{}\n{\\Huge {\\sc ") + PrepareForTeX(str) + wxT("}}\n"); str += wxT("\\setcounter{section}{0}\n\\setcounter{subsection}{0}\n"); str += wxT("\\setcounter{figure}{0}\n\n"); break; case TS_SECTION: str = wxT("\n\\section{") + PrepareForTeX(str) + wxT("}\n\n"); break; case TS_SUBSECTION: str = wxT("\n\\subsection{") + PrepareForTeX(str) + wxT("}\n\n"); break; case TS_SUBSUBSECTION: str = wxT("\n\\subsubsection{") + PrepareForTeX(str) + wxT("}\n\n"); break; default: if (str.StartsWith(wxT("TeX:"))) str = str.Mid(5, str.Length()); else { str = PrepareForTeX(str); str = MarkDownParser.MarkDown(str); } break; } } return str; }
// ParseCellTag // This function is responsible for creating // a tree of groupcells when loading XML document. // Any changes in GroupCell structure or methods // has to be reflected here in order to ensure proper // loading of WXMX files. MathCell* MathParser::ParseCellTag(wxXmlNode* node) { GroupCell *group = NULL; // read hide status #if wxCHECK_VERSION(2,9,0) bool hide = (node->GetAttribute(wxT("hide"), wxT("false")) == wxT("true")) ? true : false; #else bool hide = (node->GetPropVal(wxT("hide"), wxT("false")) == wxT("true")) ? true : false; #endif // read (group)cell type #if wxCHECK_VERSION(2,9,0) wxString type = node->GetAttribute(wxT("type"), wxT("text")); #else wxString type = node->GetPropVal(wxT("type"), wxT("text")); #endif if (type == wxT("code")) { group = new GroupCell(GC_TYPE_CODE); wxXmlNode *children = node->GetChildren(); while (children) { if (children->GetName() == wxT("input")) { MathCell *editor = ParseTag(children->GetChildren()); group->SetEditableContent(editor->GetValue()); delete editor; } if (children->GetName() == wxT("output")) group->AppendOutput(ParseTag(children->GetChildren())); children = children->GetNext(); } } else if (type == wxT("image")) { group = new GroupCell(GC_TYPE_IMAGE); wxXmlNode *children = node->GetChildren(); while (children) { if (children->GetName() == wxT("editor")) { MathCell *ed = ParseEditorTag(children); group->SetEditableContent(ed->GetValue()); delete ed; } else group->AppendOutput(ParseTag(children)); children = children->GetNext(); } } else if (type == wxT("pagebreak")) { group = new GroupCell(GC_TYPE_PAGEBREAK); } else if (type == wxT("text")) { group = new GroupCell(GC_TYPE_TEXT); MathCell *editor = ParseTag(node->GetChildren()); group->SetEditableContent(editor->GetValue()); delete editor; } else { // text types if (type == wxT("title")) group = new GroupCell(GC_TYPE_TITLE); else if (type == wxT("section")) group = new GroupCell(GC_TYPE_SECTION); else if (type == wxT("subsection")) group = new GroupCell(GC_TYPE_SUBSECTION); else return NULL; wxXmlNode *children = node->GetChildren(); while (children) { if (children->GetName() == wxT("editor")) { MathCell *ed = ParseEditorTag(children); group->SetEditableContent(ed->GetValue()); delete ed; } else if (children->GetName() == wxT("fold")) { // we have folded groupcells wxXmlNode *xmlcells = children->GetChildren(); MathCell *tree = NULL; MathCell *last = NULL; if (xmlcells) { last = tree = ParseTag(xmlcells, false); // first cell while (xmlcells->GetNext()) { xmlcells = xmlcells->GetNext(); MathCell *cell = ParseTag(xmlcells, false); last->m_next = last->m_nextToDraw = cell; last->m_next->m_previous = last->m_next->m_previousToDraw = last; last = last->m_next; } if (tree) group->HideTree((GroupCell *)tree); } } children = children->GetNext(); } } group->SetParent(group, false); group->Hide(hide); return group; }
MathCell* MathParser::ParseTag(wxXmlNode* node, bool all) { // wxYield(); MathCell* tmp = NULL; MathCell* cell = NULL; bool warning = all; wxString altCopy; while (node) { // Parse tags if (node->GetType() == wxXML_ELEMENT_NODE) { wxString tagName(node->GetName()); if (tagName == wxT("v")) { // Variables (atoms) if (cell == NULL) cell = ParseText(node->GetChildren(), TS_VARIABLE); else cell->AppendCell(ParseText(node->GetChildren(), TS_VARIABLE)); } else if (tagName == wxT("t")) { // Other text if (cell == NULL) cell = ParseText(node->GetChildren(), TS_DEFAULT); else cell->AppendCell(ParseText(node->GetChildren(), TS_DEFAULT)); } else if (tagName == wxT("n")) { // Numbers if (cell == NULL) cell = ParseText(node->GetChildren(), TS_NUMBER); else cell->AppendCell(ParseText(node->GetChildren(), TS_NUMBER)); } else if (tagName == wxT("h")) { // Hidden cells (*) MathCell* tmp = ParseText(node->GetChildren()); tmp->m_isHidden = true; if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("p")) { // Parenthesis if (cell == NULL) cell = ParseParenTag(node); else cell->AppendCell(ParseParenTag(node)); } else if (tagName == wxT("f")) { // Fractions if (cell == NULL) cell = ParseFracTag(node); else cell->AppendCell(ParseFracTag(node)); } else if (tagName == wxT("e")) { // Exponentials if (cell == NULL) cell = ParseSupTag(node); else cell->AppendCell(ParseSupTag(node)); } else if (tagName == wxT("i")) { // Subscripts if (cell == NULL) cell = ParseSubTag(node); else cell->AppendCell(ParseSubTag(node)); } else if (tagName == wxT("fn")) { // Functions if (cell == NULL) cell = ParseFunTag(node); else cell->AppendCell(ParseFunTag(node)); } else if (tagName == wxT("g")) { // Greek constants MathCell* tmp = ParseText(node->GetChildren(), TS_GREEK_CONSTANT); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("s")) { // Special constants %e,... MathCell* tmp = ParseText(node->GetChildren(), TS_SPECIAL_CONSTANT); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("fnm")) { // Function names MathCell* tmp = ParseText(node->GetChildren(), TS_FUNCTION); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("q")) { // Square roots if (cell == NULL) cell = ParseSqrtTag(node); else cell->AppendCell(ParseSqrtTag(node)); } else if (tagName == wxT("d")) { // Differentials if (cell == NULL) cell = ParseDiffTag(node); else cell->AppendCell(ParseDiffTag(node)); } else if (tagName == wxT("sm")) { // Sums if (cell == NULL) cell = ParseSumTag(node); else cell->AppendCell(ParseSumTag(node)); } else if (tagName == wxT("in")) { // integrals if (cell == NULL) cell = ParseIntTag(node); else cell->AppendCell(ParseIntTag(node)); } else if (tagName == wxT("mspace")) { if (cell == NULL) cell = new TextCell(wxT(" ")); else cell->AppendCell(new TextCell(wxT(" "))); } else if (tagName == wxT("at")) { if (cell == NULL) cell = ParseAtTag(node); else cell->AppendCell(ParseAtTag(node)); } else if (tagName == wxT("a")) { if (cell == NULL) cell = ParseAbsTag(node); else cell->AppendCell(ParseAbsTag(node)); } else if (tagName == wxT("ie")) { if (cell == NULL) cell = ParseSubSupTag(node); else cell->AppendCell(ParseSubSupTag(node)); } else if (tagName == wxT("lm")) { if (cell == NULL) cell = ParseLimitTag(node); else cell->AppendCell(ParseLimitTag(node)); } else if (tagName == wxT("r")) { if (cell == NULL) cell = ParseTag(node->GetChildren()); else cell->AppendCell(ParseTag(node->GetChildren())); } else if (tagName == wxT("tb")) { if (cell == NULL) cell = ParseTableTag(node); else cell->AppendCell(ParseTableTag(node)); } else if ((tagName == wxT("mth")) || (tagName == wxT("line"))) { MathCell *tmp = ParseTag(node->GetChildren()); if (tmp != NULL) tmp->ForceBreakLine(true); else tmp = new TextCell(wxT(" ")); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("lbl")) { MathCell* tmp = ParseText(node->GetChildren(), TS_LABEL); tmp->ForceBreakLine(true); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("st")) { MathCell* tmp = ParseText(node->GetChildren(), TS_STRING); if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("hl")) { bool highlight = m_highlight; m_highlight = true; MathCell* tmp = ParseTag(node->GetChildren()); m_highlight = highlight; if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("img")) { wxString filename(node->GetChildren()->GetContent()); #if !wxUSE_UNICODE wxString filename1(filename.wc_str(wxConvUTF8), *wxConvCurrent); filename = filename1; #endif ImgCell *tmp; if (m_fileSystem) // loading from zip tmp = new ImgCell(filename, false, m_fileSystem); #if wxCHECK_VERSION(2,9,0) else if (node->GetAttribute(wxT("del"), wxT("yes")) != wxT("no")) #else else if (node->GetPropVal(wxT("del"), wxT("yes")) != wxT("no")) #endif tmp = new ImgCell(filename, true, NULL); else tmp = new ImgCell(filename, false, NULL); #if wxCHECK_VERSION(2,9,0) if (node->GetAttribute(wxT("rect"), wxT("true")) == wxT("false")) tmp->DrawRectangle(false); #else if (node->GetPropVal(wxT("rect"), wxT("true")) == wxT("false")) tmp->DrawRectangle(false); #endif if (cell == NULL) cell = tmp; else cell->AppendCell(tmp); } else if (tagName == wxT("slide"))
wxString GroupCell::ToXML() { wxString str; str = wxT("\n<cell"); // start opening tag // write "type" according to m_groupType switch (m_groupType) { case GC_TYPE_CODE: str += wxT(" type=\"code\""); break; case GC_TYPE_IMAGE: str += wxT(" type=\"image\""); break; case GC_TYPE_TEXT: str += wxT(" type=\"text\""); break; case GC_TYPE_TITLE: str += wxT(" type=\"title\" sectioning_level=\"1\""); break; case GC_TYPE_SECTION: str += wxT(" type=\"section\" sectioning_level=\"2\""); break; case GC_TYPE_SUBSECTION: str += wxT(" type=\"subsection\" sectioning_level=\"3\""); break; case GC_TYPE_SUBSUBSECTION: // We save subsubsections as subsections with a higher sectioning level: // This makes them backwards-compatible in the way that they are displayed // as subsections on old wxMaxima installations. str += wxT(" type=\"subsection\" sectioning_level=\"4\""); break; case GC_TYPE_PAGEBREAK: { str += wxT(" type=\"pagebreak\"/>"); return str; } break; default: str += wxT(" type=\"unknown\""); break; } // write hidden status if (m_hide) str += wxT(" hide=\"true\""); str += wxT(">\n"); MathCell *input = GetInput(); MathCell *output = GetLabel(); // write contents switch (m_groupType) { case GC_TYPE_CODE: if (input != NULL) { str += wxT("<input>\n"); str += input->ListToXML(); str += wxT("</input>"); } if (output != NULL) { str += wxT("\n<output>\n"); str += wxT("<mth>"); str += output->ListToXML(); str += wxT("\n</mth></output>"); } break; case GC_TYPE_IMAGE: if (input != NULL) str += input->ListToXML(); if (output != NULL) str += output->ListToXML(); break; case GC_TYPE_TEXT: if (input) str += input->ListToXML(); break; case GC_TYPE_TITLE: case GC_TYPE_SECTION: case GC_TYPE_SUBSECTION: case GC_TYPE_SUBSUBSECTION: if (input) str += input->ListToXML(); if (m_hiddenTree) { str += wxT("<fold>"); str+= m_hiddenTree->ListToXML(); str += wxT("</fold>"); } break; default: { MathCell *tmp = output; while (tmp != NULL) { str += tmp->ListToXML(); tmp = tmp->m_next; } break; } } str += wxT("\n</cell>\n"); return str; }