📄 tabtooldeftable.cpp
字号:
// TABToolDefTable.cpp: implementation of the TABToolDefTable class.////////////////////////////////////////////////////////////////////////#include "tabtooldeftable.h"#include "ugk_errhandle.h"#include "ugk_memopr.h"/********************************************************************** * TABToolDefTable::TABToolDefTable() * * Constructor. **********************************************************************/TABToolDefTable::TABToolDefTable(){ m_papsPen = NULL; m_papsBrush = NULL; m_papsFont = NULL; m_papsSymbol = NULL; m_numPen = 0; m_numBrushes = 0; m_numFonts = 0; m_numSymbols = 0; m_numAllocatedPen = 0; m_numAllocatedBrushes = 0; m_numAllocatedFonts = 0; m_numAllocatedSymbols = 0;}/********************************************************************** * TABToolDefTable::~TABToolDefTable() * * Destructor. **********************************************************************/TABToolDefTable::~TABToolDefTable(){ int i; for(i=0; m_papsPen && i < m_numPen; i++) UGK_Free(m_papsPen[i]); UGK_Free(m_papsPen); for(i=0; m_papsBrush && i < m_numBrushes; i++) UGK_Free(m_papsBrush[i]); UGK_Free(m_papsBrush); for(i=0; m_papsFont && i < m_numFonts; i++) UGK_Free(m_papsFont[i]); UGK_Free(m_papsFont); for(i=0; m_papsSymbol && i < m_numSymbols; i++) UGK_Free(m_papsSymbol[i]); UGK_Free(m_papsSymbol);}/********************************************************************** * TABToolDefTable::ReadAllToolDefs() * * Read all tool definition blocks until we reach the end of the chain. * This function will be called only once per dataset, after that * we keep all the tool definitions in memory. * * Returns 0 on success, -1 on error. **********************************************************************/int TABToolDefTable::ReadAllToolDefs(TABMAPToolBlock *poBlock){ int nStatus = 0; int nDefType; /*----------------------------------------------------------------- * Loop until we reach the end of the chain of blocks... we assume * that the first block of data is already pre-loaded. *----------------------------------------------------------------*/ while( ! poBlock->EndOfChain() ) { nDefType = poBlock->ReadByte(); switch(nDefType) { case TABMAP_TOOL_PEN: // PEN if (m_numPen >= m_numAllocatedPen) { // Realloc array by blocks of 20 items m_numAllocatedPen += 20; m_papsPen = (TABPenDef**)UGK_Realloc(m_papsPen, m_numAllocatedPen*sizeof(TABPenDef*)); } m_papsPen[m_numPen] = (TABPenDef*)UGK_Calloc(1, sizeof(TABPenDef)); m_papsPen[m_numPen]->nRefCount = poBlock->ReadInt32(); m_papsPen[m_numPen]->nPixelWidth = poBlock->ReadByte(); m_papsPen[m_numPen]->nLinePattern = poBlock->ReadByte(); m_papsPen[m_numPen]->nPointWidth = poBlock->ReadByte(); m_papsPen[m_numPen]->rgbColor = poBlock->ReadByte()*256*256+ poBlock->ReadByte()*256 + poBlock->ReadByte(); // Adjust width value... // High bits for point width values > 255 are stored in the // pixel width byte if (m_papsPen[m_numPen]->nPixelWidth > 7) { m_papsPen[m_numPen]->nPointWidth += (m_papsPen[m_numPen]->nPixelWidth-8)*0x100; m_papsPen[m_numPen]->nPixelWidth = 1; } m_numPen++; break; case TABMAP_TOOL_BRUSH: // BRUSH if (m_numBrushes >= m_numAllocatedBrushes) { // Realloc array by blocks of 20 items m_numAllocatedBrushes += 20; m_papsBrush = (TABBrushDef**)UGK_Realloc(m_papsBrush, m_numAllocatedBrushes*sizeof(TABBrushDef*)); } m_papsBrush[m_numBrushes] = (TABBrushDef*)UGK_Calloc(1,sizeof(TABBrushDef)); m_papsBrush[m_numBrushes]->nRefCount = poBlock->ReadInt32(); m_papsBrush[m_numBrushes]->nFillPattern = poBlock->ReadByte(); m_papsBrush[m_numBrushes]->bTransparentFill = poBlock->ReadByte(); m_papsBrush[m_numBrushes]->rgbFGColor =poBlock->ReadByte()*256*256+ poBlock->ReadByte()*256 + poBlock->ReadByte(); m_papsBrush[m_numBrushes]->rgbBGColor =poBlock->ReadByte()*256*256+ poBlock->ReadByte()*256 + poBlock->ReadByte(); m_numBrushes++; break; case TABMAP_TOOL_FONT: // FONT NAME if (m_numFonts >= m_numAllocatedFonts) { // Realloc array by blocks of 20 items m_numAllocatedFonts += 20; m_papsFont = (TABFontDef**)UGK_Realloc(m_papsFont, m_numAllocatedFonts*sizeof(TABFontDef*)); } m_papsFont[m_numFonts] = (TABFontDef*)UGK_Calloc(1,sizeof(TABFontDef)); m_papsFont[m_numFonts]->nRefCount = poBlock->ReadInt32(); poBlock->ReadBytes(32, (UGKByte*)m_papsFont[m_numFonts]->szFontName); m_papsFont[m_numFonts]->szFontName[32] = '\0'; m_numFonts++; break; case TABMAP_TOOL_SYMBOL: // SYMBOL if (m_numSymbols >= m_numAllocatedSymbols) { // Realloc array by blocks of 20 items m_numAllocatedSymbols += 20; m_papsSymbol = (TABSymbolDef**)UGK_Realloc(m_papsSymbol, m_numAllocatedSymbols*sizeof(TABSymbolDef*)); } m_papsSymbol[m_numSymbols] = (TABSymbolDef*)UGK_Calloc(1,sizeof(TABSymbolDef)); m_papsSymbol[m_numSymbols]->nRefCount = poBlock->ReadInt32(); m_papsSymbol[m_numSymbols]->nSymbolNo = poBlock->ReadInt16(); m_papsSymbol[m_numSymbols]->nPointSize = poBlock->ReadInt16(); m_papsSymbol[m_numSymbols]->_nUnknownValue_ = poBlock->ReadByte(); m_papsSymbol[m_numSymbols]->rgbColor = poBlock->ReadByte()*256*256+ poBlock->ReadByte()*256 + poBlock->ReadByte(); m_numSymbols++; break; default: /* Unsupported Tool type!!! */ UGKError(ET_Failure, UGKErr_NotSupported, "Unsupported drawing tool type: `%d'", nDefType); nStatus = -1; } if (UGKGetLastErrorNo() != 0) { // An error happened reading this tool definition... stop now. nStatus = -1; } } return nStatus;}/********************************************************************** * TABToolDefTable::WriteAllToolDefs() * * Write all tool definition structures to the TABMAPToolBlock. * * Note that at the end of this call, poBlock->CommitToFile() will have * been called. * * Returns 0 on success, -1 on error. **********************************************************************/int TABToolDefTable::WriteAllToolDefs(TABMAPToolBlock *poBlock){ int i, nStatus = 0; /*----------------------------------------------------------------- * Write Pen Defs *----------------------------------------------------------------*/ for(i=0; nStatus == 0 && i< m_numPen; i++) { // The pen width is encoded over 2 bytes UGKByte byPixelWidth=1, byPointWidth=0; if (m_papsPen[i]->nPointWidth > 0) { byPointWidth = (UGKByte)(m_papsPen[i]->nPointWidth & 0xff); if (m_papsPen[i]->nPointWidth > 255) byPixelWidth = 8 + (UGKByte)(m_papsPen[i]->nPointWidth/0x100); } else byPixelWidth = MIN(MAX(m_papsPen[i]->nPixelWidth, 1), 7); poBlock->CheckAvailableSpace(TABMAP_TOOL_PEN); poBlock->WriteByte(TABMAP_TOOL_PEN); // Def Type = Pen poBlock->WriteInt32(m_papsPen[i]->nRefCount); poBlock->WriteByte(byPixelWidth); poBlock->WriteByte(m_papsPen[i]->nLinePattern); poBlock->WriteByte(byPointWidth); poBlock->WriteByte(COLOR_R(m_papsPen[i]->rgbColor)); poBlock->WriteByte(COLOR_G(m_papsPen[i]->rgbColor)); poBlock->WriteByte(COLOR_B(m_papsPen[i]->rgbColor)); if (UGKGetLastErrorNo() != 0) { // An error happened reading this tool definition... stop now. nStatus = -1; } } /*----------------------------------------------------------------- * Write Brush Defs *----------------------------------------------------------------*/ for(i=0; nStatus == 0 && i< m_numBrushes; i++) { poBlock->CheckAvailableSpace(TABMAP_TOOL_BRUSH); poBlock->WriteByte(TABMAP_TOOL_BRUSH); // Def Type = Brush poBlock->WriteInt32(m_papsBrush[i]->nRefCount); poBlock->WriteByte(m_papsBrush[i]->nFillPattern); poBlock->WriteByte(m_papsBrush[i]->bTransparentFill); poBlock->WriteByte(COLOR_R(m_papsBrush[i]->rgbFGColor)); poBlock->WriteByte(COLOR_G(m_papsBrush[i]->rgbFGColor)); poBlock->WriteByte(COLOR_B(m_papsBrush[i]->rgbFGColor)); poBlock->WriteByte(COLOR_R(m_papsBrush[i]->rgbBGColor)); poBlock->WriteByte(COLOR_G(m_papsBrush[i]->rgbBGColor)); poBlock->WriteByte(COLOR_B(m_papsBrush[i]->rgbBGColor)); if (UGKGetLastErrorNo() != 0) { // An error happened reading this tool definition... stop now. nStatus = -1; } } /*----------------------------------------------------------------- * Write Font Defs *----------------------------------------------------------------*/ for(i=0; nStatus == 0 && i< m_numFonts; i++) { poBlock->CheckAvailableSpace(TABMAP_TOOL_FONT); poBlock->WriteByte(TABMAP_TOOL_FONT); // Def Type = Font name poBlock->WriteInt32(m_papsFont[i]->nRefCount); poBlock->WriteBytes(32, (UGKByte*)m_papsFont[i]->szFontName); if (UGKGetLastErrorNo() != 0) { // An error happened reading this tool definition... stop now. nStatus = -1; } } /*----------------------------------------------------------------- * Write Symbol Defs *----------------------------------------------------------------*/ for(i=0; nStatus == 0 && i< m_numSymbols; i++) { poBlock->CheckAvailableSpace(TABMAP_TOOL_SYMBOL); poBlock->WriteByte(TABMAP_TOOL_SYMBOL); // Def Type = Symbol poBlock->WriteInt32(m_papsSymbol[i]->nRefCount); poBlock->WriteInt16(m_papsSymbol[i]->nSymbolNo); poBlock->WriteInt16(m_papsSymbol[i]->nPointSize); poBlock->WriteByte(m_papsSymbol[i]->_nUnknownValue_); poBlock->WriteByte(COLOR_R(m_papsSymbol[i]->rgbColor)); poBlock->WriteByte(COLOR_G(m_papsSymbol[i]->rgbColor)); poBlock->WriteByte(COLOR_B(m_papsSymbol[i]->rgbColor)); if (UGKGetLastErrorNo() != 0) { // An error happened reading this tool definition... stop now. nStatus = -1; } } if (nStatus == 0) nStatus = poBlock->CommitToFile(); return nStatus;}/********************************************************************** * TABToolDefTable::GetNumPen() * * Return the number of valid pen indexes for this .MAP file **********************************************************************/int TABToolDefTable::GetNumPen(){ return m_numPen;}/********************************************************************** * TABToolDefTable::GetPenDefRef() * * Return a reference to the specified Pen tool definition, or NULL if * specified index is invalid. * * Note that nIndex is a 1-based index. A value of 0 indicates "none" * in MapInfo. **********************************************************************/TABPenDef *TABToolDefTable::GetPenDefRef(int nIndex){ if (nIndex >0 && nIndex <= m_numPen) return m_papsPen[nIndex-1]; return NULL;}/********************************************************************** * TABToolDefTable::AddPenDefRef() * * Either create a new PenDefRef or add a reference to an existing one. * * Return the pen index that has been attributed to this Pen tool * definition, or -1 if something went wrong * * Note that nIndex is a 1-based index. A value of 0 indicates "none" * in MapInfo. **********************************************************************/int TABToolDefTable::AddPenDefRef(TABPenDef *poNewPenDef){ int i, nNewPenIndex = 0; TABPenDef *poDef; if (poNewPenDef == NULL) return -1; /*----------------------------------------------------------------- * Check for "none" case: pattern = 0 (pattern 0 does not exist!) *----------------------------------------------------------------*/ if (poNewPenDef->nLinePattern < 1) return 0; /*----------------------------------------------------------------- * Start by searching the list of existing pens *----------------------------------------------------------------*/ for (i=0; nNewPenIndex == 0 && i<m_numPen; i++) { poDef = m_papsPen[i];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -