v3.02 LabelRotation op contour beter ondersteunen

svn path=/Slnkdwf/trunk/; revision=19844
This commit is contained in:
Jos Groot Lipman
2013-11-16 12:25:35 +00:00
parent 8a9634c61c
commit 29c807dd00
3 changed files with 50 additions and 43 deletions

View File

@@ -381,17 +381,20 @@ void CSLNKContourImpl::SerializeLabel(WT_File &my_file,
// (afhankelijk van het font) mooier te zijn
// Ook eventueel hori/vert centreren
int width = -1; // Voor UBB code [c] van centreren
// Zoveel het insertpoint verschuiven. Wordt uiteindelijk geroteerd
double dx = 0;
double dy = 0;
switch (m_Labelpos)
{
case CSLNKContourImpl::LABEL_DEFAULT:
dy = l_fontheight; // We beginnen linksboven
break;
case CSLNKContourImpl::LABEL_TOPLEFT: // Iets naar rechtstonder moven
case CSLNKContourImpl::LABEL_TOPLEFT: // Iets naar rechts moven
{
ATLASSERT(myDC!=NULL);
CSize ptBR = DrawOneLabel(my_file, ptTxt, tok, l_fontheight, scale, myDC);
ptTxt.m_x += l_fontheight/4;
ptTxt.m_y -= l_fontheight; // ptBR.cy; lijkt beter maar eigenlijk willen we de hoogte
// van de *eerste* regel er af trekken
ptTxt.m_x += l_fontheight / 4; // niet meeroteren
// ptTxt.m_y staat al linksboven
break;
}
case CSLNKContourImpl::LABEL_OUTSIDERIGHT: // Iets naar rechts en verticaal centreren
@@ -400,18 +403,17 @@ void CSLNKContourImpl::SerializeLabel(WT_File &my_file,
ATLASSERT(myDC!=NULL);
CSize ptBR = DrawOneLabel(my_file, ptTxt, tok, l_fontheight, scale, myDC);
width = ptBR.cx;
ptTxt.m_y -= ptBR.cy + l_fontheight*9/10;
ptTxt.m_x += l_fontheight/4;
dy = ptBR.cy / 2;
ptTxt.m_x += l_fontheight / 4; // niet meeroteren
break;
}
case CSLNKContourImpl::LABEL_OUTSIDEBOTTOM: // Iets naar beneden en horizontaal centreren
case CSLNKContourImpl::LABEL_OUTSIDEBOTTOM: // Horizontaal centreren
{
// Eerst een keer simuleren om grootte te bepalen
ATLASSERT(myDC!=NULL);
CSize ptBR = DrawOneLabel(my_file, ptTxt, tok, l_fontheight, scale, myDC);
width = ptBR.cx;
ptTxt.m_y -= l_fontheight;
ptTxt.m_x -= width/2;
dx = - width / 2.0;
break;
}
case CSLNKContourImpl::LABEL_CENTROID:
@@ -422,14 +424,8 @@ void CSLNKContourImpl::SerializeLabel(WT_File &my_file,
// Eerst een keer simuleren om grootte te bepalen
CSize ptBR = DrawOneLabel(my_file, ptTxt, tok, l_fontheight, scale, myDC);
width = ptBR.cx;
double dx = width / 2.0;
double dy = ptBR.cy / 2.0;
// m_LabelRotation meerekenen
double radian = m_LabelRotation / 180.0 * PI;
int rdx = myRound(dx * cos(radian) - dy * sin(radian));
int rdy = myRound(dy * cos(radian) + dx * sin(radian));
ptTxt.m_x -= rdx;
ptTxt.m_y -= rdy;
dx = - width / 2.0;
dy = ptBR.cy / 2.0;
// Nooit verder naar links/boven dan TOPLEFT zou doen
// JGL: jul 2007: Waarom niet? Bij heel kleine ruimtes mag bij centreren de boel er best wel iets buiten
// WT_Logical_Point ptTL = LabelPosition(CSLNKContourImpl::LABEL_TOPLEFT);
@@ -442,6 +438,13 @@ pm.serialize(my_file);
}
}
// m_LabelRotation meerekenen
double radian = m_LabelRotation / 180.0 * PI;
int rdx = myRound(dx * cos(radian) - dy * sin(radian));
int rdy = myRound(dy * cos(radian) + dx * sin(radian));
ptTxt.m_x += rdx;
ptTxt.m_y += rdy;
// Nu echt tekenen met width<>-2
DrawOneLabel(my_file, ptTxt, tok, l_fontheight, scale, myDC, width);
}
@@ -451,13 +454,14 @@ pm.serialize(my_file);
// is the calculated bottomright of the full text
// Als width==-1 is centreren niet mogelijk/nodig
// Als width>0 is centreren mogelijk via [c]
// ptTxt bevat blijvend de linksboven(!) coordinaten van de totale tekst
CSize CSLNKContourImpl::DrawOneLabel(WT_File &my_file,
WT_Logical_Point ptTxt,
CString tok,
int l_fontheight,
double scale,
HDC myDC,
int width/*=-2*/)// Voor centreren. Moet aanroeper al een keer bepaald hebben
WT_Logical_Point ptTxt,
CString tok,
int l_fontheight,
double scale,
HDC myDC,
int width/*=-2*/)// Voor centreren. Moet aanroeper al een keer bepaald hebben
{
long max_width=0; // Bepaal hiermee 'rechtsonder' van de tekst als myDC
long tot_height=0; // Bepaal hiermee 'rechtsonder' van de tekst als myDC
@@ -466,17 +470,13 @@ CSize CSLNKContourImpl::DrawOneLabel(WT_File &my_file,
//TODO: UBB sluitcodes ondersteunen
int curpos = 0;
CString token = tok.Tokenize("\n", curpos);
int line = 0;
bool centering=false;
if (m_LabelRotation != 0)
{
if (width != -2)
my_file.desired_rendition().font().rotation().set((int)(m_LabelRotation * 65536 / 360));
}
while( token != "" )
{
// invariant (ook bij binnenkomst): ptTxt.m_y bevat het linksonderpunt van de huidige regel
// uitgaande van l_fontheight. Bij [s] gebruik moeten we dus corrigeren
//CString f(token);
int skipextra = 0; // Extra skip bij underline
long size=100;
int thisLineHeight = l_fontheight; // mooie default
@@ -550,11 +550,6 @@ CSize CSLNKContourImpl::DrawOneLabel(WT_File &my_file,
else
thisLineHeight = myRound(double(size)*l_fontheight/100);
// Correctie op de invariant voor huidige regel
// De *eerste* regel moet je echter maar voor de aanroep opgelost hebben
if (line > 0)
ptTxt.m_y -= (thisLineHeight - l_fontheight);
if (width != -2)
my_file.desired_rendition().font().height() = thisLineHeight;
}
@@ -566,6 +561,8 @@ CSize CSLNKContourImpl::DrawOneLabel(WT_File &my_file,
if (token[0]==']') token.Delete(0); // Skip closing ]
}
tot_height += thisLineHeight;
if (width != -2) // Echt tekenen (lees: wegschrijven naar DWF)
{
int horoffset=0;
@@ -578,14 +575,19 @@ CSize CSLNKContourImpl::DrawOneLabel(WT_File &my_file,
}
WT_String txt;
if (WT_String::is_ascii(token.GetLength(), token))
// txt.set(f.GetLength(), f);
txt.set(token.GetLength(), token);
else
{ // Use UNICODE for example for Micha<68>l
CStringW s(token);
txt.set(s.GetLength(), s);
}
WT_Text my_text(WT_Logical_Point(ptTxt.m_x+horoffset, ptTxt.m_y), txt);
// Corrigeren van m_LabelRotation
double radian = - m_LabelRotation / 180.0 * PI;
int rdx = myRound(horoffset * cos(radian) - tot_height * sin(radian));
int rdy = myRound(tot_height * cos(radian) + horoffset * sin(radian));
WT_Text my_text(WT_Logical_Point(ptTxt.m_x + rdx, ptTxt.m_y - rdy), txt);
my_text.serialize(my_file);
// Altijd terug voor volgende regel
@@ -609,13 +611,15 @@ CSize CSLNKContourImpl::DrawOneLabel(WT_File &my_file,
max_width = max(max_width, MulDiv(rc.right,thisLineHeight,l_fontheight));
}
line ++;
/* Get next token: */
token = tok.Tokenize("\n", curpos);
ptTxt.m_y -= l_fontheight + skipextra;
tot_height += thisLineHeight;
tot_height += skipextra;
}
if (width != -2) // veilig terugzetten
my_file.desired_rendition().font().rotation().set(0);
return CSize(MulDiv(max_width,l_fontheight,FONT_SIZER), tot_height);
}