Add the font width, weight and slant to the font style. 09/46709/9
authorv.cebollada <v.cebollada@samsung.com>
Tue, 25 Aug 2015 00:48:53 +0000 (09:48 +0900)
committerVictor Cebollada <v.cebollada@samsung.com>
Thu, 3 Sep 2015 09:25:49 +0000 (10:25 +0100)
Change-Id: Ia77419df7309d5948f5e69af56c5664dbf5bfe6d
Signed-off-by: v.cebollada <v.cebollada@samsung.com>
18 files changed:
dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
dali-toolkit/internal/controls/text-controls/text-font-style.cpp [new file with mode: 0644]
dali-toolkit/internal/controls/text-controls/text-font-style.h [new file with mode: 0644]
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/file.list
dali-toolkit/internal/text/text-controller-impl.cpp
dali-toolkit/internal/text/text-controller-impl.h
dali-toolkit/internal/text/text-controller.cpp
dali-toolkit/internal/text/text-controller.h
dali-toolkit/internal/text/text-definitions.h
dali-toolkit/internal/text/text-io.cpp
dali-toolkit/public-api/controls/text-controls/text-field.h
dali-toolkit/public-api/controls/text-controls/text-label.h
dali-toolkit/styles/480x800/dali-toolkit-default-theme.json
dali-toolkit/styles/720x1280/dali-toolkit-default-theme.json
docs/content/shared-javascript-and-cpp-documentation/font-selection.md [new file with mode: 0644]
docs/content/shared-javascript-and-cpp-documentation/text-field.md
docs/content/shared-javascript-and-cpp-documentation/text-label.md

index eb12543..5e69586 100644 (file)
 #include <dali-toolkit/internal/controls/text-controls/text-field-impl.h>
 
 // EXTERNAL INCLUDES
-#include <string>
-#include <iostream>
 #include <cstring>
 #include <dali/public-api/adaptor-framework/key.h>
 #include <dali/public-api/common/stage.h>
 #include <dali/public-api/images/resource-image.h>
-#include <dali/public-api/object/type-registry.h>
-#include <dali/devel-api/object/type-registry-helper.h>
-#include <dali/devel-api/scripting/scripting.h>
 #include <dali/devel-api/adaptor-framework/virtual-keyboard.h>
+#include <dali/devel-api/object/type-registry-helper.h>
 #include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/text/rendering-backend.h>
-#include <dali-toolkit/internal/text/layouts/layout-engine.h>
+#include <dali-toolkit/internal/controls/text-controls/text-font-style.h>
 #include <dali-toolkit/internal/text/rendering/text-backend.h>
 #include <dali-toolkit/internal/text/text-view.h>
 #include <dali-toolkit/internal/styling/style-manager-impl.h>
@@ -57,7 +53,6 @@ namespace // unnamed namespace
 #endif
 
   const unsigned int DEFAULT_RENDERING_BACKEND = Dali::Toolkit::Text::DEFAULT_RENDERING_BACKEND;
-
 } // unnamed namespace
 
 namespace
@@ -220,16 +215,7 @@ void TextField::SetProperty( BaseObject* object, Property::Index index, const Pr
       }
       case Toolkit::TextField::Property::FONT_STYLE:
       {
-        if( impl.mController )
-        {
-          const std::string fontStyle = value.Get< std::string >();
-          DALI_LOG_INFO( gLogFilter, Debug::General, "TextField %p FONT_STYLE %s\n", impl.mController.Get(), fontStyle.c_str() );
-
-          if( impl.mController->GetDefaultFontStyle() != fontStyle )
-          {
-            impl.mController->SetDefaultFontStyle( fontStyle );
-          }
-        }
+        SetFontStyleProperty( impl.mController, value );
         break;
       }
       case Toolkit::TextField::Property::POINT_SIZE:
@@ -630,10 +616,7 @@ Property::Value TextField::GetProperty( BaseObject* object, Property::Index inde
       }
       case Toolkit::TextField::Property::FONT_STYLE:
       {
-        if( impl.mController )
-        {
-          value = impl.mController->GetDefaultFontStyle();
-        }
+        GetFontStyleProperty( impl.mController, value );
         break;
       }
       case Toolkit::TextField::Property::POINT_SIZE:
