RTFTranslator: don't accept translations with no RTF involved.
Fixes #11650. Thanks to TwoFx for investigating the issue.
This commit is contained in:
@@ -154,18 +154,21 @@ status_t
|
|||||||
RTFTranslator::Identify(BPositionIO *stream,
|
RTFTranslator::Identify(BPositionIO *stream,
|
||||||
const translation_format *format, BMessage *ioExtension,
|
const translation_format *format, BMessage *ioExtension,
|
||||||
translator_info *info, uint32 outType)
|
translator_info *info, uint32 outType)
|
||||||
{
|
{
|
||||||
if (!outType)
|
if (!outType)
|
||||||
outType = B_TRANSLATOR_TEXT;
|
outType = B_TRANSLATOR_TEXT;
|
||||||
else if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT
|
else if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT
|
||||||
&& outType != RTF_TEXT_FORMAT)
|
&& outType != RTF_TEXT_FORMAT)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
|
|
||||||
RTF::Parser parser(*stream);
|
RTF::Parser parser(*stream);
|
||||||
status_t status = parser.Identify();
|
status_t status = parser.Identify();
|
||||||
|
|
||||||
if (status == B_OK) {
|
if (status == B_OK) {
|
||||||
|
// Source data is RTF. We can translate to RTF (no-op), plaintext, or
|
||||||
|
// styled text.
|
||||||
|
|
||||||
// return information about the data in the stream
|
// return information about the data in the stream
|
||||||
info->type = B_TRANSLATOR_TEXT; //RTF_TEXT_FORMAT;
|
info->type = B_TRANSLATOR_TEXT; //RTF_TEXT_FORMAT;
|
||||||
info->group = B_TRANSLATOR_TEXT;
|
info->group = B_TRANSLATOR_TEXT;
|
||||||
@@ -175,9 +178,14 @@ RTFTranslator::Identify(BPositionIO *stream,
|
|||||||
sizeof(info->name));
|
sizeof(info->name));
|
||||||
strcpy(info->MIME, "text/rtf");
|
strcpy(info->MIME, "text/rtf");
|
||||||
} else {
|
} else {
|
||||||
|
// Not an RTF file. We can only work with it if we are translating to
|
||||||
|
// RTF.
|
||||||
|
if (outType != RTF_TEXT_FORMAT)
|
||||||
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
stream->Seek(0, SEEK_SET);
|
stream->Seek(0, SEEK_SET);
|
||||||
TranslatorStyledTextStreamHeader header;
|
TranslatorStyledTextStreamHeader header;
|
||||||
stream->Read(&header, sizeof(header));
|
stream->Read(&header, sizeof(header));
|
||||||
swap_data(B_UINT32_TYPE, &header, sizeof(header),
|
swap_data(B_UINT32_TYPE, &header, sizeof(header),
|
||||||
B_SWAP_BENDIAN_TO_HOST);
|
B_SWAP_BENDIAN_TO_HOST);
|
||||||
stream->Seek(0, SEEK_SET);
|
stream->Seek(0, SEEK_SET);
|
||||||
@@ -191,7 +199,7 @@ RTFTranslator::Identify(BPositionIO *stream,
|
|||||||
info->capability = STXT_IN_CAPABILITY;
|
info->capability = STXT_IN_CAPABILITY;
|
||||||
strlcpy(info->name, B_TRANSLATE("Be style text file"),
|
strlcpy(info->name, B_TRANSLATE("Be style text file"),
|
||||||
sizeof(info->name));
|
sizeof(info->name));
|
||||||
strcpy(info->MIME, "text/x-vnd.Be-stxt");
|
strcpy(info->MIME, "text/x-vnd.Be-stxt");
|
||||||
} else {
|
} else {
|
||||||
info->type = B_TRANSLATOR_TEXT;
|
info->type = B_TRANSLATOR_TEXT;
|
||||||
info->group = B_TRANSLATOR_TEXT;
|
info->group = B_TRANSLATOR_TEXT;
|
||||||
@@ -219,7 +227,7 @@ RTFTranslator::Translate(BPositionIO *source,
|
|||||||
if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT
|
if (outType != B_TRANSLATOR_TEXT && outType != B_STYLED_TEXT_FORMAT
|
||||||
&& outType != RTF_TEXT_FORMAT)
|
&& outType != RTF_TEXT_FORMAT)
|
||||||
return B_NO_TRANSLATOR;
|
return B_NO_TRANSLATOR;
|
||||||
|
|
||||||
if (strncmp(inInfo->MIME, "text/rtf", 8) == 0) {
|
if (strncmp(inInfo->MIME, "text/rtf", 8) == 0) {
|
||||||
RTF::Parser parser(*source);
|
RTF::Parser parser(*source);
|
||||||
|
|
||||||
@@ -232,19 +240,19 @@ RTFTranslator::Translate(BPositionIO *source,
|
|||||||
return convert_to_plain_text(header, *target);
|
return convert_to_plain_text(header, *target);
|
||||||
else
|
else
|
||||||
return convert_to_stxt(header, *target);
|
return convert_to_stxt(header, *target);
|
||||||
|
|
||||||
} else if (inInfo->type == B_TRANSLATOR_TEXT) {
|
} else if (inInfo->type == B_TRANSLATOR_TEXT) {
|
||||||
return convert_plain_text_to_rtf(*source, *target);
|
return convert_plain_text_to_rtf(*source, *target);
|
||||||
} else if (inInfo->type == B_STYLED_TEXT_FORMAT) {
|
} else if (inInfo->type == B_STYLED_TEXT_FORMAT) {
|
||||||
return convert_styled_text_to_rtf(source, target);
|
return convert_styled_text_to_rtf(source, target);
|
||||||
} else
|
} else
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
status_t
|
status_t
|
||||||
RTFTranslator::MakeConfigurationView(BMessage *ioExtension, BView **_view,
|
RTFTranslator::MakeConfigurationView(BMessage *ioExtension, BView **_view,
|
||||||
BRect *_extent)
|
BRect *_extent)
|
||||||
{
|
{
|
||||||
if (_view == NULL || _extent == NULL)
|
if (_view == NULL || _extent == NULL)
|
||||||
|
|||||||
Reference in New Issue
Block a user