Mygui Chinese line feed solution

Source: Internet
Author: User
Tags ustring

I believe that after you solve the problem of Chinese input, you will surely encounter the problem of how to solve the problem of Chinese input. The problem of line feed in Chinese input is a problem in many gui frameworks, open the header file and source file of the textview of the widget in the engine layer of mygui and replace it: Copy codeThe Code is as follows :/*!
@ File
@ Author Albert Semenov
@ Date 09/2009
*/
# Ifndef _ MYGUI_TEXT_VIEW_DATA_H __
# Define _ MYGUI_TEXT_VIEW_DATA_H __
# Include "MyGUI_Prerequest.h"
Namespace MyGUI
{
Class CharInfo
{
Public:
CharInfo ():
MIsColour (false)
{
Required Rics. mWidth = 0.0f;
Required Rics. mHeight = 0.0f;
Metrics Rics. mAdvance = 0.0f;
Metrics Rics. mBearingX = 0.0f;
Required Rics. mBearingY = 0.0f;
}
CharInfo (
Const FloatRect & _ rect,
Float _ width,
Float _ height,
Float _ advance,
Float _ bearingX,
Float _ bearingY ):
MIsColour (false ),
MUVRect (_ rect)
{
MMetrics. mWidth = _ width;
Repeated Rics. mHeight = _ height;
Metrics Rics. mAdvance = _ advance;
Metrics Rics. mBearingX = _ bearingX;
Metrics Rics. mBearingY = _ bearingY;
}
CharInfo (uint32 _ color ):
MIsColour (true ),
MColour (_ color)
{}
Bool isColour () const
{
Return mIsColour;
}
Float getWidth () const
{
Return response Rics. mWidth;
}
Float getHeight () const
{
Return response Rics. mHeight;
}
Float getAdvance () const
{
Return response Rics. mAdvance;
}
Float getBearingX () const
{
Return response Rics. mBearingX;
}
Float getBearingY () const
{
Return response Rics. mBearingY;
}
Const FloatRect & getUVRect () const
{
Return mUVRect;
}
Uint32 getColour () const
{
Return mColour;
}
Private:
Bool mIsColour;
FloatRect mUVRect;
Struct Metrics
{
Float mWidth;
Float mHeight;
Float mAdvance;
Float mBearingX;
Float mBearingY;
};
Union
{
Metrics RICS;
Uint32 mColour;
};
};
Typedef std: vector <CharInfo> VectorCharInfo;
// Struct LineInfo
//{
// LineInfo ():
// Width (0 ),
// Offset (0 ),
// Count (0)
//{
//}
// Void clear ()
//{
// Width = 0;
// Count = 0;
// Simbols. clear ();
// Offset = 0;
//}
// Int width;
// Int offset;
// Size_t count;
// VectorCharInfo simbols;
//};
Struct LineInfo
{
LineInfo ():
Width (0 ),
Offset (0 ),
Count (0 ),
Offcount (0)
{
}
Void clear ()
{
Offcount = 0;
Width = 0;
Count = 0;
Simbols. clear ();
Offset = 0;
}
Int offcount;
Int width;
Int offset;
Size_t count;
VectorCharInfo simbols;
};
Typedef std: vector <LineInfo> VectorLineInfo;
} // Namespace MyGUI
# Endif // _ MYGUI_TEXT_VIEW_DATA_H __