diff --git a/dali-toolkit/internal/controls/text-controls/text-font-style.cpp b/dali-toolkit/internal/controls/text-controls/text-font-style.cpp
new file mode 100644 (file)
index 0000000..2c29f68
--- /dev/null
@@ -0,0 +1,202 @@
+/*
+ * 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.
+ *
+ */
+
+// FILE HEADER
+#include <dali-toolkit/internal/controls/text-controls/text-font-style.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/devel-api/builder/json-parser.h>
+#include <dali-toolkit/devel-api/builder/tree-node.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Text
+{
+
+namespace
+{
+const std::string STYLE_KEY( "style" );
+const std::string WIDTH_KEY( "width" );
+const std::string WEIGHT_KEY( "weight" );
+const std::string SLANT_KEY( "slant" );
+const std::string EMPTY_STRING( "" );
+
+} // namespace
+
+/**
+ * @brief Creates a map with pairs 'key,value' with the font's style parameters.
+ *
+ * @param[in] node Data structure with the font's style parameters.
+ * @param[out] map A map with the font's style parameters.
+ *
+ */
+void CreateFontStyleMap( const TreeNode* const node, Property::Map& map )
+{
+  switch( node->GetType() )
+  {
+    case TreeNode::IS_NULL:
+    case TreeNode::OBJECT:
+    case TreeNode::ARRAY: // FALL THROUGH
+    {
+      break;
+    }
+    case TreeNode::STRING:
+    {
+      map.Insert( node->GetName(), Property::Value( node->GetString() ) );
+      break;
+    }
+    case TreeNode::INTEGER:
+    case TreeNode::FLOAT:
+    case TreeNode::BOOLEAN: // FALL THROUGH
+    {
+      break;
+    }
+  }
+
+  for( TreeNode::ConstIterator it = node->CBegin(), endIt = node->CEnd(); it != endIt; ++it )
+  {
+    const TreeNode::KeyNodePair& pair = *it;
+    CreateFontStyleMap( &pair.second, map );
+  }
+}
+
+/**
+ * @brief Parses the font's style string.
+ *
+ * @param[in] style The font's style string.
+ * @param[out] map A map with the font's style parameters.
+ *
+ */
+void ParseFontStyleString( const std::string& style, Property::Map& map )
+{
+  Toolkit::JsonParser parser = Toolkit::JsonParser::New();
+
+  if( parser.Parse( style ) )
+  {
+    const TreeNode* const node = parser.GetRoot();
+
+    CreateFontStyleMap( node, map );
+  }
+}
+
+void SetFontStyleProperty( ControllerPtr controller, const Property::Value& value )
+{
+  if( controller )
+  {
+    const std::string style = value.Get< std::string >();
+
+    // Stores the string to be recovered by the GetFontStyleProperty() function.
+    controller->SetDefaultFontStyle( style );
+
+    // Parses and applies the style.
+    Property::Map map;
+    ParseFontStyleString( style, map );
+
+    if( !map.Empty() )
+    {
+      /// Width key
+      Property::Value* widthValue = map.Find( WIDTH_KEY );
+
+      if( widthValue )
+      {
+        const std::string widthStr = widthValue->Get<std::string>();
+
+        FontWidth width = TextAbstraction::FontWidth::NORMAL;
+        if( Scripting::GetEnumeration< FontWidth >( widthStr.c_str(),
+                                                    FONT_WIDTH_STRING_TABLE,
+                                                    FONT_WIDTH_STRING_TABLE_COUNT,
+                                                    width ) )
+        {
+          if( controller->GetDefaultFontWidth() != width )
+          {
+            controller->SetDefaultFontWidth( width );
+          }
+        }
+      }
+      else
+      {
+        controller->SetDefaultFontWidth( TextAbstraction::FontWidth::NORMAL );
+      }
+
+      /// Weight key
+      Property::Value* weightValue = map.Find( WEIGHT_KEY );
+
+      if( weightValue )
+      {
+        const std::string weightStr = weightValue->Get<std::string>();
+
+        FontWeight weight = TextAbstraction::FontWeight::NORMAL;
+        if( Scripting::GetEnumeration< FontWeight >( weightStr.c_str(),
+                                                     FONT_WEIGHT_STRING_TABLE,
+                                                     FONT_WEIGHT_STRING_TABLE_COUNT,
+                                                     weight ) )
+        {
+          if( controller->GetDefaultFontWeight() != weight )
+          {
+            controller->SetDefaultFontWeight( weight );
+          }
+        }
+      }
+      else
+      {
+        controller->SetDefaultFontWeight( TextAbstraction::FontWeight::NORMAL );
+      }
+
+      /// Slant key
+      Property::Value* slantValue = map.Find( SLANT_KEY );
+
+      if( slantValue )
+      {
+        const std::string slantStr = slantValue->Get<std::string>();
+
+        FontSlant slant = TextAbstraction::FontSlant::NORMAL;
+        if( Scripting::GetEnumeration< FontSlant >( slantStr.c_str(),
+                                                    FONT_SLANT_STRING_TABLE,
+                                                    FONT_SLANT_STRING_TABLE_COUNT,
+                                                    slant ) )
+        {
+          if( controller->GetDefaultFontSlant() != slant )
+          {
+            controller->SetDefaultFontSlant( slant );
+          }
+        }
+      }
+      else
+      {
+        controller->SetDefaultFontSlant( TextAbstraction::FontSlant::NORMAL );
+      }
+    }
+  }
+}
+
+void GetFontStyleProperty( ControllerPtr controller, Property::Value& value )
+{
+  if( controller )
+  {
+    value = controller->GetDefaultFontStyle();
+  }
+}
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
diff --git a/dali-toolkit/internal/controls/text-controls/text-font-style.h b/dali-toolkit/internal/controls/text-controls/text-font-style.h
new file mode 100644 (file)
index 0000000..35696af
--- /dev/null
@@ -0,0 +1,106 @@
+#ifndef __DALI_TOOLKIT_INTERNAL_TEXT_FONT_STYLE_H__
+#define __DALI_TOOLKIT_INTERNAL_TEXT_FONT_STYLE_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/devel-api/scripting/scripting.h>
+
+// INTERNAL INCLUDES
+#include <dali-toolkit/internal/text/text-controller.h>
+#include <dali-toolkit/internal/text/text-definitions.h>
+
+namespace Dali
+{
+
+namespace Toolkit
+{
+
+namespace Text
+{
+
+const Scripting::StringEnum FONT_WIDTH_STRING_TABLE[] =
+{
+  { "ultra-condensed", TextAbstraction::FontWidth::ULTRA_CONDENSED },
+  { "extra-condensed", TextAbstraction::FontWidth::EXTRA_CONDENSED },
+  { "condensed", TextAbstraction::FontWidth::CONDENSED },
+  { "semi-condensed", TextAbstraction::FontWidth::SEMI_CONDENSED },
+  { "normal", TextAbstraction::FontWidth::NORMAL },
+  { "semi-expanded", TextAbstraction::FontWidth::SEMI_EXPANDED },
+  { "expanded", TextAbstraction::FontWidth::EXPANDED },
+  { "extra-expanded", TextAbstraction::FontWidth::EXTRA_EXPANDED },
+  { "ultra-expanded", TextAbstraction::FontWidth::ULTRA_EXPANDED },
+};
+const unsigned int FONT_WIDTH_STRING_TABLE_COUNT = sizeof( FONT_WIDTH_STRING_TABLE ) / sizeof( FONT_WIDTH_STRING_TABLE[0] );
+
+const Scripting::StringEnum FONT_WEIGHT_STRING_TABLE[] =
+{
+  { "thin", TextAbstraction::FontWeight::THIN },
+  { "ultra-light", TextAbstraction::FontWeight::ULTRA_LIGHT },
+  { "extra-light", TextAbstraction::FontWeight::EXTRA_LIGHT },
+  { "light", TextAbstraction::FontWeight::LIGHT },
+  { "demi-light", TextAbstraction::FontWeight::DEMI_LIGHT },
+  { "semi-light", TextAbstraction::FontWeight::SEMI_LIGHT },
+  { "book", TextAbstraction::FontWeight::BOOK },
+  { "normal", TextAbstraction::FontWeight::NORMAL },
+  { "regular", TextAbstraction::FontWeight::REGULAR },
+  { "medium", TextAbstraction::FontWeight::MEDIUM },
+  { "demi-bold", TextAbstraction::FontWeight::DEMI_BOLD },
+  { "semi-bold", TextAbstraction::FontWeight::SEMI_BOLD },
+  { "bold", TextAbstraction::FontWeight::BOLD },
+  { "ultra-bold", TextAbstraction::FontWeight::ULTRA_BOLD },
+  { "extra-bold", TextAbstraction::FontWeight::EXTRA_BOLD },
+  { "black", TextAbstraction::FontWeight::BLACK },
+  { "heavy", TextAbstraction::FontWeight::HEAVY },
+  { "extra-black", TextAbstraction::FontWeight::EXTRA_BLACK }
+};
+const unsigned int FONT_WEIGHT_STRING_TABLE_COUNT = sizeof( FONT_WEIGHT_STRING_TABLE ) / sizeof( FONT_WEIGHT_STRING_TABLE[0] );
+
+const Scripting::StringEnum FONT_SLANT_STRING_TABLE[] =
+{
+  { "normal", TextAbstraction::FontSlant::NORMAL },
+  { "roman", TextAbstraction::FontSlant::ROMAN },
+  { "italic", TextAbstraction::FontSlant::ITALIC },
+  { "oblique", TextAbstraction::FontSlant::OBLIQUE }
+};
+const unsigned int FONT_SLANT_STRING_TABLE_COUNT = sizeof( FONT_SLANT_STRING_TABLE ) / sizeof( FONT_SLANT_STRING_TABLE[0] );
+
+/**
+ * @brief Sets the font's style property.
+ *
+ * @param[in] controller The text's controller.
+ * @param[in] value The value of the font's style.
+ *
+ */
+void SetFontStyleProperty( ControllerPtr controller, const Property::Value& value );
+
+/**
+ * @brief Retrieves the font's style property.
+ *
+ * @param[in] controller The text's controller.
+ * @param[out] value The value of the font's style.
+ */
+void GetFontStyleProperty( ControllerPtr controller, Property::Value& value );
+
+} // namespace Text
+
+} // namespace Toolkit
+
+} // namespace Dali
+
+#endif // __DALI_TOOLKIT_INTERNAL_TEXT_FONT_STYLE_H__
index ce08f89..0857852 100644 (file)
 #include <dali-toolkit/internal/controls/text-controls/text-label-impl.h>
 
 // EXTERNAL INCLUDES
-#include <dali/public-api/object/type-registry.h>
 #include <dali/devel-api/object/type-registry-helper.h>
-#include <dali/devel-api/scripting/scripting.h>
 #include <dali/integration-api/debug.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/text/rendering-backend.h>
-#include <dali-toolkit/internal/text/layouts/layout-engine.h>
+#include <dali-toolkit/internal/controls/text-controls/text-font-style.h>
 #include <dali-toolkit/internal/text/rendering/text-backend.h>
 #include <dali-toolkit/internal/text/text-view.h>
 #include <dali-toolkit/internal/styling/style-manager-impl.h>
@@ -158,15 +156,7 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr
       }
       case Toolkit::TextLabel::Property::FONT_STYLE:
       {
-        if( impl.mController )
-        {
-          const std::string fontStyle = value.Get< std::string >();
-
-          if( impl.mController->GetDefaultFontStyle() != fontStyle )
-          {
-            impl.mController->SetDefaultFontStyle( fontStyle );
-          }
-        }
+        SetFontStyleProperty( impl.mController, value );
         break;
       }
       case Toolkit::TextLabel::Property::POINT_SIZE:
