• Create Account

### #Actualanders211

Posted 19 December 2012 - 07:20 PM

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:/
&amp;amp;amp;ScriptControl,
&amp;amp;amp;ScriptState,
NULL,
NULL,
NULL,
&amp;amp;amp;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[i].fWordStop && mBuffer[i] != '\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[i];
if((pLogAttr[i].fWhiteSpace && !pLogAttr[i+1].fWhiteSpace) || mBuffer[i] == '\n' || mBuffer[i] == '\0')
{
i32 X;
CPtoX(i, FALSE, &X);
if(width >= X-fromBegX && mBuffer[i] != '\n')
charNr = i; //remember the last succeed char number
else
{
if(mBuffer[i] == '\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[i]] = '\n';*/
}

### #5anders211

Posted 19 December 2012 - 11:34 AM

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:/
&amp;amp;ScriptControl,
&amp;amp;ScriptState,
NULL,
NULL,
NULL,
&amp;amp;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 has to be 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(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[i].fWordStop && mBuffer[i] != '\n') //'\n' is also softBreak, charStop and wordStop
++numWords;

vector<i32> znaczniki;
i32 fromBegX = 0;
i32 charNr = 0;
for(i32 i=0; i<limit - 1; ++i)
if((pLogAttr[i].fWhiteSpace && !pLogAttr[i+1].fWhiteSpace) || mBuffer[i] == '\n')
{
i32 X;
CPtoX(i, FALSE, &X);
if(width >= X-fromBegX)
charNr = i; //remember the last succeed char number
else
{
fromBegX += width;
//mBuffer[charNr] = '\n'; //in fact I have to change here the char and then invoke analyse() and maybe in recursive way call again transformText
znaczniki.push_back(charNr); //charNr will be replaced with '\n'
}
}

i32 size = static_cast<i32>(znaczniki.size());
for(i32 i = 0; i<size; ++i)
mBuffer[znaczniki[i]] = '\n';
}

### #4anders211

Posted 19 December 2012 - 11:30 AM

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:/
&amp;ScriptControl,
&amp;ScriptState,
NULL,
NULL,
NULL,
&amp;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 has to be 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.

### #3anders211

Posted 19 December 2012 - 11:30 AM

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:/
&amp;ScriptControl,
&amp;ScriptState,
NULL,
NULL,
NULL,
&amp;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 has to be 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.

### #2anders211

Posted 19 December 2012 - 11:23 AM

What is more we use only ID3DXFont::DrawTextW, ScriptStringAnalyse and similar Script functions. We assume that we don't use any SetTextAlign (because we cannot mess both setTextAlign and DrawTextW). Is any simple way or my approach isn't a waste of time because the reality is that there aren't any easy built-in functions to do this?
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
&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 ' ' which then You have to change into '\n' character.

This approach has to be 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.

### #1anders211

Posted 19 December 2012 - 09:31 AM

I have WCHAR* mBuffer in my class and I have developed some implementation, however it doesn't work, so that I am fed up with this:

void Buffer::transformText(i32 width)
{
string text;

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 = 0;
for(i32 i=0; i<limit - 1; ++i) //without '\0'
if(pLogAttr[i].fWordStop && mBuffer[i] != '\0')
++numWords;
vector<i32> znaczniki;
i32 fromBegX = 0;
i32 charNr = 0;
for(i32 i=0; i<limit - 1; ++i)
if(pLogAttr[i].fWhiteSpace && !pLogAttr[i+1].fWhiteSpace)
{
i32 X;
CPtoX(i, FALSE, &X);
if(width >= X-fromBegX)
charNr = i; //remember the last succeed char number
else
{
fromBegX += width;
znaczniki.push_back(charNr); //charNr will be replaced with '\n'
}
}
i32 size = static_cast<i32>(znaczniki.size());
for(i32 i = 0; i<size; ++i)
mBuffer[znaczniki[i]] = '\n';
}


PARTNERS