From ebf4610ff0f2a8f6d3bd7418c6e340e0efcc55e3 Mon Sep 17 00:00:00 2001 From: shatty Date: Sun, 6 Jul 2003 08:59:20 +0000 Subject: [PATCH] broken but halfway working input conversion git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3867 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/stylededit/StyledEditView.cpp | 30 ++++++++++++++++++++++++++ src/apps/stylededit/StyledEditView.h | 2 +- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/src/apps/stylededit/StyledEditView.cpp b/src/apps/stylededit/StyledEditView.cpp index b075382144..5c476958d6 100644 --- a/src/apps/stylededit/StyledEditView.cpp +++ b/src/apps/stylededit/StyledEditView.cpp @@ -105,6 +105,36 @@ StyledEditView::GetStyledText(BPositionIO * stream) SetTextRect(textRect); } } + if (fEncoding != 0) { + CharacterSetRoster * roster = CharacterSetRoster::Roster(&result); + if (result == B_OK) { + uint32 id = roster->FindCharacterSetByFontID(fEncoding)->GetConversionID(); + SetText(""); + char inBuffer[256]; + off_t location = 0; + int32 textOffset = 0; + int32 state = 0; + int32 bytesRead; + while ((bytesRead = stream->ReadAt(location,inBuffer,256)) > 0) { + location += bytesRead; + char * inPtr = inBuffer; + char textBuffer[256]; + int32 textLength = 256; + int32 bytesConverted = bytesRead; + while (textLength > 0) { + convert_to_utf8(id,inPtr,&bytesConverted,textBuffer,&textLength,&state); + InsertText(textBuffer,textLength,textOffset); + textOffset += textLength; + inPtr += bytesConverted; + bytesRead -= bytesConverted; + bytesConverted = bytesRead; + if (textLength > 0) { + textLength = 256; + } + } + } + } + } fSuppressChanges = false; return result; } diff --git a/src/apps/stylededit/StyledEditView.h b/src/apps/stylededit/StyledEditView.h index b9efb73ab1..48e947ea12 100644 --- a/src/apps/stylededit/StyledEditView.h +++ b/src/apps/stylededit/StyledEditView.h @@ -20,7 +20,7 @@ public: virtual void SetEncoding(uint32 encoding); virtual uint32 GetEncoding() const; protected: - virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs); + virtual void InsertText(const char *text, int32 length, int32 offset, const text_run_array *runs = NULL); virtual void DeleteText(int32 start, int32 finish); private: