📄 tabfeaturepen.cpp
字号:
// tabfeaturepen.cpp: implementation of the TABFeaturePen class.////////////////////////////////////////////////////////////////////////#include "tabfeaturepen.h"#include "ugk_string.h"/********************************************************************** * TABFeaturePen::TABFeaturePen() **********************************************************************/TABFeaturePen::TABFeaturePen(){ static const TABPenDef csDefaultPen = MITAB_PEN_DEFAULT; m_nPenDefIndex=-1; m_sPenDef = csDefaultPen;}/********************************************************************** * TABFeaturePen::~TABFeaturePen() **********************************************************************/TABFeaturePen::~TABFeaturePen(){}/********************************************************************** * TABFeaturePen::GetPenWidthMIF() * TABFeaturePen::SetPenWidthMIF() * * The MIF representation for pen width is either a value from 1 to 7 * for a pen width in pixels, or a value from 11 to 2047 for a pen * width in points = 10 + (point_width*10) **********************************************************************/int TABFeaturePen::GetPenWidthMIF(){ return ( m_sPenDef.nPointWidth > 0? (m_sPenDef.nPointWidth+10): m_sPenDef.nPixelWidth );}void TABFeaturePen::SetPenWidthMIF(int val) { if (val > 10) { m_sPenDef.nPointWidth = MIN((val-10), 2037); m_sPenDef.nPixelWidth = 0; } else { m_sPenDef.nPixelWidth = (UGKByte)MIN(MAX(val, 1), 7); m_sPenDef.nPointWidth = 0; }}/********************************************************************** * TABFeaturePen::GetPenWidthPixel() * TABFeaturePen::SetPenWidthPixel() * TABFeaturePen::GetPenWidthPoint() * TABFeaturePen::SetPenWidthPoint() * * Pen width can be expressed in pixels (value from 1 to 7 pixels) or * in points (value from 0.1 to 203.7 points). The default pen width * in MapInfo is 1 pixel. Pen width in points exist only in file version 450. * * The following methods hide the way the pen width is stored in the files. * * In order to establish if a given pen def had its width specified in * pixels or in points, one should first call GetPenWidthPoint(), and if * it returns 0 then the Pixel width should be used instead: * if (GetPenWidthPoint() == 0) * ... use pen width in points ... * else * ... use Pixel width from GetPenWidthPixel() * * Note that the reverse is not true: the default pixel width is always 1, * even when the pen width was actually set in points. **********************************************************************/UGKByte TABFeaturePen::GetPenWidthPixel(){ return m_sPenDef.nPixelWidth;}void TABFeaturePen::SetPenWidthPixel(UGKByte val) { m_sPenDef.nPixelWidth = MIN(MAX(val, 1), 7); m_sPenDef.nPointWidth = 0;}double TABFeaturePen::GetPenWidthPoint(){ // We store point width internally as tenths of points return m_sPenDef.nPointWidth/10.0;}void TABFeaturePen::SetPenWidthPoint(double val) { m_sPenDef.nPointWidth = MAX(MIN(((int)(val*10)), 1), 2037); m_sPenDef.nPixelWidth = 1;}/********************************************************************** * ITABFeaturePen::GetPenStyleString() * * Return a PEN() string. All representations info for the pen are here. **********************************************************************/const char *TABFeaturePen::GetPenStyleString(){ const char *pszStyle = NULL; int nUGKStyle = 0; char szPattern[20]; szPattern[0] = '\0'; // For now, I only add the 25 first styles switch (GetPenPattern()) { case 1: nUGKStyle =1; break; case 2: nUGKStyle = 0; break; case 3: nUGKStyle = 3; strcpy(szPattern,"1 1"); break; case 4: nUGKStyle = 3; strcpy(szPattern,"2 1"); break; case 5: nUGKStyle = 3; strcpy(szPattern,"3 1"); break; case 6: nUGKStyle = 3; strcpy(szPattern,"6 1"); break; case 7: nUGKStyle = 4; strcpy(szPattern,"12 2"); break; case 8: nUGKStyle = 4; strcpy(szPattern,"24 4"); break; case 9: nUGKStyle = 3; strcpy(szPattern,"4 3"); break; case 10: nUGKStyle = 5; strcpy(szPattern,"1 4"); break; case 11: nUGKStyle = 3; strcpy(szPattern,"4 6"); break; case 12: nUGKStyle = 3; strcpy(szPattern,"6 4"); break; case 13: nUGKStyle = 4; strcpy(szPattern,"12 12"); break; case 14: nUGKStyle = 6; strcpy(szPattern,"8 2 1 2"); break; case 15: nUGKStyle = 6; strcpy(szPattern,"12 1 1 1"); break; case 16: nUGKStyle = 6; strcpy(szPattern,"12 1 3 1"); break; case 17: nUGKStyle = 6; strcpy(szPattern,"24 6 4 6"); break; case 18: nUGKStyle = 7; strcpy(szPattern,"24 3 3 3 3 3"); break; case 19: nUGKStyle = 7; strcpy(szPattern,"24 3 3 3 3 3 3 3"); break; case 20: nUGKStyle = 7; strcpy(szPattern,"6 3 1 3 1 3"); break; case 21: nUGKStyle = 7; strcpy(szPattern,"12 2 1 2 1 2"); break; case 22: nUGKStyle = 7; strcpy(szPattern,"12 2 1 2 1 2 1 2"); break; case 23: nUGKStyle = 6; strcpy(szPattern,"4 1 1 1"); break; case 24: nUGKStyle = 7; strcpy(szPattern,"4 1 1 1 1"); break; case 25: nUGKStyle = 6; strcpy(szPattern,"4 1 1 1 2 1 1 1"); break; default: nUGKStyle = 0; break; } if (strlen(szPattern) != 0) { if(m_sPenDef.nPointWidth > 0) pszStyle =UGKSPrintf("PEN(w:%dpt,c:#%6.6x,id:\"mapinfo-pen-%d." "ogr-pen-%d\",p:\"%spx\")", ((int)GetPenWidthPoint()), m_sPenDef.rgbColor,GetPenPattern(),nUGKStyle, szPattern); else pszStyle =UGKSPrintf("PEN(w:%dpx,c:#%6.6x,id:\"mapinfo-pen-%d." "ogr-pen-%d\",p:\"%spx\")", GetPenWidthPixel(), m_sPenDef.rgbColor,GetPenPattern(),nUGKStyle, szPattern); } else { if(m_sPenDef.nPointWidth > 0) pszStyle =UGKSPrintf("PEN(w:%dpt,c:#%6.6x,id:\"" "mapinfo-pen-%d.ogr-pen-%d\")", ((int)GetPenWidthPoint()), m_sPenDef.rgbColor,GetPenPattern(),nUGKStyle); else pszStyle =UGKSPrintf("PEN(w:%dpx,c:#%6.6x,id:\"" "mapinfo-pen-%d.ogr-pen-%d\")", GetPenWidthPixel(), m_sPenDef.rgbColor,GetPenPattern(),nUGKStyle); } return pszStyle;}/********************************************************************** * ITABFeaturePen::DumpPenDef() * * Dump pen definition information. **********************************************************************/void TABFeaturePen::DumpPenDef(FILE *fpOut /*=NULL*/){ if (fpOut == NULL) fpOut = stdout; fprintf(fpOut, " m_nPenDefIndex = %d\n", m_nPenDefIndex); fprintf(fpOut, " m_sPenDef.nRefCount = %d\n", m_sPenDef.nRefCount); fprintf(fpOut, " m_sPenDef.nPixelWidth = %d\n", m_sPenDef.nPixelWidth); fprintf(fpOut, " m_sPenDef.nLinePattern = %d\n", m_sPenDef.nLinePattern); fprintf(fpOut, " m_sPenDef.nPointWidth = %d\n", m_sPenDef.nPointWidth); fprintf(fpOut, " m_sPenDef.rgbColor = 0x%6.6x (%d)\n", m_sPenDef.rgbColor, m_sPenDef.rgbColor); fflush(fpOut);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -