Mostly adapted to the refactored RTF classes hierarchy.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@10564 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2005-01-03 02:04:44 +00:00
parent a7e0bca0f7
commit 64214d4cce
4 changed files with 30 additions and 27 deletions
@@ -120,7 +120,9 @@ RTFTranslator::Identify(BPositionIO *stream,
if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT) if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT)
return B_NO_TRANSLATOR; return B_NO_TRANSLATOR;
status_t status = RTFHeader::Identify(*stream); RTF::Parser parser(*stream);
status_t status = parser.Identify();
if (status != B_OK) if (status != B_OK)
return B_NO_TRANSLATOR; return B_NO_TRANSLATOR;
@@ -149,8 +151,10 @@ RTFTranslator::Translate(BPositionIO *source,
if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT) if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT)
return B_NO_TRANSLATOR; return B_NO_TRANSLATOR;
RTFHeader header; RTF::Parser parser(*source);
status_t status = RTFHeader::Parse(*source, header);
RTF::Header header;
status_t status = parser.Parse(header);
if (status != B_OK) if (status != B_OK)
return status; return status;
@@ -15,7 +15,6 @@
#include <File.h> #include <File.h>
#include <ByteOrder.h> #include <ByteOrder.h>
#include <fs_attr.h> #include <fs_attr.h>
#include "BaseTranslator.h"
#define RTF_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VER(1, 0, 0) #define RTF_TRANSLATOR_VERSION B_TRANSLATION_MAKE_VER(1, 0, 0)
@@ -52,7 +52,7 @@ AppServerConnection::~AppServerConnection()
static size_t static size_t
get_text_for_command(RTFCommand *command, char *text, size_t size) get_text_for_command(RTF::Command *command, char *text, size_t size)
{ {
const char *name = command->Name(); const char *name = command->Name();
@@ -89,23 +89,23 @@ get_style(BList &runs, text_run *run, int32 offset)
static text_run_array * static text_run_array *
get_text_run_array(RTFHeader &header) get_text_run_array(RTF::Header &header)
{ {
// collect styles // collect styles
RTFIterator iterator(header, RTF_TEXT); RTF::Iterator iterator(header, RTF::TEXT_DESTINATION);
text_run *current = NULL; text_run *current = NULL;
int32 offset = 0; int32 offset = 0;
BList runs; BList runs;
while (iterator.HasNext()) { while (iterator.HasNext()) {
RTFElement *element = iterator.Next(); RTF::Element *element = iterator.Next();
if (RTFText *text = dynamic_cast<RTFText *>(element)) { if (RTF::Text *text = dynamic_cast<RTF::Text *>(element)) {
offset += text->TextLength(); offset += text->Length();
continue; continue;
} }
RTFCommand *command = dynamic_cast<RTFCommand *>(element); RTF::Command *command = dynamic_cast<RTF::Command *>(element);
if (command == NULL) if (command == NULL)
continue; continue;
@@ -149,20 +149,20 @@ get_text_run_array(RTFHeader &header)
status_t status_t
write_plain_text(RTFHeader &header, BDataIO &target) write_plain_text(RTF::Header &header, BDataIO &target)
{ {
RTFIterator iterator(header, RTF_TEXT); RTF::Iterator iterator(header, RTF::TEXT_DESTINATION);
while (iterator.HasNext()) { while (iterator.HasNext()) {
RTFElement *element = iterator.Next(); RTF::Element *element = iterator.Next();
char buffer[1024]; char buffer[1024];
const char *string = NULL; const char *string = NULL;
size_t size = 0; size_t size = 0;
if (RTFText *text = dynamic_cast<RTFText *>(element)) { if (RTF::Text *text = dynamic_cast<RTF::Text *>(element)) {
string = text->Text(); string = text->String();
size = text->TextLength(); size = text->Length();
} else if (RTFCommand *command = dynamic_cast<RTFCommand *>(element)) { } else if (RTF::Command *command = dynamic_cast<RTF::Command *>(element)) {
size = get_text_for_command(command, buffer, sizeof(buffer)); size = get_text_for_command(command, buffer, sizeof(buffer));
if (size != 0) if (size != 0)
string = buffer; string = buffer;
@@ -186,18 +186,18 @@ write_plain_text(RTFHeader &header, BDataIO &target)
status_t status_t
convert_to_stxt(RTFHeader &header, BDataIO &target) convert_to_stxt(RTF::Header &header, BDataIO &target)
{ {
// count text bytes // count text bytes
size_t textSize = 0; size_t textSize = 0;
RTFIterator iterator(header, RTF_TEXT); RTF::Iterator iterator(header, RTF::TEXT_DESTINATION);
while (iterator.HasNext()) { while (iterator.HasNext()) {
RTFElement *element = iterator.Next(); RTF::Element *element = iterator.Next();
if (RTFText *text = dynamic_cast<RTFText *>(element)) { if (RTF::Text *text = dynamic_cast<RTF::Text *>(element)) {
textSize += text->TextLength(); textSize += text->Length();
} else if (RTFCommand *command = dynamic_cast<RTFCommand *>(element)) { } else if (RTF::Command *command = dynamic_cast<RTF::Command *>(element)) {
textSize += get_text_for_command(command, NULL, 0); textSize += get_text_for_command(command, NULL, 0);
} }
} }
@@ -294,7 +294,7 @@ convert_to_stxt(RTFHeader &header, BDataIO &target)
status_t status_t
convert_to_plain_text(RTFHeader &header, BPositionIO &target) convert_to_plain_text(RTF::Header &header, BPositionIO &target)
{ {
// put out main text // put out main text
@@ -10,7 +10,7 @@
#include <DataIO.h> #include <DataIO.h>
extern status_t convert_to_stxt(RTFHeader &header, BDataIO &target); extern status_t convert_to_stxt(RTF::Header &header, BDataIO &target);
extern status_t convert_to_plain_text(RTFHeader &header, BPositionIO &target); extern status_t convert_to_plain_text(RTF::Header &header, BPositionIO &target);
#endif /* CONVERT_H */ #endif /* CONVERT_H */