Paragraph: Added simple PrintToStream().

This commit is contained in:
Stephan Aßmus 2014-01-22 00:10:49 +01:00
parent 0e36794492
commit b3299ecd73
2 changed files with 28 additions and 2 deletions

View File

@ -1,11 +1,12 @@
/*
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#include "Paragraph.h"
#include <algorithm>
#include <stdio.h>
Paragraph::Paragraph()
@ -268,3 +269,26 @@ Paragraph::GetText(int32 start, int32 length) const
return text;
}
void
Paragraph::PrintToStream() const
{
int32 spanCount = fTextSpans.CountItems();
if (spanCount == 0) {
printf(" <p/>\n");
return;
}
printf(" <p>\n");
for (int32 i = 0; i < spanCount; i++) {
const TextSpan& span = fTextSpans.ItemAtFast(i);
if (span.CountChars() == 0)
printf(" <span/>\n");
else {
BString text = span.Text();
text.ReplaceAll("\n", "\\n");
printf(" <span>%s<span/>\n", text.String());
}
}
printf(" </p>\n");
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2013, Stephan Aßmus <superstippi@gmx.de>.
* Copyright 2013-2014, Stephan Aßmus <superstippi@gmx.de>.
* All rights reserved. Distributed under the terms of the MIT License.
*/
#ifndef PARAGRAPH_H
@ -41,6 +41,8 @@ public:
BString GetText(int32 start, int32 length) const;
void PrintToStream() const;
private:
ParagraphStyle fStyle;
TextSpanList fTextSpans;