// CLASS HEADER
#include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
-// INTERNAL INCLUDES
+// EXTERNAL INCLUDES
#include <dali/public-api/object/type-registry.h>
+#include <dali/integration-api/debug.h>
namespace
{
{
case Toolkit::TextLabel::PROPERTY_TEXT:
{
- labelImpl.mText = value.Get< std::string >();
-
- // TODO - Update Model etc.
+ labelImpl.SetText( value.Get< std::string >() );
break;
}
}
if( label )
{
- TextLabel& labelImpl( GetImpl( label ) );
switch( index )
{
case Toolkit::TextLabel::PROPERTY_TEXT:
{
- value = labelImpl.mText;
+ DALI_LOG_WARNING( "UTF-8 text representation was discarded\n" );
break;
}
}
void TextLabel::OnInitialize()
{
+ mController = Text::Controller::New();
+}
+
+void TextLabel::SetText( const std::string& text )
+{
+ if( mController )
+ {
+ // The Controller updates the View for the renderer
+ mController->SetText( text );
+
+ if( mRenderer )
+ {
+ Actor renderableActor = mRenderer->Render( mController->GetView() );
+
+ if( renderableActor )
+ {
+ Self().Add( renderableActor );
+ }
+ }
+ }
}
TextLabel::TextLabel()
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/controls/control-impl.h>
#include <dali-toolkit/public-api/controls/text-controls/text-label.h>
+#include <dali-toolkit/public-api/text/text-controller.h>
namespace Dali
{
private: // Implementation
/**
+ * Helper for SetProperty.
+ * @param[in] text The new "text" property value.
+ */
+ void SetText( const std::string& text );
+
+ /**
* Construct a new TextLabel.
*/
TextLabel();
private: // Data
- // TODO - Use Controller/Model for storage
+ Text::ControllerPtr mController;
Text::RendererPtr mRenderer;
- std::string mText;
};
} // namespace Internal
$(public_api_base_src_dir)/controls/text-controls/text-label.cpp \
$(public_api_base_src_dir)/text/character-set-conversion.cpp \
$(public_api_base_src_dir)/text/logical-model.cpp \
+ $(public_api_base_src_dir)/text/text-controller.cpp \
$(public_api_base_src_dir)/text/text-renderer.cpp \
$(public_api_base_src_dir)/text/text-view.cpp \
$(public_api_base_src_dir)/text/text-view-interface.cpp \
public_api_base_text_header_files = \
$(public_api_base_src_dir)/text/character-set-conversion.h \
$(public_api_base_src_dir)/text/logical-model.h \
+ $(public_api_base_src_dir)/text/text-controller.h \
$(public_api_base_src_dir)/text/text-definitions.h \
$(public_api_base_src_dir)/text/text-renderer.h \
$(public_api_base_src_dir)/text/text-view.h \
*
*/
-// FILE HEATHER
+// FILE HEADER
#include <dali-toolkit/public-api/text/character-set-conversion.h>
namespace Dali
for( ; begin < end ; ++numberOfCharacters )
{
const uint8_t leadByte = *begin;
+
switch( UTF8_LENGTH[leadByte] )
{
- case U1:
- {
- *utf32 = leadByte;
- begin++;
- break;
- }
- case U2:
- {
- uint32_t& code = *utf32;
- code = leadByte & 0x1fu;
- begin++;
- code <<= 6u;
- code |= *begin++ & 0x3fu;
- break;
- }
- case U3:
- {
- uint32_t& code = *utf32;
- code = leadByte & 0x1fu;
- begin++;
- code <<= 6u;
- code |= *begin++ & 0x3fu;
- code <<= 6u;
- code |= *begin++ & 0x3fu;
- break;
- }
- case U4:
- {
- uint32_t& code = *utf32;
- code = leadByte & 0x1fu;
- begin++;
- code <<= 6u;
- code |= *begin++ & 0x3fu;
- code <<= 6u;
- code |= *begin++ & 0x3fu;
- code <<= 6u;
- code |= *begin++ & 0x3fu;
- break;
- }
+ case U1:
+ {
+ *utf32++ = leadByte;
+ begin++;
+ break;
+ }
+
+ case U2:
+ {
+ uint32_t& code = *utf32++;
+ code = leadByte & 0x1fu;
+ begin++;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ break;
+ }
+
+ case U3:
+ {
+ uint32_t& code = *utf32++;
+ code = leadByte & 0x1fu;
+ begin++;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ break;
+ }
+
+ case U4:
+ {
+ uint32_t& code = *utf32++;
+ code = leadByte & 0x1fu;
+ begin++;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ code <<= 6u;
+ code |= *begin++ & 0x3fu;
+ break;
+ }
}
}
LogicalModel::~LogicalModel()
{
+ delete mImpl;
}
LogicalModel::LogicalModel()
--- /dev/null
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include <dali-toolkit/public-api/text/text-controller.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/text/character-set-conversion.h>
+#include <dali-toolkit/public-api/text/logical-model.h>
+#include <dali-toolkit/public-api/text/text-view.h>
+#include <dali-toolkit/public-api/text/visual-model.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Text
+{
+
+struct Controller::Impl
+{
+ Impl()
+ {
+ mLogicalModel = LogicalModel::New();
+ mVisualModel = VisualModel::New();
+
+ mView.SetVisualModel( mVisualModel );
+
+ mFontClient = TextAbstraction::FontClient::Get();
+ }
+
+ LogicalModelPtr mLogicalModel;
+ VisualModelPtr mVisualModel;
+
+ View mView;
+
+ TextAbstraction::FontClient mFontClient;
+};
+
+ControllerPtr Controller::New()
+{
+ return ControllerPtr( new Controller() );
+}
+
+void Controller::SetText( const std::string& text )
+{
+ // Convert text into UTF-32
+ Vector<Character> utf32Characters;
+ utf32Characters.Resize( text.size() );
+
+ // This is a bit horrible but std::string returns a (signed) char*
+ const uint8_t* utf8 = reinterpret_cast<const uint8_t*>( text.c_str() );
+
+ Length characterCount = Utf8ToUtf32( utf8, text.size(), &utf32Characters[0] );
+
+ // Manipulate the logical model
+ mImpl->mLogicalModel->SetText( &utf32Characters[0], characterCount );
+
+ UpdateVisualModel();
+}
+
+View& Controller::GetView()
+{
+ return mImpl->mView;
+}
+
+Controller::~Controller()
+{
+ delete mImpl;
+}
+
+Controller::Controller()
+: mImpl( NULL )
+{
+ mImpl = new Controller::Impl();
+}
+
+// TODO - Move this with LayoutEngine
+void Controller::UpdateVisualModel()
+{
+ if( mImpl->mLogicalModel &&
+ mImpl->mVisualModel )
+ {
+ const LogicalModel& logicalModel = *(mImpl->mLogicalModel);
+ VisualModel& visualModel = *(mImpl->mVisualModel);
+
+ TextAbstraction::FontId fontId = mImpl->mFontClient.GetFontId( "/usr/share/fonts/truetype/ubuntu-font-family/UbuntuMono-R.ttf", 13*64 );
+
+ const Length characterCount = logicalModel.GetNumberOfCharacters();
+
+ Vector<GlyphInfo> glyphs;
+ glyphs.Reserve( characterCount );
+
+ Vector<CharacterIndex> characterIndices;
+ characterIndices.Reserve( characterCount );
+
+ std::vector<Length> charactersPerGlyph;
+ charactersPerGlyph.assign( characterCount, 1 );
+
+ for( unsigned int i=0; i<characterCount; ++i )
+ {
+ Character charcode;
+ logicalModel.GetText( i, &charcode, 1 );
+
+ // TODO - Perform shaping to get correct glyph indices
+ GlyphIndex glyphIndex = mImpl->mFontClient.GetGlyphIndex( fontId, charcode );
+
+ glyphs.PushBack( GlyphInfo(fontId, glyphIndex) );
+ characterIndices.PushBack( 1 );
+ }
+
+ if( mImpl->mFontClient.GetGlyphMetrics( &glyphs[0], glyphs.Size() ) )
+ {
+ visualModel.SetGlyphs( &glyphs[0],
+ &characterIndices[0],
+ &charactersPerGlyph[0],
+ characterCount );
+
+ UpdateVisualPositions();
+ }
+ }
+}
+
+// TODO - Move this with LayoutEngine
+void Controller::UpdateVisualPositions()
+{
+ if( mImpl->mVisualModel )
+ {
+ VisualModel& visualModel = *(mImpl->mVisualModel);
+
+ Length glyphCount = visualModel.GetNumberOfGlyphs();
+
+ std::vector<Vector2> glyphPositions;
+ glyphPositions.reserve( glyphCount );
+
+ if( glyphCount > 0 )
+ {
+ // FIXME Single font assumption
+ Text::FontMetrics fontMetrics;
+ GlyphInfo firstGlyph;
+ visualModel.GetGlyphs( 0, &firstGlyph, 1 );
+ mImpl->mFontClient.GetFontMetrics( firstGlyph.fontId, fontMetrics );
+
+ int penX( 0 );
+ int penY( fontMetrics.ascender ); // Move to baseline
+
+ for( unsigned int i=0; i<glyphCount; ++i )
+ {
+ GlyphInfo glyph;
+ visualModel.GetGlyphs( i, &glyph, 1 );
+
+ if( glyph.width > 0 &&
+ glyph.height > 0 ) // Skip whitespace
+ {
+ glyphPositions.push_back( Vector2( penX + glyph.xBearing,
+ penY - glyph.yBearing ) );
+ }
+
+ penX += glyph.advance;
+ }
+
+ visualModel.SetGlyphPositions( &glyphPositions[0], glyphCount );
+ }
+ }
+}
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
--- /dev/null
+#ifndef __DALI_TOOLKIT_TEXT_CONTROLLER_H__
+#define __DALI_TOOLKIT_TEXT_CONTROLLER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/common/intrusive-ptr.h>
+#include <dali/public-api/object/ref-object.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/public-api/text/text-view.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Text
+{
+
+class Controller;
+typedef IntrusivePtr<Controller> ControllerPtr;
+
+/**
+ * @brief A Text Controller is used by UI Controls which display text.
+ *
+ * It manipulates the Logical & Visual text models on behalf of the UI Controls.
+ * It provides a view of the text that can be used by rendering back-ends.
+ */
+class Controller : public RefObject
+{
+public:
+
+ /**
+ * @brief Create a new instance of a Controller.
+ *
+ * @return A pointer to a new Controller.
+ */
+ static ControllerPtr New();
+
+ // TODO - Layouting options e.g. single vs multi-line
+
+ /**
+ * @brief Replaces any text previously set.
+ *
+ * @note This will be converted into UTF-32 when stored in the text model.
+ * @param[in] text A string of UTF-8 characters.
+ */
+ void SetText( const std::string& text );
+
+ /**
+ * @brief Return a view of the text.
+ *
+ * @return An interface to the view.
+ */
+ View& GetView();
+
+protected:
+
+ /**
+ * @brief A reference counted object may only be deleted by calling Unreference().
+ */
+ virtual ~Controller();
+
+private:
+
+ /**
+ * @brief Private constructor.
+ */
+ Controller();
+
+ /**
+ * TODO - Move these with LayoutEngine
+ */
+ void UpdateVisualModel();
+ void UpdateVisualPositions();
+
+ // Undefined
+ Controller( const Controller& handle );
+
+ // Undefined
+ Controller& operator=( const Controller& handle );
+
+private:
+
+ struct Impl;
+ Impl* mImpl;
+};
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // __DALI_TOOLKIT_TEXT_CONTROLLER_H__
{
typedef TextAbstraction::FontId FontId; ///< The unique identifier for a font face (generated by FontClient)
+typedef TextAbstraction::FontMetrics FontMetrics; ///< The metrics for a Font expressed in 26.6 fractional pixel format
typedef TextAbstraction::PointSize26Dot6 PointSize26Dot6; ///< The point size in 26.6 fractional points
typedef TextAbstraction::FaceIndex FaceIndex; ///< Used with fonts which allow several font faces
typedef TextAbstraction::GlyphIndex GlyphIndex; ///< Uniquely identifies a glyph within a particular font
VisualModelPtr mVisualModel;
};
-ViewPtr View::New()
+View::View()
+: mImpl( NULL )
{
- return ViewPtr( new View() );
+ mImpl = new View::Impl();
+}
+
+View::~View()
+{
+ delete mImpl;
}
void View::SetVisualModel( VisualModelPtr visualModel )
}
}
-View::~View()
-{
-}
-
-View::View()
-: mImpl( NULL )
-{
- mImpl = new View::Impl();
-}
-
} // namespace Text
} // namespace Toolkit
*
*/
-// EXTERNAL INCLUDES
-#include <dali/public-api/common/intrusive-ptr.h>
-#include <dali/public-api/object/ref-object.h>
-
// INTERNAL INCLUDES
#include <dali-toolkit/public-api/text/text-view-interface.h>
#include <dali-toolkit/public-api/text/visual-model.h>
namespace Text
{
-class View;
-typedef IntrusivePtr<View> ViewPtr;
-
/**
* @brief View provides an interface between the Text layout engine and rendering back-end.
*/
-class View : public RefObject, public ViewInterface
+class View : public ViewInterface
{
public:
/**
* @brief Create a new instance of a View.
- *
- * @return A pointer to a new View.
*/
- static ViewPtr New();
+ View();
+
+ /**
+ * @brief Virtual destructor.
+ */
+ virtual ~View();
/**
* @brief Set the visual model.
Vector2* glyphPositions,
Length numberOfGlyphs ) const;
-protected:
-
- /**
- * @brief A reference counted object may only be deleted by calling Unreference().
- */
- virtual ~View();
-
private:
- /**
- * @brief Private constructor.
- */
- View();
-
// Undefined
View( const View& handle );
VisualModel::~VisualModel()
{
+ delete mImpl;
}
VisualModel::VisualModel()
#include <dali-toolkit/public-api/shader-effects/swirl-effect.h>
#include <dali-toolkit/public-api/text/character-set-conversion.h>
#include <dali-toolkit/public-api/text/logical-model.h>
+#include <dali-toolkit/public-api/text/text-controller.h>
#include <dali-toolkit/public-api/text/text-definitions.h>
#include <dali-toolkit/public-api/text/text-renderer.h>
#include <dali-toolkit/public-api/text/text-view.h>