📄 tabtext.cpp
字号:
GetMBR(dXMin, dYMin, dXMax, dYMax); poMapFile->Coordsys2Int(dXMin, dYMin, nXMin, nYMin); poMapFile->Coordsys2Int(dXMax, dYMax, nXMax, nYMax); // Label line end point double dX, dY; GetTextLineEndPoint(dX, dY); // Make sure a default line end point is set poMapFile->Coordsys2Int(m_dfLineEndX, m_dfLineEndY, poTextHdr->m_nLineEndX, poTextHdr->m_nLineEndY); // Text Height poMapFile->Coordsys2IntDist(0.0, m_dHeight, nX, nY); poTextHdr->m_nHeight = nY; // Font name m_nFontDefIndex = poMapFile->WriteFontDef(&m_sFontDef); poTextHdr->m_nFontId = m_nFontDefIndex; // Font name index // MBR after rotation poTextHdr->SetMBR(nXMin, nYMin, nXMax, nYMax); m_nPenDefIndex = poMapFile->WritePenDef(&m_sPenDef); poTextHdr->m_nPenId = m_nPenDefIndex; // Pen index for line/arrow if (UGKGetLastErrorNo() != 0) return -1; return 0;}/********************************************************************** * TABText::GetTextString() * * Return ref to text string value. * * Returned string is a reference to the internal string buffer and should * not be modified or freed by the caller. **********************************************************************/const char *TABText::GetTextString(){ if (m_pszString == NULL) return ""; return m_pszString;}/********************************************************************** * TABText::SetTextString() * * Set new text string value. * * Note: The text string may contain "\n" chars or "\\" chars * and we expect to receive them in a 2 chars escaped form as * described in the MIF format specs. **********************************************************************/void TABText::SetTextString(const char *pszNewStr){ UGK_Free(m_pszString); m_pszString = UGKStrdup(pszNewStr);}/********************************************************************** * TABText::GetTextAngle() * * Return text angle in degrees. **********************************************************************/double TABText::GetTextAngle(){ return m_dAngle;}void TABText::SetTextAngle(double dAngle){ // Make sure angle is in the range [0..360] while(dAngle < 0.0) dAngle += 360.0; while(dAngle > 360.0) dAngle -= 360.0; m_dAngle = dAngle; UpdateTextMBR();}/********************************************************************** * TABText::GetTextBoxHeight() * * Return text height in Y axis coord. units of the text box before rotation. **********************************************************************/double TABText::GetTextBoxHeight(){ return m_dHeight;}void TABText::SetTextBoxHeight(double dHeight){ m_dHeight = dHeight; UpdateTextMBR();}/********************************************************************** * TABText::GetTextBoxWidth() * * Return text width in X axis coord. units. of the text box before rotation. * * If value has not been set, then we force a default value that assumes * that one char's box width is 60% of its height... and we ignore * the multiline case. This should not matter when the user PROPERLY sets * the value. **********************************************************************/double TABText::GetTextBoxWidth(){ if (m_dWidth == 0.0 && m_pszString) { m_dWidth = 0.6 * m_dHeight * strlen(m_pszString); } return m_dWidth;}void TABText::SetTextBoxWidth(double dWidth){ m_dWidth = dWidth; UpdateTextMBR();}/********************************************************************** * TABText::GetTextLineEndPoint() * * Return X,Y coordinates of the text label line end point. * Default is the center of the text MBR. **********************************************************************/void TABText::GetTextLineEndPoint(double &dX, double &dY){ if (!m_bLineEndSet) { // Set default location at center of text MBR double dXMin, dYMin, dXMax, dYMax; UpdateTextMBR(); GetMBR(dXMin, dYMin, dXMax, dYMax); m_dfLineEndX = (dXMin + dXMax) /2.0; m_dfLineEndY = (dYMin + dYMax) /2.0; m_bLineEndSet = TRUE; } // Return values dX = m_dfLineEndX; dY = m_dfLineEndY;}void TABText::SetTextLineEndPoint(double dX, double dY){ m_dfLineEndX = dX; m_dfLineEndY = dY; m_bLineEndSet = TRUE;}/********************************************************************** * TABText::UpdateTextMBR() * * Update the feature MBR using the text origin (UGKPoint geometry), the * rotation angle, and the Width/height before rotation. * * This function cannot perform properly unless all the above have been set. **********************************************************************/void TABText::UpdateTextMBR(){ UGKGeometry *poGeom; UGKPoint *poPoint=NULL; poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) { double dSin, dCos, dX0, dY0, dX1, dY1; double dX[4], dY[4]; poPoint = (UGKPoint *)poGeom; dX0 = poPoint->getX(); dY0 = poPoint->getY(); dSin = sin(m_dAngle*PI/180.0); dCos = cos(m_dAngle*PI/180.0); GetTextBoxWidth(); // Force default width value if necessary. dX[0] = dX0; dY[0] = dY0; dX[1] = dX0 + m_dWidth; dY[1] = dY0; dX[2] = dX0 + m_dWidth; dY[2] = dY0 + m_dHeight; dX[3] = dX0; dY[3] = dY0 + m_dHeight; SetMBR(dX0, dY0, dX0, dY0); for(int i=0; i<4; i++) { // Rotate one of the box corners dX1 = dX0 + (dX[i]-dX0)*dCos - (dY[i]-dY0)*dSin; dY1 = dY0 + (dX[i]-dX0)*dSin + (dY[i]-dY0)*dCos; // And update feature MBR with rotated coordinate if (dX1 < m_dXMin) m_dXMin = dX1; if (dX1 > m_dXMax) m_dXMax = dX1; if (dY1 < m_dYMin) m_dYMin = dY1; if (dY1 > m_dYMax) m_dYMax = dY1; } }}/********************************************************************** * TABText::GetFontBGColor() * * Return background color. **********************************************************************/UGKInt32 TABText::GetFontBGColor(){ return m_rgbBackground;}void TABText::SetFontBGColor(UGKInt32 rgbColor){ m_rgbBackground = rgbColor;}/********************************************************************** * TABText::GetFontFGColor() * * Return foreground color. **********************************************************************/UGKInt32 TABText::GetFontFGColor(){ return m_rgbForeground;}void TABText::SetFontFGColor(UGKInt32 rgbColor){ m_rgbForeground = rgbColor;}/********************************************************************** * TABText::GetTextJustification() * * Return text justification. Default is TABTJLeft **********************************************************************/TABTextJust TABText::GetTextJustification(){ TABTextJust eJust = TABTJLeft; if (m_nTextAlignment & 0x0200) eJust = TABTJCenter; else if (m_nTextAlignment & 0x0400) eJust = TABTJRight; return eJust;}void TABText::SetTextJustification(TABTextJust eJustification){ // Flush current value... default is TABTJLeft m_nTextAlignment &= ~ 0x0600; // ... and set new one. if (eJustification == TABTJCenter) m_nTextAlignment |= 0x0200; else if (eJustification == TABTJRight) m_nTextAlignment |= 0x0400;}/********************************************************************** * TABText::GetTextSpacing() * * Return text vertical spacing factor. Default is TABTSSingle **********************************************************************/TABTextSpacing TABText::GetTextSpacing(){ TABTextSpacing eSpacing = TABTSSingle; if (m_nTextAlignment & 0x0800) eSpacing = TABTS1_5; else if (m_nTextAlignment & 0x1000) eSpacing = TABTSDouble; return eSpacing;}void TABText::SetTextSpacing(TABTextSpacing eSpacing){ // Flush current value... default is TABTSSingle m_nTextAlignment &= ~ 0x1800; // ... and set new one. if (eSpacing == TABTS1_5) m_nTextAlignment |= 0x0800; else if (eSpacing == TABTSDouble) m_nTextAlignment |= 0x1000;}/********************************************************************** * TABText::GetTextLineType() * * Return text line (arrow) type. Default is TABTLNoLine **********************************************************************/TABTextLineType TABText::GetTextLineType(){ TABTextLineType eLine = TABTLNoLine; if (m_nTextAlignment & 0x2000) eLine = TABTLSimple; else if (m_nTextAlignment & 0x4000) eLine = TABTLArrow; return eLine;}void TABText::SetTextLineType(TABTextLineType eLineType){ // Flush current value... default is TABTLNoLine m_nTextAlignment &= ~ 0x6000; // ... and set new one. if (eLineType == TABTLSimple) m_nTextAlignment |= 0x2000; else if (eLineType == TABTLArrow) m_nTextAlignment |= 0x4000;}/********************************************************************** * TABText::QueryFontStyle() * * Return TRUE if the specified font style attribute is turned ON, * or FALSE otherwise. See enum TABFontStyle for the list of styles * that can be queried on. **********************************************************************/UGKBool TABText::QueryFontStyle(TABFontStyle eStyleToQuery){ return (m_nFontStyle & (int)eStyleToQuery) ? TRUE: FALSE;}void TABText::ToggleFontStyle(TABFontStyle eStyleToToggle, UGKBool bStyleOn){ if (bStyleOn) m_nFontStyle |= (int)eStyleToToggle; else m_nFontStyle &= ~ (int)eStyleToToggle;}/********************************************************************** * TABText::GetFontStyleMIFValue() * * Return the Font Style value for this object using the style values * that are used in a MIF FONT() clause. See MIF specs (appendix A). * * The reason why we have to differentiate between the TAB and the MIF font * style values is that in TAB, TABFSBox is included in the style value * as code 0x100, but in MIF it is not included, instead it is implied by * the presence of the BG color in the FONT() clause (the BG color is * present only when TABFSBox or TABFSHalo is set). * This also has the effect of shifting all the other style values > 0x100 * by 1 byte. **********************************************************************/int TABText::GetFontStyleMIFValue(){ // The conversion is simply to remove bit 0x100 from the value and shift // down all values past this bit. return (m_nFontStyle & 0xff) + (m_nFontStyle & (0xff00-0x0100))/2;}void TABText:: SetFontStyleMIFValue(int nStyle, UGKBool bBGColorSet){ m_nFontStyle = (nStyle & 0xff) + (nStyle & 0x7f00)*2; // When BG color is set, then either BOX or HALO should be set. if (bBGColorSet && !QueryFontStyle(TABFSHalo)) ToggleFontStyle(TABFSBox, TRUE);}int TABText::IsFontBGColorUsed(){ // Font BG color is used only when BOX or HALO are set. return (QueryFontStyle(TABFSBox) || QueryFontStyle(TABFSHalo));}/********************************************************************** * TABText::GetLabelStyleString() * * This is not the correct location, it should be in ITABFeatureFont, * but it's really more easy to put it here. This fct return a complete * string for the representation with the string to display **********************************************************************/const char *TABText::GetLabelStyleString(){ const char *pszStyle = NULL; char szPattern[20]; int nJustification = 1; szPattern[0] = '\0'; switch(GetTextJustification()) { case TABTJCenter: nJustification = 2; break; case TABTJRight: nJustification = 1; break; case TABTJLeft: default: nJustification =1; break; } // Compute real font size, taking number of lines ("\\n") and line // spacing into account. int numLines = 1; const char *pszNewline = GetTextString(); while((pszNewline = strstr(pszNewline, "\\n")) != NULL) { numLines++;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -