Beispiel #1
0
void 
MenuTexture::SetString( )
{
  // LOGI("Menu Texture set string: <%s> %dx%d stride %d bpp %d", menu_str, width, height, stride, bpp );
  // LOGI("Menu Texture set string: <%s> len %d", menu_str, len );

  CharMap * chars = CharMap::Instance();

  int len = strlen( menu_str );

  memset( texData, 0xff, stride * height );
  int xoff = 0;
  for ( int k=0; k<len && xoff+WIDTH*bpp<=stride; ++k) {
    unsigned char * shape = chars->Shape( menu_str[k] );
    for (unsigned char m = 0x80; m > 0; m>>=1) {
      unsigned char * off = texData + xoff;
      for ( int j=0; j<HEIGHT; ++j ) {
        if ( (m & shape[ j ]) == m ) {
          memset( off, 0, bpp );
          off[bpp-1] = 0xff;
        }
        off += stride;
      }
      xoff += bpp;
    }
    xoff += 2 * bpp;
  }
  // InitTexture(); // do not initailize here: makes a black rectangle
}
Beispiel #2
0
CharMap::CharMap(const CharMap &other)
{
	for (std::list<CodePage *>::const_iterator it = other.CBegin();
		it != other.CEnd(); ++it) {
		m_map.push_back(new CodePage(**it));
	}
}
Beispiel #3
0
void 
StationTexture::AddStation( int k, const char * str )
{
  if ( k >= nStation ) return;
  int col = k % COLS;
  int row = k / COLS;
  int len = (length < strlen( str ))? length : strlen(str);

  float h = 1.0f / rows;
  float lw = len * (1.0f / (length * COLS));
  float cw = col * (1.0f / COLS);
  int k20 = k*20;
  int k4  = k*4;
  int k6  = k*6;
  vertex[ k20     + 3 ] = cw;           // (0) ---------- (1) k
  vertex[ k20     + 4 ] = (row+1) * h;  //  |              |
  vertex[ k20 + 5 + 3 ] = cw + lw;      // (2) ---------- (3) k+1
  vertex[ k20 + 5 + 4 ] = (row+1) * h;
  vertex[ k20 +10 + 3 ] = cw;
  vertex[ k20 +10 + 4 ] = (row+0) * h;
  vertex[ k20 +15 + 3 ] = cw + lw;
  vertex[ k20 +15 + 4 ] = (row+0) * h;
  // geom coords are not initialized

  index[k6 + 0] = k4 + 0;
  index[k6 + 1] = k4 + 2;
  index[k6 + 2] = k4 + 1;
  index[k6 + 3] = k4 + 1;
  index[k6 + 4] = k4 + 2;
  index[k6 + 5] = k4 + 3;

  CharMap * chars = CharMap::Instance();
  int xoff = name_stride  * col;
  int yoff = table_stride * row * HEIGHT;
  for ( int k1=0; k1<len; ++k1) {
    unsigned char * shape = chars->Shape( str[k1] );
    for (unsigned char m = 0x80; m > 0; m>>=1) {
      unsigned char * off = texData + yoff + xoff;
      for ( int j=0; j<HEIGHT; ++j ) {
        if ( (m & shape[ j ]) == m ) {
          memset( off, 0, bpp );
          off[0] = 0xff;
          off[bpp-1] = 0xff;
        }
        off += table_stride;
      }
      xoff += bpp;
    }
    xoff += 2 * bpp; // two empty pixel after each char
  }
}
Beispiel #4
0
void removeDuplicates(Node* head) {
  CharMap map;
  Node* n = head;
  do {
    map[n->val]++;
    n = n->next;
  } while(n);


  for(CharMap::const_iterator it = map.begin(); it != map.end(); ++it) {
    int cnt = it->second;
    while(cnt > 1) {
      head = removeNode(head, it->first);
      --cnt;
    }
  }
}
Beispiel #5
0
    bool exist(vector<vector<char>>& board, string word)
    {
        if(board.empty() || board[0].empty())
        {
            return false;
        }

        int row = board.size();
        int col = board[0].size();

        typedef std::unordered_map<char, std::vector<std::pair<int,int>>> CharMap;

        CharMap charMap;
        for(int i = 0; i < board.size(); ++i)
        {
            for(int j = 0; j < board[i].size(); ++j)
            {
                char c = board[i][j];
                if(charMap.find(c) == charMap.end())
                {
                    charMap[c] = std::vector<std::pair<int,int>>{std::make_pair(i, j)};
                }
                else
                {
                    charMap[c].push_back(std::make_pair(i, j));
                }
            }
        }

        vector<vector<bool>> visited(row, vector<bool>(col, false));

        if(charMap.find(word[0]) != charMap.end())
        {
            for(const auto& p : charMap[word[0]])
            {
                visited[p.first][p.second] = true;
                if(impl(board, row, col, visited, word, 1, p.first, p.second))
                {
                    return true;
                }
                visited[p.first][p.second] = false;
            }
        }

        return false;
    }
Beispiel #6
0
void
MenuTexture::UpdateString( int j )
{
  CharMap * chars = CharMap::Instance();

  int xoff = j * 10 * bpp;
  unsigned char * shape = chars->Shape( menu_str[j] );
  for (unsigned char m = 0x80; m > 0; m>>=1) {
    unsigned char * off = texData + xoff;
    for ( int j=0; j<HEIGHT; ++j ) {
      if ( (m & shape[ j ]) == m ) {
        memset( off, 0, bpp );
        off[bpp-1] = 0xff;
      }
      off += stride;
    }
    xoff += bpp;
  }
}
Beispiel #7
0
int main() {

  Map* map = new Map();
  map->insert(pair<int, string>(10, "ten"));
  map->insert(pair<int, string>(2, "two"));
  map->insert(pair<int, string>(1, "one"));
  map->insert(pair<int, string>(3, "three"));
  
  pair<Map::iterator, bool> ret;
  ret = map->insert(pair<int, string>(12, "twelve"));

  cout << "insert new\t";
  cout << ret.second << endl;
  cout << "insert again\t";
  //cout << map->insert(pair<int, string>(3, "asdf")).second << endl;
  
#ifndef USE_STD
  //cout << "Min:\t" << map->min().first << endl;
  //cout << "Max:\t" << map->max().first << endl;
#endif
  
  cout << "map size  " << map->size() << endl;
  cout << "is empty? " << map->empty() << endl;
 
  cout << "Find 10:\t" << map->find(10)->second << endl;
  cout << "Find 3:\t\t" << map->find(3)->second << endl;
  cout << "Can find 4?\t"  << (map->find(4) == map->end()) << endl;

  cout << "-------------------" << endl;
  cout << "Begin:\t" << (*map->begin()).second << endl;
  cout << "-------------------" << endl;
  Map map2(*map); // Copy constructor
  
  cout << "Find2 10:\t"    << map2.find(10)->second << endl;
  cout << "Find2 3:\t"     << map2.find(3)->second << endl;
  cout << "Can find2 4?\t 0 = " << !(map2.find(4) == map2.end()) << endl;

  int num = 11;
  map2[num] = "eleven";

  cout << "map[2]\t"  << map2[2]  << endl;
  cout << "map[11]\t" << map2[11] << endl;
  
  cout << "-----------------" << endl;
  
  Map del_map;

  del_map.insert(pair<int, string>(10, "ten"));
  del_map.insert(pair<int, string>(5,  "five"));
  del_map.insert(pair<int, string>(2,  "two"));
  del_map.insert(pair<int, string>(13, "thirteen"));
  del_map.insert(pair<int, string>(3,  "three"));
  del_map.insert(pair<int, string>(2,  "two"));
  del_map.insert(pair<int, string>(11, "eleven"));
  del_map.insert(pair<int, string>(7,  "seven"));

  del_map.erase(13);
  del_map.insert(pair<int, string>(13, "thirteen"));

  del_map[3] = "THIS VALUE SUCCESSFULLY CHANGED";

  for (Map::iterator i = del_map.begin(); i != del_map.end(); ++i) {
    cout << "del map\t" << (*i).second << endl;
  }

  Map::iterator i = del_map.begin();
  i++;
  ++i;

  del_map.clear();

  cout << "del_map[new]:\t" << del_map[42] << endl;

  cout << "is empty?  " << del_map.empty() << endl;
  cout << "size       " << del_map.size() << endl;
  //cout << "min / max  " << del_map.min().second << " " << del_map.max().first << endl;
  cout << "-------------------" << endl;
  
  CharMap first;
  CharMap second;

  first['x']=8;
  first['y']=16;
  first['z']=32;

  second = first;              // second now contains 3 ints

  first = CharMap();  // and first is now empty

  cout << "Size of first:  0 = " << first.size() << '\n';   // prints 0
  cout << "Size of second: 3 = " << second.size() << '\n'; // prints 3

  cout << "-------------------" << endl;

}
Beispiel #8
0
void BinaryDataGenerator::SaveCharmap(const CharMap &charmap, bool compress,
	enum OutputFormat format, const wxString &filePath)
{
	// Try opening the file for writing
	wxFFileOutputStream file(filePath);
	if (!file.IsOk()) {
		wxLogError(_("Could not open the file for writing"));
		return;
	}
	wxDataOutputStream out(file);
	out.BigEndianOrdered(false);
	out.UseBasicPrecisions();

	int numCodePages = charmap.GetCountCodePages();
	int headerSize = sizeof(wxUint32) + sizeof(wxInt16) + 2 * sizeof(wxUint8) + numCodePages * sizeof(wxUint32);
	int codePageBaseSize = sizeof(wxUint32) * 2 + 16;

