How to convert WCHAR* table into the table which fits some editBox?

Started by
1 comment, last by anders211 11 years, 4 months ago
How to convert the text into the text which is align to the some width (so also how to divide the text into multiline and align between left and right border (not center))? What is more we use only ID3DXFont::DrawTextW, ScriptStringAnalyse and similar Script functions. We assume that we don't use any SetTextAlign. Is any simple way, better than below one?
My approach in pseudocode:
- invoke analyse sth like that:

HDC hDC = mFont->font->GetDC();
HRESULT hr = ScriptStringAnalyse(hDC,
mBuffer,
lstrlenW(mBuffer) + 1, // NULL is also analyzed
lstrlenW(mBuffer) * 3/2 + 16, //size of buffer for glyph, recommended value 1.5 * length + 16
-1, //for unicode set -1
SSA_BREAK | SSA_GLYPHS | SSA_FALLBACK | SSA_LINK, // | SSA_FIT, SSA_CLIP
0, //127 this is piece of shit in the msdn, it doesn't divide the text into width = 127 px I have to do it on my own:/
&ScriptControl,
&ScriptState,
NULL,
NULL,
NULL,
&mAnalysis);


- then go trough each buffer character and collect the full words which are able to fit into the Width of editBox and catch all the specific ' ' which then You have to change into '\n' character.

This approach was improved, after each modification ' ' into '\n' I have to invoke again analyse(), because the X coordinates of chars change when You replace ' ' into '\n'.
However this approach doesn't solve the problem of alignment the text. Here I don't have idea. So in other words I would like to have the divided text and alignment to both borders in the buffer! That is why any setTextAlign function cannot be used.

This is my code which is trying to modify the mBuffer.

void Buffer::transformText(i32 width)
{
if(width < 0)
return;

if(mAnalyseRequired)
if(analyse() != OK)
return;

const SCRIPT_LOGATTR* pLogAttr = ScriptString_pLogAttr(mAnalysis);
if(!pLogAttr)
return;

if(!ScriptString_pcOutChars(mAnalysis))
return;

i32 limit = *ScriptString_pcOutChars(mAnalysis);

//calculate number of words
u32 numWords = 1;
for(i32 i=0; i<limit - 1; ++i) //without '\0'
if(pLogAttr.fWordStop && mBuffer != '\n') //'\n' is also softBreak, charStop and wordStop
++numWords;

//vector<i32> znaczniki;
mBeginMarks.clear();
mBeginMarks.swap(vector<i32>(mBeginMarks));
mBeginMarks.push_back(0);
mLines = 1;
i32 fromBegX = 0;
i32 charNr = 0;
for(i32 i=0; i<limit; ++i)
{
(void)mBuffer;
if((pLogAttr.fWhiteSpace && !pLogAttr[i+1].fWhiteSpace) || mBuffer == '\n' || mBuffer == '\0')
{
i32 X;
CPtoX(i, FALSE, &X);
if(width >= X-fromBegX && mBuffer != '\n')
charNr = i; //remember the last succeed char number
else
{
if(mBuffer == '\n')
charNr = i;
else
mBuffer[charNr] = '\n';
mAnalyseRequired = true;
analyse();
pLogAttr = ScriptString_pLogAttr(mAnalysis);
if(!pLogAttr)
return;
if(!ScriptString_pcOutChars(mAnalysis))
return;
limit = *ScriptString_pcOutChars(mAnalysis);
CPtoX(charNr, TRUE, &X);
fromBegX = X; //+= width;
++mLines;
//znaczniki.push_back(charNr);
mBeginMarks.push_back(X); //remember the X coordinate of the lines first chars
}
}
}

/*i32 size = static_cast<i32>(znaczniki.size());
for(i32 i = 0; i<size; ++i)
mBuffer[znaczniki] = '\n';*/
}
Advertisement
What do you mean by it doesn't work? Do you a compile error? A runtime error? Does it not do what you want it to do? If so, what do you want it to do?

What do you mean by it doesn't work? Do you a compile error? A runtime error? Does it not do what you want it to do? If so, what do you want it to do?

OK I updated the first post. I have just written also to microsoft because this task is a bit challange and maybe not solvable.


I am in the middle of implementation my own multiline EditBox control (based on oneline EditBox from CDXUT Utility). I divided my text (which is kept in WCHAR * buffer) into lines (replacing some ' ' into '\n' between breakable words) and now my text fits into the width of EditBox but I have a problem how can I now justify (align) the text. I have to have aligment text in the buffer because only in this way when I click with the aid of mouse on the editBox, the caret will be set at the given char perfectly. I suppose it can be done with some scriptStringMethods but I don't have idea how to use them to cause the effect which I would like.
Thanks in advance for help

This topic is closed to new replies.

Advertisement