The above is the header file, and the following is the source file:Copy codeThe Code is as follows :/*!
@ File
@ Author Albert Semenov
@ Date 09/2010
*/
/*
This file is part of MyGUI.
MyGUI is free software: you can redistribute it and/or modify
It under the terms of the GNU Lesser General Public License as published
The Free Software Foundation, either version 3 of the License, or
(At your option) any later version.
MyGUI is distributed in the hope that it will be useful,
But without any warranty; without even the implied warranty
MERCHANTABILITY or fitness for a particle PURPOSE. See
GNU Lesser General Public License for more details.
You shoshould have your ed a copy of the GNU Lesser General Public License
Along with MyGUI. If not, see */
# Include "MyGUI_Precompiled.h"
# Include "MyGUI_TextView.h"
Namespace MyGUI
{
Namespace
{
Template <typename T>
Void setMin (T & _ var, const T & _ newValue)
{
If (_ newValue <_ var)
_ Var = _ newValue;
}
Template <typename T>
Void setMax (T & _ var, const T & _ newValue)
{
If (_ var <_ newValue)
_ Var = _ newValue;
}
}
Class RollBackPoint
{
Public:
RollBackPoint ():
Position (0 ),
Count (0 ),
Width (0 ),
Rollback (false)
{
}
Void set (size_t _ position, UString: const_iterator & _ space_point, size_t _ count, float _ width)
{
Position = _ position;
Space_point = _ space_point;
Count = _ count;
Width = _ width;
Rollback = true;
}
Void clear ()
{
Rollback = false;
}
Bool empty () const
{
Return! Rollback;
}
Float getWidth () const
{
MYGUI_DEBUG_ASSERT (rollback, "rollback point not valid ");
Return width;
}
Size_t getCount () const
{
MYGUI_DEBUG_ASSERT (rollback, "rollback point not valid ");
Return count;
}
Size_t getPosition () const
{
MYGUI_DEBUG_ASSERT (rollback, "rollback point not valid ");
Return position;
}
UString: const_iterator getTextIter () const
{
MYGUI_DEBUG_ASSERT (rollback, "rollback point not valid ");
Return space_point;
}
Private:
Size_t position;
UString: const_iterator space_point;
Size_t count;
Float width;
Bool rollback;
};
TextView: TextView ():
MLength (0 ),
MFontHeight (0)
{
}
Void TextView: update (const UString & _ text, IFont * _ font, int _ height, Align _ align, VertexColourType _ format, int _ maxWidth)
{
MFontHeight = _ height;
// When there are too many threads, there are too many threads in the queue.
Static const char convert_colour [64] =
{
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 0, 0, 0, 0,
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 10, 11, 12, 13, 14, 15, 0, 0, 0, 0, 0, 0, 0
};
MViewSize. clear ();
RollBackPoint roll_back;
IntSize result;
Float width = 0.0f;
Size_t count = 0;
MLength = 0;
MLineInfo. clear ();
LineInfo line_info;
Int font_height = _ font-> getDefaultHeight ();
UString: const_iterator end = _ text. end ();
UString: const_iterator index = _ text. begin ();
/* If (index = end)
Return ;*/
Result. height + = _ height;
For (; index! = End; ++ index)
{
Char character = * index;
// When there are too many threads, there are too many other threads
If (character = FontCodeType: CR
| Character = FontCodeType: NEL
| Character = FontCodeType: LF)
{
If (character = FontCodeType: CR)
{
UString: const_iterator peeki = index;
++ Peeki;
If (peeki! = End) & (* peeki = FontCodeType: LF ))
Index = peeki; // skip both as one newline
}
Line_info.width = (int) ceil (width );
Line_info.count = count;
// MLength + = line_info.count + 1;
MLength + = line_info.offcount;
Result. height + = _ height;
SetMax (result. width, line_info.width );
Width = 0;
Count = 0;
MLineInfo. push_back (line_info );
Line_info.clear ();
// When there are too many threads, there are too many other threads.
Roll_back.clear ();
Continue;
}
// Zookeeper APIs
Else if (character = l '#')
{
// When there are too many threads, there are too many threads, too many threads
++ Index;
If (index = end)
{
-- Index; // There are too many rows when there are too many rows
Continue;
}
Character = * index;
// When there are too many threads, there are too many threads, too many threads, when there are too many threads, there are too many threads, too many threads.
If (character! = L '#')
{
// When there are too many threads, there are too many threads, too many threads
Uint32 color = convert_colour [(character-48) & 0x3F];
// When there are too many threads, there are too many threads, too many threads
For (char I = 0; I <5; I ++)
{
++ Index;
If (index = end)
{
-- Index; // There are too many rows when there are too many rows
Continue;
}
Color <= 4;
Color + = convert_colour [(* index)-48) & 0x3F];
}
// When there are already too many attempts, when there are too many threads, there are too many threads, too many threads
Texture_utility: convertColour (color, _ format );
Line_info.simbols.push_back (CharInfo (color ));
Continue;
}
}
GlyphInfo * info = _ font-> getGlyphInfo (character );
If (info = nullptr)
Continue;
If (FontCodeType: Space = character)
{
Roll_back.set (line_info.simbols.size (), index, count, width );
}
Else if (FontCodeType: Tab = character)
{
Roll_back.set (line_info.simbols.size (), index, count, width );
}
Float char_width = info-> width;
Float char_height = info-> height;
Float char_advance = info-> advance;
Float char_bearingX = info-> bearingX;
Float char_bearingY = info-> bearingY;
If (_ height! = Font_height)
{
Float scale = (float) _ height/font_height;
Char_width * = scale;
Char_height * = scale;
Char_advance * = scale;
Char_bearingX * = scale;
Char_bearingY * = scale;
}
Float char_fullAdvance = char_bearingX + char_advance;
// When there are too many threads, there are too many other threads
If (_ maxWidth! =-1
& (Width + char_fullAdvance)> _ maxWidth
/*&&! Roll_back.empty ()*/)
{
-- Index;
// When there are too many threads, there are too many threads in the queue.
/* Width = roll_back.getWidth ();
Count = roll_back.getCount ();
Index = roll_back.getTextIter ();
Line_info.simbols.erase (line_info.simbols.begin () + roll_back.getPosition (), line_info.simbols.end ());*/

// When there are too many threads, there are too many threads in the queue. When there are too many threads, there are too many threads in the queue.
/* Line_info.width = (int) ceil (width );
Line_info.count = count;
MLength + = line_info.count + 1;
Result. height + = _ height;
SetMax (result. width, line_info.width );
Width = 0;
Count = 0;
MLineInfo. push_back (line_info );
Line_info.clear ();*/
// When there are too many threads, there are too many threads in the queue. When there are too many threads, there are too many threads in the queue.
Line_info.width = (int) ceil (width );
Line_info.count = count;
Line_info.offcount = 0;
MLength + = line_info.count; // + 1;
Result. height + = _ height;
SetMax (result. width, line_info.width );
Width = 0;
Count = 0;
MLineInfo. push_back (line_info );
Line_info.clear ();
// When there are too many threads, there are too many other threads.
Roll_back.clear ();
Continue;
}
Line_info.simbols.push_back (CharInfo (info-> uvRect, char_width, char_height, char_advance, char_bearingX, char_bearingY ));
Width + = char_fullAdvance;
Count ++;
}
Line_info.width = (int) ceil (width );
Line_info.count = count;
MLength + = line_info.count;
MLineInfo. push_back (line_info );
SetMax (result. width, line_info.width );
// When there are too many threads, there are too many threads, too many threads
For (VectorLineInfo: iterator line = mLineInfo. begin (); line! = MLineInfo. end (); ++ line)
{
If (_ align. isRight ())
Line-> offset = result. width-line-> width;
Else if (_ align. isHCenter ())
Line-> offset = (result. width-line-> width)/2;
}
MViewSize = result;
}
Size_t TextView: getCursorPosition (const IntPoint & _ value)
{
Const int height = mFontHeight;
Size_t result = 0;
Int top = 0;
For (VectorLineInfo: const_iterator line = mLineInfo. begin (); line! = MLineInfo. end (); ++ line)
{
// When there are too many threads, there are too many threads, too many threads
Bool lastline =! (Line + 1! = MLineInfo. end ());
// When there are too many threads, there are too many other threads
If (top + height> _ value. top | lastline)
{
Top + = height;
Float left = (float) line-> offset;
Int count = 0;
// When there are too many threads, there are too many other threads
For (VectorCharInfo: const_iterator sim = line-> simbols. begin (); sim! = Line-> simbols. end (); ++ sim)
{
If (sim-> isColour ())
Continue;
Float fullAdvance = sim-> getAdvance () + sim-> getBearingX ();
If (left + fullAdvance/2.0f> _ value. left)
{
Break;
}
Left + = fullAdvance;
Count ++;
}
Result + = count;
Break;
}
If (! Lastline)
{
Top + = height;
Result + = line-> count + line-> offcount;

}
}
Return result;
}
IntPoint TextView: getCursorPoint (size_t _ position)
{
SetMin (_ position, mLength );
Size_t position = 0;
Int top = 0;
Float left = 0.0f;
For (VectorLineInfo: const_iterator line = mLineInfo. begin (); line! = MLineInfo. end (); ++ line)
{
Left = (float) line-> offset;
If (position + line-> count> = _ position)
{
For (VectorCharInfo: const_iterator sim = line-> simbols. begin (); sim! = Line-> simbols. end (); ++ sim)
{
If (sim-> isColour ())
Continue;
If (position = _ position)
Break;
Position ++;
Left + = sim-> getBearingX () + sim-> getAdvance ();
}
Break;
}
Position + = line-> count + line-> offcount;

Top + = mFontHeight;
}
Return IntPoint (int) left, top );
}
Const IntSize & TextView: getViewSize () const
{
Return mViewSize;
}
Size_t TextView: getTextLength () const
{
Return mLength;
}
Const VectorLineInfo & TextView: getData () const
{
Return mLineInfo;
}
} // Namespace MyGUI

After these two changes, the edit Control is changed to multi-line support and automatic line feed, so that the mygui's Chinese automatic line feed problem is realized.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.