X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5cb0b827f11ccf2a8e570b3b361a1daf0e5eed76..f9226383059545b8f76bcde41f90d18fbfcffe00:/src/richtext/richtextbuffer.cpp diff --git a/src/richtext/richtextbuffer.cpp b/src/richtext/richtextbuffer.cpp index 3b3e0e0386..782856d81d 100644 --- a/src/richtext/richtextbuffer.cpp +++ b/src/richtext/richtextbuffer.cpp @@ -66,6 +66,7 @@ inline void wxCheckSetFont(wxDC& dc, const wxFont& font) font1.GetStyle() == font.GetStyle() && font1.GetWeight() == font.GetWeight() && font1.GetUnderlined() == font.GetUnderlined() && + font1.GetFamily() == font.GetFamily() && font1.GetFaceName() == font.GetFaceName()) return; } @@ -1988,6 +1989,23 @@ bool wxRichTextParagraphLayoutBox::CollectStyle(wxTextAttr& currentStyle, const } } + if (style.HasFontFamily() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_FAMILY)) + { + if (currentStyle.HasFontFamily()) + { + if (currentStyle.GetFontFamily() != style.GetFontFamily()) + { + // Clash of style - mark as such + multipleStyleAttributes |= wxTEXT_ATTR_FONT_FAMILY; + currentStyle.SetFlags(currentStyle.GetFlags() & ~wxTEXT_ATTR_FONT_FAMILY); + } + } + else + { + currentStyle.SetFontFamily(style.GetFontFamily()); + } + } + if (style.HasFontWeight() && !wxHasStyle(multipleStyleAttributes|absentStyleAttributes, wxTEXT_ATTR_FONT_WEIGHT)) { if (currentStyle.HasFontWeight()) @@ -2836,7 +2854,7 @@ bool wxRichTextParagraphLayoutBox::DoNumberList(const wxRichTextRange& range, co bool withUndo = ((flags & wxRICHTEXT_SETSTYLE_WITH_UNDO) != 0); // bool applyMinimal = ((flags & wxRICHTEXT_SETSTYLE_OPTIMIZE) != 0); -#ifdef __WXDEBUG__ +#if wxDEBUG_LEVEL bool specifyLevel = ((flags & wxRICHTEXT_SETSTYLE_SPECIFY_LEVEL) != 0); #endif @@ -3155,7 +3173,7 @@ bool wxRichTextParagraph::Draw(wxDC& dc, const wxRichTextRange& range, const wxR } // Get line height from first line, if any - wxRichTextLine* line = m_cachedLines.GetFirst() ? (wxRichTextLine* ) m_cachedLines.GetFirst()->GetData() : (wxRichTextLine*) NULL; + wxRichTextLine* line = m_cachedLines.GetFirst() ? (wxRichTextLine* ) m_cachedLines.GetFirst()->GetData() : NULL; wxPoint linePos; int lineHeight wxDUMMY_INITIALIZE(0); @@ -3453,6 +3471,10 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) wxSize actualSize; wxRichTextRange actualRange(lastCompletedEndPos+1, wrapPosition); + /// Use previous descent, not the wrapping descent we just found, since this may be too big + /// for the fragment we're about to add. + childDescent = maxDescent; + #if wxRICHTEXT_USE_PARTIAL_TEXT_EXTENTS // Get height only, then the width using the partial extents GetRangeSize(actualRange, actualSize, childDescent, dc, wxRICHTEXT_UNFORMATTED|wxRICHTEXT_HEIGHT_ONLY); @@ -3550,7 +3572,7 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) ClearUnusedLines(lineCount); // Apply styles to wrapped lines - ApplyParagraphStyle(attr, rect); + ApplyParagraphStyle(attr, rect, dc); SetCachedSize(wxSize(maxWidth, currentPosition.y + spaceBeforePara + spaceAfterPara)); @@ -3602,7 +3624,7 @@ bool wxRichTextParagraph::Layout(wxDC& dc, const wxRect& rect, int style) } /// Apply paragraph styles, such as centering, to wrapped lines -void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttr& attr, const wxRect& rect) +void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttr& attr, const wxRect& rect, wxDC& dc) { if (!attr.HasAlignment()) return; @@ -3618,12 +3640,18 @@ void wxRichTextParagraph::ApplyParagraphStyle(const wxTextAttr& attr, const wxRe // centering, right-justification if (attr.HasAlignment() && GetAttributes().GetAlignment() == wxTEXT_ALIGNMENT_CENTRE) { - pos.x = (rect.GetWidth() - size.x)/2 + pos.x; + int rightIndent = ConvertTenthsMMToPixels(dc, attr.GetRightIndent()); + pos.x = (rect.GetWidth() - (pos.x - rect.x) - rightIndent - size.x)/2 + pos.x; + // Lines are relative to the paragraph position + pos.x -= GetPosition().x; line->SetPosition(pos); } else if (attr.HasAlignment() && GetAttributes().GetAlignment() == wxTEXT_ALIGNMENT_RIGHT) { - pos.x = pos.x + rect.GetWidth() - size.x; + int rightIndent = ConvertTenthsMMToPixels(dc, attr.GetRightIndent()); + pos.x = rect.x + rect.GetWidth() - size.x - rightIndent; + // Lines are relative to the paragraph position + pos.x -= GetPosition().x; line->SetPosition(pos); } @@ -4228,7 +4256,7 @@ bool wxRichTextParagraph::FindWrapPosition(const wxRichTextRange& range, wxDC& d widthBefore = 0; size_t i; - for (i = (size_t) range.GetStart(); i < (size_t) range.GetEnd(); i++) + for (i = (size_t) range.GetStart(); i <= (size_t) range.GetEnd(); i++) { int widthFromStartOfThisRange = (*partialExtents)[i - GetRange().GetStart()] - widthBefore; @@ -4643,7 +4671,9 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR int s1 = selectionRange.GetStart()-1; int fragmentLen = s1 - r1 + 1; if (fragmentLen < 0) + { wxLogDebug(wxT("Mid(%d, %d"), (int)(r1 - offset), (int)fragmentLen); + } wxString stringFragment = str.Mid(r1 - offset, fragmentLen); DrawTabbedString(dc, textAttr, rect, stringFragment, x, y, false); @@ -4674,7 +4704,9 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR int fragmentLen = s2 - s1 + 1; if (fragmentLen < 0) + { wxLogDebug(wxT("Mid(%d, %d"), (int)(s1 - offset), (int)fragmentLen); + } wxString stringFragment = str.Mid(s1 - offset, fragmentLen); DrawTabbedString(dc, textAttr, rect, stringFragment, x, y, true); @@ -4705,7 +4737,9 @@ bool wxRichTextPlainText::Draw(wxDC& dc, const wxRichTextRange& range, const wxR int fragmentLen = r2 - s2 + 1; if (fragmentLen < 0) + { wxLogDebug(wxT("Mid(%d, %d"), (int)(s2 - offset), (int)fragmentLen); + } wxString stringFragment = str.Mid(s2 - offset, fragmentLen); DrawTabbedString(dc, textAttr, rect, stringFragment, x, y, false); @@ -4766,6 +4800,7 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxTextAttr& attr, con dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT); } + wxCoord x_orig = x; while (hasTabs) { // the string has a tab @@ -4777,7 +4812,7 @@ bool wxRichTextPlainText::DrawTabbedString(wxDC& dc, const wxTextAttr& attr, con bool not_found = true; for (int i = 0; i < tabCount && not_found; ++i) { - nextTabPos = tabArray.Item(i); + nextTabPos = tabArray.Item(i) + x_orig; // Find the next tab position. // Even if we're at the end of the tab array, we must still draw the chunk. @@ -5473,7 +5508,7 @@ wxTextAttr wxRichTextBuffer::GetStyleForNewParagraph(long pos, bool caretPositio if (para->GetAttributes().HasBulletNumber()) attr.SetBulletNumber(para->GetAttributes().GetBulletNumber()); } - } + } if (!foundAttributes) { @@ -5658,7 +5693,7 @@ void wxRichTextBuffer::ClearStyleStack() bool wxRichTextBuffer::BeginBold() { wxTextAttr attr; - attr.SetFontWeight(wxBOLD); + attr.SetFontWeight(wxFONTWEIGHT_BOLD); return BeginStyle(attr); } @@ -5667,7 +5702,7 @@ bool wxRichTextBuffer::BeginBold() bool wxRichTextBuffer::BeginItalic() { wxTextAttr attr; - attr.SetFontStyle(wxITALIC); + attr.SetFontStyle(wxFONTSTYLE_ITALIC); return BeginStyle(attr); } @@ -5903,7 +5938,7 @@ wxRichTextFileHandler *wxRichTextBuffer::FindHandlerFilenameOrType(const wxStrin else if (!filename.IsEmpty()) { wxString path, file, ext; - wxSplitPath(filename, & path, & file, & ext); + wxFileName::SplitPath(filename, & path, & file, & ext); return FindHandler(ext, imageType); } else @@ -6460,10 +6495,10 @@ bool wxRichTextStdRenderer::DrawBitmapBullet(wxRichTextParagraph* WXUNUSED(parag /// Enumerate the standard bullet names currently supported bool wxRichTextStdRenderer::EnumerateStandardBulletNames(wxArrayString& bulletNames) { - bulletNames.Add(wxT("standard/circle")); - bulletNames.Add(wxT("standard/square")); - bulletNames.Add(wxT("standard/diamond")); - bulletNames.Add(wxT("standard/triangle")); + bulletNames.Add(wxTRANSLATE("standard/circle")); + bulletNames.Add(wxTRANSLATE("standard/square")); + bulletNames.Add(wxTRANSLATE("standard/diamond")); + bulletNames.Add(wxTRANSLATE("standard/triangle")); return true; } @@ -7067,10 +7102,11 @@ bool wxRichTextImage::LoadFromBlock() /// Make block from the wxImage bool wxRichTextImage::MakeBlock() { - if (m_imageBlock.GetImageType() == wxBITMAP_TYPE_ANY || m_imageBlock.GetImageType() == -1) - m_imageBlock.SetImageType(wxBITMAP_TYPE_PNG); + wxBitmapType type = m_imageBlock.GetImageType(); + if ( type == wxBITMAP_TYPE_ANY || type == wxBITMAP_TYPE_INVALID ) + m_imageBlock.SetImageType(type = wxBITMAP_TYPE_PNG); - m_imageBlock.MakeImageBlock(m_image, m_imageBlock.GetImageType()); + m_imageBlock.MakeImageBlock(m_image, type); return m_imageBlock.Ok(); } @@ -7300,7 +7336,7 @@ bool wxRichTextFileHandler::SaveFile(wxRichTextBuffer *buffer, const wxString& f bool wxRichTextFileHandler::CanHandle(const wxString& filename) const { wxString path, file, ext; - wxSplitPath(filename, & path, & file, & ext); + wxFileName::SplitPath(filename, & path, & file, & ext); return (ext.Lower() == GetExtension()); } @@ -7416,17 +7452,15 @@ bool wxRichTextImageBlock::MakeImageBlock(const wxString& filename, wxBitmapType wxString filenameToRead(filename); bool removeFile = false; - if (imageType == -1) + if (imageType == wxBITMAP_TYPE_INVALID) return false; // Could not determine image type if ((imageType != wxBITMAP_TYPE_JPEG) && convertToJPEG) { - wxString tempFile; - bool success = wxGetTempFileName(_("image"), tempFile) ; - - wxASSERT(success); + wxString tempFile = + wxFileName::CreateTempFileName(_("image")); - wxUnusedVar(success); + wxASSERT(!tempFile.IsEmpty()); image.SaveFile(tempFile, wxBITMAP_TYPE_JPEG); filenameToRead = tempFile; @@ -7458,14 +7492,11 @@ bool wxRichTextImageBlock::MakeImageBlock(wxImage& image, wxBitmapType imageType m_imageType = imageType; image.SetOption(wxT("quality"), quality); - if (imageType == -1) + if (imageType == wxBITMAP_TYPE_INVALID) return false; // Could not determine image type - wxString tempFile; - bool success = wxGetTempFileName(_("image"), tempFile) ; - - wxASSERT(success); - wxUnusedVar(success); + wxString tempFile = wxFileName::CreateTempFileName(_("image")) ; + wxASSERT(!tempFile.IsEmpty()); if (!image.SaveFile(tempFile, m_imageType)) { @@ -7532,9 +7563,8 @@ bool wxRichTextImageBlock::Load(wxImage& image) wxMemoryInputStream mstream(m_data, m_dataSize); bool success = image.LoadFile(mstream, GetImageType()); #else - wxString tempFile; - bool success = wxGetTempFileName(_("image"), tempFile) ; - wxASSERT(success); + wxString tempFile = wxFileName::CreateTempFileName(_("image")); + wxASSERT(!tempFile.IsEmpty()); if (!WriteBlock(tempFile, m_data, m_dataSize)) { @@ -7588,7 +7618,10 @@ bool wxRichTextImageBlock::ReadHex(wxInputStream& stream, int length, wxBitmapTy if (m_data) delete[] m_data; - wxChar str[2]; + // create a null terminated temporary string: + char str[3]; + str[2] = '\0'; + m_data = new unsigned char[dataSize]; int i; for (i = 0; i < dataSize; i ++)