@@ -341,10 +331,7 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde
       }
       case Toolkit::TextLabel::Property::FONT_STYLE:
       {
-        if( impl.mController )
-        {
-          value = impl.mController->GetDefaultFontStyle();
-        }
+        GetFontStyleProperty( impl.mController, value );
         break;
       }
       case Toolkit::TextLabel::Property::POINT_SIZE:
index 0b71ff8..0b0517c 100644 (file)
@@ -49,6 +49,7 @@ toolkit_src_files = \
    $(toolkit_src_dir)/controls/super-blur-view/super-blur-view-impl.cpp \
    $(toolkit_src_dir)/controls/table-view/table-view-impl.cpp \
    $(toolkit_src_dir)/controls/text-controls/text-field-impl.cpp \
+   $(toolkit_src_dir)/controls/text-controls/text-font-style.cpp \
    $(toolkit_src_dir)/controls/text-controls/text-label-impl.cpp \
    $(toolkit_src_dir)/controls/text-controls/text-selection-popup-impl.cpp \
    $(toolkit_src_dir)/controls/text-controls/text-selection-toolbar-impl.cpp \
index 55b5893..5ae3d7f 100644 (file)
@@ -58,8 +58,6 @@ struct GlyphMetrics
   float xBearing;   ///< The x bearing of the first glyph.
 };
 
-const std::string EMPTY_STRING("");
-
 } // namespace
 
 namespace Dali
@@ -478,8 +476,8 @@ float Controller::Impl::GetDefaultFontLineHeight()
   FontId defaultFontId = 0u;
   if( NULL == mFontDefaults )
   {
-    defaultFontId = mFontClient.GetFontId( EMPTY_STRING,
-                                           EMPTY_STRING );
+    TextAbstraction::FontDescription fontDescription;
+    defaultFontId = mFontClient.GetFontId( fontDescription );
   }
   else
   {
@@ -1768,8 +1766,8 @@ void Controller::Impl::UpdateCursorPosition()
     FontId defaultFontId = 0u;
     if( NULL == mFontDefaults )
     {
-      defaultFontId = mFontClient.GetFontId( EMPTY_STRING,
-                                             EMPTY_STRING );
+      TextAbstraction::FontDescription fontDescription;
+      defaultFontId = mFontClient.GetFontId( fontDescription );
     }
     else
     {
index e60fe37..65fce8e 100644 (file)
@@ -175,8 +175,8 @@ struct ModifyEvent
 struct FontDefaults
 {
   FontDefaults()
-  : mDefaultFontFamily(""),
-    mDefaultFontStyle(""),
+  : mFontDescription(),
+    mFontStyle(),
     mDefaultPointSize(0.0f),
     mFontId(0u)
   {
@@ -187,14 +187,14 @@ struct FontDefaults
     if( !mFontId )
     {
       Dali::TextAbstraction::PointSize26Dot6 pointSize = mDefaultPointSize*64;
-      mFontId = fontClient.GetFontId( mDefaultFontFamily, mDefaultFontStyle, pointSize );
+      mFontId = fontClient.GetFontId( mFontDescription, pointSize );
     }
 
     return mFontId;
   }
 
-  std::string mDefaultFontFamily;
-  std::string mDefaultFontStyle;
+  TextAbstraction::FontDescription mFontDescription;
+  std::string mFontStyle;
   float mDefaultPointSize;
   FontId mFontId;
 };
@@ -218,7 +218,7 @@ struct Controller::Impl
     mOperationsPending( NO_OPERATION ),
     mMaximumNumberOfCharacters( 50 ),
     mRecalculateNaturalSize( true ),
-    mUserDefinedFontFamily( false)
+    mUserDefinedFontFamily( false )
   {
     mLogicalModel = LogicalModel::New();
     mVisualModel  = VisualModel::New();
@@ -488,7 +488,7 @@ struct Controller::Impl
   Length mMaximumNumberOfCharacters;       ///< Maximum number of characters that can be inserted.
 
   bool mRecalculateNaturalSize:1;          ///< Whether the natural size needs to be recalculated.
-  bool mUserDefinedFontFamily:1;           ///< Whether the Font family was Set by the user instead of being left as sytem default
+  bool mUserDefinedFontFamily:1;           ///< Whether the Font family was set by the user instead of being left as sytem default.
 };
 
 } // namespace Text
index 47afc96..822a62f 100644 (file)
@@ -41,6 +41,7 @@ const float MAX_FLOAT = std::numeric_limits<float>::max();
 const unsigned int POINTS_PER_INCH = 72;
 
 const std::string EMPTY_STRING("");
+const unsigned int ZERO = 0u;
 
 float ConvertToEven( float value )
 {
@@ -232,8 +233,9 @@ void Controller::SetDefaultFontFamily( const std::string& defaultFontFamily, boo
     mImpl->mFontDefaults = new FontDefaults();
   }
 
-  mImpl->mFontDefaults->mDefaultFontFamily = defaultFontFamily;
+  mImpl->mFontDefaults->mFontDescription.family = defaultFontFamily;
   mImpl->mUserDefinedFontFamily = userDefined;
+
   // Clear the font-specific data
   ClearFontData();
 
@@ -247,20 +249,40 @@ const std::string& Controller::GetDefaultFontFamily() const
 {
   if( mImpl->mFontDefaults )
   {
-    return mImpl->mFontDefaults->mDefaultFontFamily;
+    return mImpl->mFontDefaults->mFontDescription.family;
   }
 
   return EMPTY_STRING;
 }
 
-void Controller::SetDefaultFontStyle( const std::string& defaultFontStyle )
+void Controller::SetDefaultFontStyle( const std::string& style )
 {
   if( !mImpl->mFontDefaults )
   {
     mImpl->mFontDefaults = new FontDefaults();
   }
 
-  mImpl->mFontDefaults->mDefaultFontStyle = defaultFontStyle;
+  mImpl->mFontDefaults->mFontStyle = style;
+}
+
+const std::string& Controller::GetDefaultFontStyle() const
+{
+  if( mImpl->mFontDefaults )
+  {
+    return mImpl->mFontDefaults->mFontStyle;
+  }
+
+  return EMPTY_STRING;
+}
+
+void Controller::SetDefaultFontWidth( FontWidth width )
+{
+  if( !mImpl->mFontDefaults )
+  {
+    mImpl->mFontDefaults = new FontDefaults();
+  }
+
+  mImpl->mFontDefaults->mFontDescription.width = width;
 
   // Clear the font-specific data
   ClearFontData();
@@ -271,14 +293,70 @@ void Controller::SetDefaultFontStyle( const std::string& defaultFontStyle )
   mImpl->RequestRelayout();
 }
 
-const std::string& Controller::GetDefaultFontStyle() const
+FontWidth Controller::GetDefaultFontWidth() const
 {
   if( mImpl->mFontDefaults )
   {
-    return mImpl->mFontDefaults->mDefaultFontStyle;
+    return mImpl->mFontDefaults->mFontDescription.width;
   }
 
-  return EMPTY_STRING;
+  return TextAbstraction::FontWidth::NORMAL;
+}
+
+void Controller::SetDefaultFontWeight( FontWeight weight )
+{
+  if( !mImpl->mFontDefaults )
+  {
+    mImpl->mFontDefaults = new FontDefaults();
+  }
+
+  mImpl->mFontDefaults->mFontDescription.weight = weight;
+
+  // Clear the font-specific data
+  ClearFontData();
+
+  mImpl->mOperationsPending = ALL_OPERATIONS;
+  mImpl->mRecalculateNaturalSize = true;
+
+  mImpl->RequestRelayout();
+}
+
+FontWeight Controller::GetDefaultFontWeight() const
+{
+  if( mImpl->mFontDefaults )
+  {
+    return mImpl->mFontDefaults->mFontDescription.weight;
+  }
+
+  return TextAbstraction::FontWeight::NORMAL;
+}
+
+void Controller::SetDefaultFontSlant( FontSlant slant )
+{
+  if( !mImpl->mFontDefaults )
+  {
+    mImpl->mFontDefaults = new FontDefaults();
+  }
+
+  mImpl->mFontDefaults->mFontDescription.slant = slant;
+
+  // Clear the font-specific data
+  ClearFontData();
+
+  mImpl->mOperationsPending = ALL_OPERATIONS;
+  mImpl->mRecalculateNaturalSize = true;
+
+  mImpl->RequestRelayout();
+}
+
+FontSlant Controller::GetDefaultFontSlant() const
+{
+  if( mImpl->mFontDefaults )
+  {
+    return mImpl->mFontDefaults->mFontDescription.slant;
+  }
+
+  return TextAbstraction::FontSlant::NORMAL;
 }
 
 void Controller::SetDefaultPointSize( float pointSize )
@@ -327,7 +405,7 @@ void Controller::UpdateAfterFontChange( std::string& newDefaultFont )
   if ( !mImpl->mUserDefinedFontFamily ) // If user defined font then should not update when system font changes
   {
     DALI_LOG_INFO( gLogFilter, Debug::Concise, "Controller::UpdateAfterFontChange newDefaultFont(%s)\n", newDefaultFont.c_str() );
-    mImpl->mFontDefaults->mDefaultFontFamily=newDefaultFont;
+    mImpl->mFontDefaults->mFontDescription.family = newDefaultFont;
     mImpl->UpdateModel( ALL_OPERATIONS );
     mImpl->QueueModifyEvent( ModifyEvent::TEXT_REPLACED );
     mImpl->mRecalculateNaturalSize = true;
index fa4f966..e665ac2 100644 (file)
@@ -190,23 +190,67 @@ public:
   const std::string& GetDefaultFontFamily() const;
 
   /**
-   * @brief Set the default font style.
+   * @brief Sets the font's style string.
    *
-   * @param[in] defaultFontStyle The default font style.
+   * @note The style set may be changed by the underlying font system. The string is stored to be recovered.
+   *
+   * @param[in] style The font's style string.
    */
-  void SetDefaultFontStyle( const std::string& defaultFontStyle );
+  void SetDefaultFontStyle( const std::string& style );
 
   /**
-   * @brief Retrieve the default font style.
+   * @brief Retrieves the font's style.
    *
-   * @return The default font style.
+   * @return The font's style.
    */
   const std::string& GetDefaultFontStyle() const;
 
   /**
+   * @brief Sets the default font width.
+   *
+   * @param[in] width The font width.
+   */
+  void SetDefaultFontWidth( FontWidth width );
+
+  /**
+   * @brief Retrieves the default font width.
+   *
+   * @return The default font width.
+   */
+  FontWidth GetDefaultFontWidth() const;
+
+  /**
+   * @brief Sets the default font weight.
+   *
+   * @param[in] weight The font weight.
+   */
+  void SetDefaultFontWeight( FontWeight weight );
+
+  /**
+   * @brief Retrieves the default font weight.
+   *
+   * @return The default font weight.
+   */
+  FontWeight GetDefaultFontWeight() const;
+
+  /**
+   * @brief Sets the default font slant.
+   *
+   * @param[in] slant The font slant.
+   */
+  void SetDefaultFontSlant( FontSlant slant );
+
+  /**
+   * @brief Retrieves the default font slant.
+   *
+   * @return The default font slant.
+   */
+  FontSlant GetDefaultFontSlant() const;
+
+  /**
    * @brief Set the default point size.
    *
-   * @param[in] defaultFontStyle The default point size.
+   * @param[in] pointSize The default point size.
    */
   void SetDefaultPointSize( float pointSize );
 
index 85888b0..dbb29cd 100644 (file)
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
+#include <dali/devel-api/text-abstraction/font-list.h>
 #include <dali/devel-api/text-abstraction/font-metrics.h>
 #include <dali/devel-api/text-abstraction/glyph-info.h>
 #include <dali/devel-api/text-abstraction/script.h>
@@ -34,6 +35,9 @@ namespace Text
 {
 
 typedef TextAbstraction::FontId             FontId;             ///< The unique identifier for a font face (generated by FontClient).
+typedef TextAbstraction::FontWidth::Type    FontWidth;          ///< The font's width.
+typedef TextAbstraction::FontWeight::Type   FontWeight;         ///< The font's weight.
+typedef TextAbstraction::FontSlant::Type    FontSlant;          ///< The font's slant.
 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.
index 99f8a8c..279e1aa 100644 (file)
@@ -77,7 +77,7 @@ std::ostream& operator<< (std::ostream& o, const Vector<FontRun>& fontRun)
     FontId id = fontRun[i].fontId;
     TextAbstraction::FontDescription fontDescription;
     fontClient.GetDescription( id, fontDescription );
-    o << "ID:" << id << ", " << fontDescription.family << " style:" << fontDescription.style << " size:" << (fontClient.GetPointSize(id) / 64);
+    o << "ID:" << id << ", " << fontDescription.family << " width: " << fontDescription.width << " weight: " << fontDescription.weight << " slant: " << fontDescription.slant <<  " size:" << (fontClient.GetPointSize(id) / 64);
 
     if( i+1 < fontRun.Count() )
     {
index eacee82..5406361 100644 (file)
@@ -67,7 +67,7 @@ public:
       PLACEHOLDER_TEXT,                         ///< name "placeholder-text",                    The text to display when the TextField is empty and inactive,             type STRING
       PLACEHOLDER_TEXT_FOCUSED,                 ///< name "placeholder-text-focused",            The text to display when the TextField is empty with key-input focus,     type STRING
       FONT_FAMILY,                              ///< name "font-family",                         The requested font family,                                                type STRING
-      FONT_STYLE,                               ///< name "font-style",                          The requested font style e.g. Regular/Italic,                             type STRING
+      FONT_STYLE,                               ///< name "font-style",                          The requested font style,                                                 type STRING
       POINT_SIZE,                               ///< name "point-size",                          The size of font in points,                                               type FLOAT
       MAX_LENGTH,                               ///< name "max-length"                           The maximum number of characters that can be inserted,                    type INTEGER
       EXCEED_POLICY,                            ///< name "exceed-policy"                        Specifies how the text is truncated when it does not fit,                 type INTEGER
index b11bd13..f882e55 100644 (file)
@@ -60,7 +60,7 @@ public:
       RENDERING_BACKEND = PROPERTY_START_INDEX, ///< name "rendering-backend",    The type or rendering e.g. bitmap-based,          type INT
       TEXT,                                     ///< name "text",                 The text to display in UTF-8 format,              type STRING
       FONT_FAMILY,                              ///< name "font-family",          The requested font family,                        type STRING
-      FONT_STYLE,                               ///< name "font-style",           The requested font style e.g. Regular/Italic,     type STRING
+      FONT_STYLE,                               ///< name "font-style",           The requested font style,                         type STRING
       POINT_SIZE,                               ///< name "point-size",           The size of font in points,                       type FLOAT
       MULTI_LINE,                               ///< name "multi-line",           The single-line or multi-line layout option,      type BOOLEAN
       HORIZONTAL_ALIGNMENT,                     ///< name "horizontal-alignment", The line horizontal alignment,                    type STRING,  values "BEGIN", "CENTER", "END"
index 660a392..35531e4 100644 (file)
@@ -110,7 +110,7 @@ distributing this software or its derivatives.
       "label":
       {
         "point-size":8,
-        "font-style":"Light"
+        "font-style":"{\"weight\":\"light\"}"
       }
     },
     "scrollview":
index 7b4def1..935744f 100644 (file)
@@ -110,7 +110,7 @@ distributing this software or its derivatives.
       "label":
       {
         "point-size":8,
-        "font-style":"Light"
+        "font-style":"{\"weight\":\"light\"}"
       }
     },
     "scrollview":
diff --git a/docs/content/shared-javascript-and-cpp-documentation/font-selection.md b/docs/content/shared-javascript-and-cpp-documentation/font-selection.md
new file mode 100644 (file)
index 0000000..348bf1b
--- /dev/null
@@ -0,0 +1,133 @@
+<!--
+/**-->
+
+# Font Selection {#font-selection}
+
+By default TextLabel or TextField will automatically select a suitable font from the platform.
+Typically fonts do not support all scripts, for example Latin fonts often do not provide Arabic glyphs.
+Therefore you should expect the text control to select different fonts for each script.
+
+Alternatively a font may be requested using either or all of FONT_FAMILY, FONT_STYLE, and POINT_SIZE properties:
+
+- FONT_FAMILY
+  Is a string with the font's family name. i.e. *FreeSerif*
+- FONT_STYLE
+  Is a json formatted string with the font's style. Possible *key, value* pairs are:
+  + *width* Modifies the space between glyphs. Possible values are:
+    - *ultra-condensed*
+    - *extra-condensed*
+    - *condensed*
+    - *semi-condensed*
+    - *normal*
+    - *semi-expanded*
+    - *expanded*
+    - *extra-expanded*
+    - *ultra-expanded*
+  + *weight* Modifies the thickness or darkness of the glyphs. Possible values are:
+    - *thin*
+    - *ultra-light*
+    - *extra-light*
+    - *light*
+    - *demi-light*
+    - *semi-light*
+    - *book*
+    - *normal*
+    - *regular*
+    - *medium*
+    - *demi-bold*
+    - *semi-bold*
+    - *bold*
+    - *ultra-bold*
+    - *extra-bold*
+    - *black*
+    - *heavy*
+    - *extra-black*
+  + *slant* Whether to use italics. Usually *italic* is a different font whilst the *oblique* has been generated by slanting the *normal* one. Possible values are:
+    - *normal*
+    - *roman* Same as *normal*
+    - *italic*
+    - *oblique*
+- POINT_SIZE
+  Is a float with the font's size in points. To get the point size from pixels, could use the formula: <em>point_size = 72 * pixels / vertical_dpi</em> where <em>vertical_dpi</em> is the device's vertical resolution in dots per inch.
+
+~~~{.cpp}
+// C++
+
+label.SetProperty( TextLabel::Property::FONT_FAMILY, "FreeSerif" );
+label.SetProperty( TextLabel::Property::FONT_STYLE,  "{\"weight\":\"bold\",\"slant\":\"italic\"}" );
+label.SetProperty( TextLabel::Property::POINT_SIZE,  12.0f );
+~~~
+
+~~~{.js}
+// JavaScript
+
+label.fontFamily = "FreeSerif";
+label.fontStyle = "{\"weight\":\"bold\",\"slant\":\"italic\"}";
+label.pointSize = 12;
+~~~
+
+However the text control will fall-back to using the default font, if the requested font does not support the required scripts.
+
+### Font Styles
+
+Setting a font size programmatically is not ideal for applications which support multiple screen resolutions etc.
+A more flexible approach is to prepare various JSON stylesheets, and request a different style for each platform:
+
+~~~{.cpp}
+// C++
+StyleManager styleManager = StyleManager::Get();
+styleManager.RequestThemeChange( "example-path/example.json" );
+~~~
+
+To change the font for standard text controls, this JSON syntax can be used:
+
+~~~{.json}
+{
+  "styles":
+  {
+    "textlabel":
+    {
+      "font-family":"FreeSerif",
+      "font-style":"{\"weight\":\"bold\",\"slant\":\"italic\"}",
+      "point-size":8
+    }
+  }
+}
+~~~
+
+However the same point-size is unlikely to be suitable for all text controls in an application.
+To set custom sizes simply set a "style name" for each case, and then provide a style override in JSON:
+
+~~~{.cpp}
+  // C++
+
+  label.SetProperty( Control::Property::STYLE_NAME, "custom" );
+~~~
+~~~{.js}
+  // JavaScript
+
+  label.styleName = "custom"';
+~~~
+
+~~~{.json}
+{
+  "styles":
+  {
+    "textlabel":
+    {
+      "font-family":"FreeSerif",
+      "font-style":"{\"weight\":\"bold\",\"slant\":\"italic\"}",
+      "point-size":8
+    },
+
+    "custom":
+    {
+      "point-size":10
+    }
+  }
+}
+~~~
+
+In the example above, standard text labels will have point-size 8, and "custom" labels will have point-size 10.
+
+*/
index 79e20ed..05bf048 100644 (file)
@@ -51,22 +51,7 @@ console.log( field.text );
 
 ### Font Selection
 
-TextField will automatically select a suitable fonts, in the same was as TextLabel.
-The preferred font can also be selected from a JSON stylesheet:
-
-~~~{.json}
-{
-  "styles":
-  {
-    "textfield":
-    {
-      "font-family":"Arial",
-      "font-style":"Regular",
-      "point-size":8
-    }
-  }
-}
-~~~
+By default TextField will automatically select a suitable font from the platform. However, a different font could be selected. See the [Font Selection](@ref font-selection) section for more details.
 
 ### Text Alignment
 
index c08af6d..1b63a42 100644 (file)
@@ -41,91 +41,7 @@ The position of the label on-screen is dependent on the parent-origin and anchor
 
 ### Font Selection
 
-By default TextLabel will automatically select a suitable font from the platform.  
-Typically fonts do not support all scripts, for example Latin fonts often do not provide Arabic glyphs.  
-Therefore you should expect TextLabel to select different fonts for each script.
-
-Alternatively a font may be requested using either or all of FONT_FAMILY, FONT_STYLE, and POINT_SIZE properties:
-
-~~~{.cpp}
-// C++
-
-label.SetProperty( TextLabel::Property::FONT_FAMILY, "HelveticaNue" );
-label.SetProperty( TextLabel::Property::FONT_STYLE,  "Regular" );
-label.SetProperty( TextLabel::Property::POINT_SIZE,  12.0f );
-~~~
-
-~~~{.js}
-// JavaScript
-
-label.fontFamily = "HelveticaNue";
-label.fontStyle = "Regular";
-label.pointSize = 12;
-~~~
-
-However the TextLabel will fall-back to using the default font, if the requested font does not support the required scripts.
-
-### Font Styles
-
-Setting a font size programmatically is not ideal for applications which support multiple screen resolutions etc.  
-A more flexible approach is to prepare various JSON stylesheets, and request a different style for each platform:  
-
-~~~{.cpp}
-// C++
-StyleManager styleManager = StyleManager::Get();
-styleManager.RequestThemeChange( "example-path/example.json" );
-~~~
-
-To change the font for standard text labels, this JSON syntax can be used:
-
-~~~{.json}
-{
-  "styles":
-  {
-    "textlabel":
-    {
-      "font-family":"Arial",
-      "font-style":"Regular",
-      "point-size":8
-    }
-  }
-}
-~~~
-
-However the same point-size is unlikely to be suitable for all labels in an application.  
-To set custom sizes simply set a "style name" for each case, and then provide a style override in JSON:
-
-~~~{.cpp}
-  // C++
-
-  label.SetProperty( Control::Property::STYLE_NAME, "custom" );
-~~~
-~~~{.js}
-  // JavaScript
-
-  label.styleName = "custom"';
-~~~
-
-~~~{.json}
-{
-  "styles":
-  {
-    "textlabel":
-    {
-      "font-family":"Arial",
-      "font-style":"Regular",
-      "point-size":8
-    },
-
-    "custom":
-    {
-      "point-size":10
-    }
-  }
-}
-~~~
-
-In the example above, standard text labels will have point-size 8, and "custom" labels will have point-size 10.  
+By default TextLabel will automatically select a suitable font from the platform. However, a different font could be selected. See the [Font Selection](@ref font-selection) section for more details.
 
 ### Text Alignment