Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-13971] Fixed font size #195

Merged
merged 2 commits into from
Dec 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
112 changes: 3 additions & 109 deletions src/tibb/NativeAbstractTextControlObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "TiObject.h"
#include "V8Utils.h"
#include "TiUtils.h"
#include "TiCore.h"

using namespace titanium;

Expand Down Expand Up @@ -117,70 +118,8 @@ int NativeAbstractTextControlObject::setTextAlign(TiObject* obj)

int NativeAbstractTextControlObject::setFont(TiObject* obj)
{
QMap<QString, QString> font;
int error = NativeControlObject::getMapObject(obj, font);
if (error != NATIVE_ERROR_OK)
{
return error;
}

QMap<QString, QString>::const_iterator it = font.begin();
for (; it != font.end(); ++it)
{
if (it.key().compare(FONT_FAMILY) == 0)
{
textControl_->textStyle()->setFontFamily(it.value());
}
else if (it.key().compare(FONT_SIZE) == 0)
{
float size = computeValue(it.value().toUtf8().constData());
if (size > 0)
{
textControl_->textStyle()->setFontSize(bb::cascades::FontSize::PointValue);
textControl_->textStyle()->setFontSizeValue(size);
}
else
{
N_DEBUG(Native::Msg::Failed_to_convert_font_size_to_float_with_value << ": " << it.value());
}
}
else if (it.key().compare(FONT_STYLE) == 0)
{
if (it.value().compare(FONT_STYLE_NORMAL) == 0)
{
textControl_->textStyle()->setFontStyle(bb::cascades::FontStyle::Normal);
}
else if (it.value().compare(FONT_STYLE_ITALIC) == 0)
{
textControl_->textStyle()->setFontStyle(bb::cascades::FontStyle::Italic);
}
else
{
N_DEBUG(Native::Msg::Unknown_value_received << ": " << it.value());
}
}
else if (it.key().compare(FONT_WEIGHT) == 0)
{
if (it.value().compare(FONT_WEIGHT_NORMAL) == 0)
{
textControl_->textStyle()->setFontWeight(bb::cascades::FontWeight::Normal);
}
else if (it.value().compare(FONT_WEIGHT_BOLD) == 0)
{
textControl_->textStyle()->setFontWeight(bb::cascades::FontWeight::Bold);
}
else
{
N_DEBUG(Native::Msg::Unknown_value_received << ": " << it.value());
}
}
else
{
N_DEBUG(Native::Msg::Unknown_key_value_received << ": " << it.key() << ":" << it.value());
}
}

return NATIVE_ERROR_OK;
Ti::TiHelper::applyFontToText(Ti::TiValue(obj->getValue()), textControl_);
return NATIVE_ERROR_OK;
}

void NativeAbstractTextControlObject::updateLayout(QRectF rect)
Expand All @@ -195,48 +134,3 @@ void NativeAbstractTextControlObject::updateLayout(QRectF rect)
textControl_->setPreferredHeight(rect.height());
}
}

float NativeAbstractTextControlObject::computeValue(std::string value) {
std::string units;
float parsedValue;

if ((value.find("mm") != std::string::npos) || (value.find("cm") != std::string::npos) ||
(value.find("em") != std::string::npos) || (value.find("pt") != std::string::npos) ||
(value.find("in") != std::string::npos) || (value.find("px") != std::string::npos) ||
(value.find("dp") != std::string::npos) || (value.find("dip") != std::string::npos)) {

if((value.find("dip") != std::string::npos)) {
units = value.substr (value.size() - 3 , 3);
parsedValue = atof(value.substr(0, value.size() - 3).c_str());
} else {
units = value.substr (value.size() - 2 , 2);
parsedValue = atof(value.substr(0, value.size() - 2).c_str());
}
}
else {
parsedValue = atof(value.c_str());
units = "dp";
}

if (units == "mm") {
return parsedValue /= 10;
}
else if (units == "cm") {
return parsedValue * 0.393700787 * ppi_;
}
else if (units == "em" || units == "pt") {
return parsedValue /= 12;
}
else if (units == "pc") {
return parsedValue /= 6;
}
else if (units == "in") {
return parsedValue * ppi_;
}
else if (units == "px") {
return parsedValue;
}
else if (units == "dp" || units == "dip") {
return parsedValue / (ppi_ / 96); // http://msdn.microsoft.com/en-us/library/windows/desktop/ff684173(v=vs.85).aspx
}
}
1 change: 0 additions & 1 deletion src/tibb/NativeAbstractTextControlObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class NativeAbstractTextControlObject : public NativeControlObject
// Disable copy ctor & assignment operator
NativeAbstractTextControlObject(const NativeAbstractTextControlObject& textControl);
NativeAbstractTextControlObject& operator=(const NativeAbstractTextControlObject& textControl);
float computeValue(std::string value);

bb::cascades::AbstractTextControl* textControl_;
double ppi_;
Expand Down