📄 tabtext.cpp
字号:
pszNewline +=2; } double dHeight = GetTextBoxHeight()/numLines; // In all cases, take out 20% of font height to account for line spacing switch(GetTextSpacing()) { case TABTS1_5: dHeight *= (0.67 * 0.8); break; case TABTSDouble: dHeight *= (0.5 * 0.8); break; default: dHeight *= 0.8; } if (IsFontBGColorUsed()) pszStyle=UGKSPrintf("LABEL(t:\"%s\",a:%f,s:%fg,c:#%6.6x,b:#%6.6x,p:%d,f:\"%s\")", GetTextString(),GetTextAngle(), dHeight, GetFontFGColor(),GetFontBGColor(),nJustification, GetFontNameRef()); else pszStyle=UGKSPrintf("LABEL(t:\"%s\",a:%f,s:%fg,c:#%6.6x,p:%d,f:\"%s\")", GetTextString(),GetTextAngle(), dHeight, GetFontFGColor(),nJustification, GetFontNameRef()); return pszStyle; } /********************************************************************** * TABText::GetStyleString() * * Return style string for this feature. * * Style String is built only once during the first call to GetStyleString(). **********************************************************************/const char *TABText::GetStyleString(){ if (m_pszStyleString == NULL) { m_pszStyleString = UGKStrdup(GetLabelStyleString()); } return m_pszStyleString;}/********************************************************************** * TABText::DumpMIF() * * Dump feature geometry in a format similar to .MIF REGIONs. **********************************************************************/void TABText::DumpMIF(FILE *fpOut /*=NULL*/){ UGKGeometry *poGeom; UGKPoint *poPoint = NULL; if (fpOut == NULL) fpOut = stdout; /*----------------------------------------------------------------- * Fetch and validate geometry *----------------------------------------------------------------*/ poGeom = GetGeometryRef(); if (poGeom && wkbFlatten(poGeom->getGeometryType()) == wkbPoint) { /*------------------------------------------------------------- * Generate output for text object *------------------------------------------------------------*/ poPoint = (UGKPoint*)poGeom; fprintf(fpOut, "TEXT \"%s\" %g %g\n", m_pszString?m_pszString:"", poPoint->getX(), poPoint->getY()); fprintf(fpOut, " m_pszString = '%s'\n", m_pszString); fprintf(fpOut, " m_dAngle = %g\n", m_dAngle); fprintf(fpOut, " m_dHeight = %g\n", m_dHeight); fprintf(fpOut, " m_rgbForeground = 0x%6.6x (%d)\n", m_rgbForeground, m_rgbForeground); fprintf(fpOut, " m_rgbBackground = 0x%6.6x (%d)\n", m_rgbBackground, m_rgbBackground); fprintf(fpOut, " m_nTextAlignment = 0x%4.4x\n", m_nTextAlignment); fprintf(fpOut, " m_nFontStyle = 0x%4.4x\n", m_nFontStyle); } else { UGKError(ET_Failure, UGKErr_AssertionFailed, "TABText: Missing or Invalid Geometry!"); return; } // Finish with PEN/BRUSH/etc. clauses DumpPenDef(); DumpFontDef(); fflush(fpOut);}/********************************************************************** * TABText::ReadGeometryFromMIFFile **********************************************************************/int TABText::ReadGeometryFromMIFFile(MIDDATAFile *fp){ double dXMin, dYMin, dXMax, dYMax; UGKGeometry *poGeometry; const char *pszLine; char **papszToken; const char *pszString; papszToken = TokenizeString2(fp->GetLastLine(), " \t", 0x0001); if (CountOfList(papszToken) == 1) { FreeStrList(papszToken); papszToken = TokenizeString2(fp->GetLine(), " \t", 0x0001); if (CountOfList(papszToken) != 1) { FreeStrList(papszToken); return -1; } else pszString = papszToken[0]; } else if (CountOfList(papszToken) == 2) { pszString = papszToken[1]; } else { FreeStrList(papszToken); return -1; } /*------------------------------------------------------------- * Note: The text string may contain escaped "\n" chars, and we * return them in their escaped form. *------------------------------------------------------------*/ m_pszString = UGKStrdup(pszString); FreeStrList(papszToken); papszToken = TokenizeString2(fp->GetLine(), " \t", 0x0001); if (CountOfList(papszToken) != 4) { FreeStrList(papszToken); return -1; } else { dXMin = fp->GetXTrans(atof(papszToken[0])); dXMax = fp->GetXTrans(atof(papszToken[2])); dYMin = fp->GetYTrans(atof(papszToken[1])); dYMax = fp->GetYTrans(atof(papszToken[3])); m_dHeight = dYMax - dYMin; //SetTextBoxHeight(dYMax - dYMin); m_dWidth = dXMax - dXMin; //SetTextBoxWidth(dXMax - dXMin); if (m_dHeight <0.0) m_dHeight*=-1.0; if (m_dWidth <0.0) m_dWidth*=-1.0; } FreeStrList(papszToken); papszToken = NULL; /* Set/retrieve the MBR to make sure Mins are smaller than Maxs */ SetMBR(dXMin, dYMin, dXMax, dYMax); GetMBR(dXMin, dYMin, dXMax, dYMax); while (((pszLine = fp->GetLine()) != NULL) && fp->IsValidFeature(pszLine) == FALSE) { papszToken = TokenizeStringComplex(pszLine,"() ,", TRUE,FALSE); if (CountOfList(papszToken) > 1) { if (EQUALN(papszToken[0],"FONT",4)) { if (CountOfList(papszToken) >= 5) { SetFontName(papszToken[1]); SetFontFGColor(atoi(papszToken[4])); if (CountOfList(papszToken) ==6) { SetFontBGColor(atoi(papszToken[5])); SetFontStyleMIFValue(atoi(papszToken[2]),TRUE); } else SetFontStyleMIFValue(atoi(papszToken[2])); // papsztoken[3] = Size ??? } } else if (EQUALN(papszToken[0],"SPACING",7)) { if (CountOfList(papszToken) >= 2) { if (EQUALN(papszToken[1],"2",1)) { SetTextSpacing(TABTSDouble); } else if (EQUALN(papszToken[1],"1.5",3)) { SetTextSpacing(TABTS1_5); } } if (CountOfList(papszToken) == 7) { if (EQUALN(papszToken[2],"LAbel",5)) { if (EQUALN(papszToken[4],"simple",6)) { SetTextLineType(TABTLSimple); SetTextLineEndPoint(fp->GetXTrans(atof(papszToken[5])), fp->GetYTrans(atof(papszToken[6]))); } else if (EQUALN(papszToken[4],"arrow", 5)) { SetTextLineType(TABTLArrow); SetTextLineEndPoint(fp->GetXTrans(atof(papszToken[5])), fp->GetYTrans(atof(papszToken[6]))); } } } } else if (EQUALN(papszToken[0],"Justify",7)) { if (CountOfList(papszToken) == 2) { if (EQUALN( papszToken[1],"Center",6)) { SetTextJustification(TABTJCenter); } else if (EQUALN( papszToken[1],"Right",5)) { SetTextJustification(TABTJRight); } } } else if (EQUALN(papszToken[0],"Angle",5)) { if (CountOfList(papszToken) == 2) { SetTextAngle(atof(papszToken[1])); } } else if (EQUALN(papszToken[0],"LAbel",5)) { if (CountOfList(papszToken) == 5) { if (EQUALN(papszToken[2],"simple",6)) { SetTextLineType(TABTLSimple); SetTextLineEndPoint(fp->GetXTrans(atof(papszToken[3])), fp->GetYTrans(atof(papszToken[4]))); } else if (EQUALN(papszToken[2],"arrow", 5)) { SetTextLineType(TABTLArrow); SetTextLineEndPoint(fp->GetXTrans(atof(papszToken[3])), fp->GetYTrans(atof(papszToken[4]))); } } // What I do with the XY coordonate } } FreeStrList(papszToken); papszToken = NULL; } /*----------------------------------------------------------------- * Create an UGKPoint Geometry... * The point X,Y values will be the coords of the lower-left corner before * rotation is applied. (Note that the rotation in MapInfo is done around * the upper-left corner) * We need to calculate the true lower left corner of the text based * on the MBR after rotation, the text height and the rotation angle. *---------------------------------------------------------------- */ double dCos, dSin, dX, dY; dSin = sin(m_dAngle*PI/180.0); dCos = cos(m_dAngle*PI/180.0); if (dSin > 0.0 && dCos > 0.0) { dX = dXMin + m_dHeight * dSin; dY = dYMin; } else if (dSin > 0.0 && dCos < 0.0) { dX = dXMax; dY = dYMin - m_dHeight * dCos; } else if (dSin < 0.0 && dCos < 0.0) { dX = dXMax + m_dHeight * dSin; dY = dYMax; } else // dSin < 0 && dCos > 0 { dX = dXMin; dY = dYMax - m_dHeight * dCos; } poGeometry = new UGKPoint(dX, dY); SetGeometryDirectly(poGeometry); /*----------------------------------------------------------------- * Compute Text Width: the width of the Text MBR before rotation * in ground units... unfortunately this value is not stored in the * file, so we have to compute it with the MBR after rotation and * the height of the MBR before rotation: * With W = Width of MBR before rotation * H = Height of MBR before rotation * dX = Width of MBR after rotation * dY = Height of MBR after rotation * teta = rotation angle * * For [-PI/4..teta..+PI/4] or [3*PI/4..teta..5*PI/4], we'll use: * W = H * (dX - H * sin(teta)) / (H * cos(teta)) * * and for other teta values, use: * W = H * (dY - H * cos(teta)) / (H * sin(teta)) *---------------------------------------------------------------- */ dSin = ABS(dSin); dCos = ABS(dCos); if (m_dHeight == 0.0) m_dWidth = 0.0; else if ( dCos > dSin ) m_dWidth = m_dHeight * ((dXMax-dXMin) - m_dHeight*dSin) / (m_dHeight*dCos); else m_dWidth = m_dHeight * ((dYMax-dYMin) - m_dHeight*dCos) / (m_dHeight*dSin); m_dWidth = ABS(m_dWidth); return 0; }/********************************************************************** * **********************************************************************/int TABText::WriteGeometryToMIFFile(MIDDATAFile *fp){ double dXMin,dYMin,dXMax,dYMax; /*------------------------------------------------------------- * Note: The text string may contain "\n" chars or "\\" chars * and we expect to receive them in an escaped form. *------------------------------------------------------------*/ fp->WriteLine("Text \"%s\"\n", GetTextString() ); // UpdateTextMBR(); GetMBR(dXMin, dYMin, dXMax, dYMax); fp->WriteLine(" %.16g %.16g %.16g %.16g\n",dXMin, dYMin,dXMax, dYMax); if (IsFontBGColorUsed()) fp->WriteLine(" Font (\"%s\",%d,%d,%d,%d)\n", GetFontNameRef(), GetFontStyleMIFValue(),0,GetFontFGColor(), GetFontBGColor()); else fp->WriteLine(" Font (\"%s\",%d,%d,%d)\n", GetFontNameRef(), GetFontStyleMIFValue(),0,GetFontFGColor()); switch (GetTextSpacing()) { case TABTS1_5: fp->WriteLine(" Spacing 1.5\n"); break; case TABTSDouble: fp->WriteLine(" Spacing 2.0\n"); break; case TABTSSingle: default: break; } switch (GetTextJustification()) { case TABTJCenter: fp->WriteLine(" Justify Center\n"); break; case TABTJRight: fp->WriteLine(" Justify Right\n"); break; case TABTJLeft: default: break; } if (ABS(GetTextAngle()) > 0.000001) fp->WriteLine(" Angle %.16g\n",GetTextAngle()); switch (GetTextLineType()) { case TABTLSimple: if (m_bLineEndSet) fp->WriteLine(" Label Line Simple %.16g %.16g \n", m_dfLineEndX, m_dfLineEndY ); break; case TABTLArrow: if (m_bLineEndSet) fp->WriteLine(" Label Line Arrow %.16g %.16g \n", m_dfLineEndX, m_dfLineEndY ); break; case TABTLNoLine: default: break; } return 0; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -