Skip to content

Commit

Permalink
fix wrong effect of RichText (cocos2d#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
minggo authored Oct 18, 2017
1 parent 3071c87 commit c549110
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ creator_project/build/
creator_project/temp/
creator_project/json/
creator_project/ccreator/
creator_project/settings/
#/////////////////////////////////////////////////////////////////////////////
# Logs and databases
#/////////////////////////////////////////////////////////////////////////////
Expand Down
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,10 @@ Supported nodes:
* `TiledMap`
* `Button`
* `ProgressBar`
* `RichText`: need cocos2d-x 3.16+ to support img tag, refer to [this issue](https://github.com/cocos2d/creator_to_cocos2dx/issues/41) for detail information
* `RichText`:
* Need cocos2d-x 3.16+ to support img tag, refer to [this issue](https://github.com/cocos2d/creator_to_cocos2dx/issues/41) for detail information.
* Doesn't support `line height`because cocos2d-x's `RichText` doesn't support this features.
* Doesn't support `horizontal alignment`because cocos2d-x's `RichText` doesn't support this features. Though cocos2d-x v3.16+ supports this feature, but it is hard for plugin to danymicly supporting it according cocos2d-x's version.
* `SpineSkeleton`
* `Widget`: only supports `AlignOnce`
* `Animations`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,8 @@ class RichText extends Node {
let regex = /(<outline color|width)=(\w*) (color|width)=(\w*)/;
text = text.replace(regex, "$1='$2' $3='$4'");

// <br/> -> \n
text = text.replace('<br/>', '\n');

// add <font></font> if the text starts with charactor
if (text[0] !== '<')
text = '<font>' + text + '</font>';
// add <font></font> for raw strings
text = '<font>' + text + '</font>';

// add sprite frames if there is img component
if (component._N$imageAtlas) {
Expand Down Expand Up @@ -56,6 +52,13 @@ class RichText extends Node {
let f = component._N$font;
if (f)
this._properties.fontFilename = Utils.get_font_path_by_uuid(f.__uuid__);
else
this._properties.fontFilename = 'Arial';

// should floor the content size, or it may cause to create a new line
let contentSize = this._properties.node.contentSize;
let newContentSize = {w:Math.ceil(contentSize.w), h:Math.ceil(contentSize.h)};
this._properties.node.contentSize = newContentSize;
}
}
RichText.H_ALIGNMENTS = ['Left', 'Center', 'Right'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,9 +744,14 @@ void CreatorReader::parseRichText(cocos2d::ui::RichText* richText, const buffers
}

// should do it after richText->initWithXML
richText->ignoreContentAdaptWithSize(false);

const auto& maxWidth = richTextBuffer->maxWidth();
if (maxWidth > 0)
richText->ignoreContentAdaptWithSize(false);
{
const auto& contentSize = richText->getContentSize();
richText->setContentSize(cocos2d::Size(maxWidth, contentSize.height));
}
}

cocos2d::ParticleSystemQuad* CreatorReader::createParticle(const buffers::Particle* particleBuffer) const
Expand Down

0 comments on commit c549110

Please sign in to comment.