Added another GetStyledText() function to force a specific encoding.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19847 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-01-17 12:04:02 +00:00
parent 691e54b4ab
commit 849de6ef97
2 changed files with 32 additions and 46 deletions
+18 -5
View File
@@ -312,19 +312,20 @@ BTranslationUtils::GetBitmap(BPositionIO *stream, BTranslatorRoster *roster)
defined in
/boot/develop/headers/be/translation/TranslatorFormats.h
\param fromStream the stream with the styled text
\param source the stream with the styled text
\param intoView the view where the test will be inserted
roster, BTranslatorRoster used to do the translation
\param the encoding to use, defaults to UTF-8
\return B_BAD_VALUE, if fromStream or intoView is NULL
\return B_ERROR, if any other error occurred
\return B_OK, if successful
*/
status_t
BTranslationUtils::GetStyledText(BPositionIO *fromStream, BTextView *intoView,
BTranslatorRoster *roster)
BTranslationUtils::GetStyledText(BPositionIO* source, BTextView* intoView,
const char* encoding, BTranslatorRoster* roster)
{
if (fromStream == NULL || intoView == NULL)
if (source == NULL || intoView == NULL)
return B_BAD_VALUE;
// Use default Translator if none is specified
@@ -334,10 +335,14 @@ BTranslationUtils::GetStyledText(BPositionIO *fromStream, BTextView *intoView,
return B_ERROR;
}
BMessage config;
if (encoding != NULL && encoding[0])
config.AddString("be:encoding", encoding);
// Translate the file from whatever format it is to B_STYLED_TEXT_FORMAT
// we understand
BMallocIO mallocIO;
if (roster->Translate(fromStream, NULL, NULL, &mallocIO,
if (roster->Translate(source, NULL, &config, &mallocIO,
B_STYLED_TEXT_FORMAT) < B_OK)
return B_BAD_TYPE;
@@ -429,6 +434,14 @@ BTranslationUtils::GetStyledText(BPositionIO *fromStream, BTextView *intoView,
}
status_t
BTranslationUtils::GetStyledText(BPositionIO* source, BTextView* intoView,
BTranslatorRoster* roster)
{
return GetStyledText(source, intoView, NULL, roster);
}
/*!
This function takes styled text data from fromView and writes it to
intoStream. The plain text data and styled text data are combined