	wxASSERT(numCodePages <= UINT8_MAX);
	if(compress) wxLogDebug("Compression not supported yet");
	// TODO: add compression
	// Write header
	wxUint32 magic = 'EMGF';
	wxUint8 flags = format;
	if (compress) flags |= FLAG_COMPRESSED;
	int ascender = 0;
	int ascenderDiv = 0;
	out.Write32(magic);
	file.SeekO(sizeof(wxInt16), wxFromCurrent);
	out.Write8(flags);
	out.Write8((wxUint8)numCodePages);

	wxUint32 *codepagePtrs = new wxUint32[numCodePages];
	wxUint32 **glyphPtrs = new wxUint32*[numCodePages];

	// Write codepages
	file.SeekO(headerSize);
	std::list<CodePage *>::const_iterator it = charmap.CBegin();
	for (int i = 0; i < numCodePages; i++) {
		wxASSERT(it != charmap.CEnd());
		codepagePtrs[i] = file.TellO();
		out.Write32((*it)->GetRangeStart());
		out.Write32((*it)->GetRangeEnd());
		const wxString &name = (*it)->GetName();
		for (unsigned int j = 0; j < 16; ++j) {
			out.Write8(j < name.Length() ? name.ToAscii()[j] : '\0');
		}
		glyphPtrs[i] = new wxUint32[(*it)->GetSize()];
		file.SeekO(sizeof(wxUint32) * (*it)->GetSize(), wxFromCurrent);
	}
	// Write glyphs
	it = charmap.CBegin();
	for (int i = 0; i < numCodePages; i++) {
		wxASSERT(it != charmap.CEnd());
		for (unsigned int j = 0; j < (*it)->GetSize(); j++) {
			const CharMapEntry *entry = (*it)->GetCharMapEntry((*it)->GetRangeStart() + j);
			if (entry == NULL) {
				glyphPtrs[i][j] = 0;
				continue;
			}
			LoadFont(entry->GetFamily(), entry->GetStyle(), entry->GetSize(), entry->GetEncodingID());
			wxUint32 glyph;
			if (!m_loadedFont.IsOk() || (glyph = m_loadedFont.GetGlyphIndex(entry->GetCode())) == 0)
			{
				wxLogWarning("Could not load glyph with code %u", (*it)->GetRangeStart() + j);
				glyphPtrs[i][j] = 0;
				continue;
			}
			wxPoint advance = m_loadedFont.GetGlyphAdvance(glyph);
			wxPoint bitmapTL = m_loadedFont.GetGlyphBitmapTL(glyph);
			int bitmapWidth, bitmapHeight;
			int bitmapSize = m_loadedFont.GetGlyphBitmap(glyph, NULL, &bitmapWidth, &bitmapHeight);
			if (bitmapSize < 0) {
				wxLogWarning("Error while getting bitmap for glyph with code %u", (*it)->GetRangeStart() + j);
				glyphPtrs[i][j] = 0;
				continue;
			}
			wxUint8 *bitmap = new wxUint8[bitmapSize];
			int result = m_loadedFont.GetGlyphBitmap(glyph, bitmap, &bitmapWidth, &bitmapHeight);
			wxASSERT(result == bitmapSize);

			bitmapSize = ConvertToFormat(bitmap, bitmapSize, format);

			if (compress) {
				CompressBitmap(&bitmap, &bitmapSize,  bitmapWidth * bitmapHeight, format);
			}

			ascender += m_loadedFont.GetAscender();
			ascenderDiv++;

			glyphPtrs[i][j] = file.TellO();
			out.Write16((wxInt16)advance.x);
			out.Write16((wxInt16)advance.y);
			out.Write16((wxInt16)bitmapTL.x);
			out.Write16((wxInt16)bitmapTL.y);
			out.Write16((wxUint16)bitmapWidth);
			out.Write16((wxUint16)bitmapHeight);
			out.Write32(bitmapSize);
			file.Write(bitmap, bitmapSize & ~(1<<31));
			delete[] bitmap;
		}
	}
	// Write glyph pointers
	it = charmap.CBegin();
	for (int i = 0; i < numCodePages; i++) {
		wxASSERT(it != charmap.CEnd());
		file.SeekO(codepagePtrs[i] + codePageBaseSize);
		for (unsigned int j = 0; j < (*it)->GetSize(); j++) {
			out.Write32(glyphPtrs[i][j]);
		}
		delete[] glyphPtrs[i];
		file.Sync();
	}
	delete[] glyphPtrs;
	
	// Write codepage pointers
	file.SeekO(headerSize - numCodePages * sizeof(wxUint32));
	for (int i = 0; i < numCodePages; i++) {
		out.Write32(codepagePtrs[i]);
	}
	delete[] codepagePtrs;
	delete[] glyphPtrs;

	// Write font wide parameters
	file.SeekO(sizeof(wxUint32));
	ascender = ascenderDiv > 0 ? ascender / ascenderDiv : 0;
	wxASSERT(ascender >= INT16_MIN && ascender <= INT16_MAX);
	out.Write16(ascender);

	file.Close();
}