Exemplo n.º 1
0
// Tries the given font and save it |outFontFamilyName| if it succeeds.
PassRefPtr<SimpleFontData> FontCache::fontDataFromDescriptionAndLogFont(const FontDescription& fontDescription, ShouldRetain shouldRetain, const LOGFONT& font, wchar_t* outFontFamilyName)
{
    RefPtr<SimpleFontData> fontData = getFontData(fontDescription, font.lfFaceName, false, shouldRetain);
    if (fontData)
        memcpy(outFontFamilyName, font.lfFaceName, sizeof(font.lfFaceName));
    return fontData.release();
}
Exemplo n.º 2
0
int
LedMatrixFont::getStart(char c) 
{
	const uint8_t *fontChar = getFontData()[c-32];

	if( c == ' ' ) {
		return 2;
	}

	int offset = 0;

	for(int b=0;b<8;b++) {
		bool hasBits = false;
		for(int r=0;r<8;r++) {
			if( (fontChar[r] >> (7-b)) & 0x1 ) {
				hasBits = true;
				break;
			}
		}
		if( !hasBits ) {
			offset = b;	
		} else {
			break;
		}
	}
	return offset;
}
Exemplo n.º 3
0
std::shared_ptr<const FontFace> FontManager::getFontFace(const std::string& name, int sizeX, int sizeY)
{
	std::shared_ptr<const FontFace> fontFace;
	auto it = m_faces.find(std::make_tuple(name, sizeX, sizeY));

	if(it != m_faces.end())
	{
		fontFace = it->second.lock();
	}

	if(!fontFace)
	{
		auto fontData = getFontData(name);
		fontFace = std::shared_ptr<const FontFace>(new FontFace(this, fontData, sizeX, sizeY, 0, m_defaultLoadFlags));
		if(it != m_faces.end())
		{
			it->second = std::weak_ptr<const FontFace>(fontFace);
		}
		else
		{
			m_faces.emplace(std::make_tuple(name, sizeX, sizeY), std::weak_ptr<const FontFace>(fontFace));
		}
	}

	return fontFace;
}
void CSSSegmentedFontFace::loadFont(const FontDescription& fontDescription, PassRefPtr<LoadFontCallback> callback)
{
    getFontData(fontDescription); // Kick off the load.

    if (callback) {
        if (isLoading())
            m_callbacks.append(callback);
        else if (checkFont())
            callback->notifyLoaded(this);
        else
            callback->notifyError(this);
    }
}
        void DirectionReader::parseWords( const core::DirectionType& directionType)
        {
            const auto& wordSet = directionType.getWordsSet();

            for( const auto& wordPtr : wordSet )
            {
                api::WordsData outWords;
                const auto& attr = *wordPtr->getAttributes();
                outWords.text = wordPtr->getValue().getValue();
                outWords.positionData = getPositionData( attr );
                outWords.colorData = getColor( attr );
                outWords.fontData = getFontData( attr );
                myOutDirectionData.words.emplace_back( std::move( outWords ) );
            }
        }
Exemplo n.º 6
0
static void drawBackgroundMessages(DisplayInternalInfo& displayInternalInfo) {
  HT1632Class& HT1632 = displayInternalInfo.ht1632;
  int boardId, i, j;
  for (i=0; i < BACKGROUND_MESSAGE_COUNT; ++i) {
    if (backgroundMessage[i].enabled == false) continue;
    if (willAnimate(&backgroundMessage[i].animation) == false) continue;
    for (j=0; j < BUFFER_SECONDARY; ++j) {
      switch (backgroundMessage[i].displayColor) {
        case displayColorGreen: boardId = 0; break;
        case displayColorRed: boardId = 1; break;
        case displayColorYellow:  // fall thru...
        default: boardId = j; break;
      }
      HT1632.drawTarget(BUFFER_BOARD(boardId+1));
      HT1632.drawText(backgroundMessage[i].msg, backgroundMessage[i].x, backgroundMessage[i].y,
		      getFontData(backgroundMessage[i].font),
		      getFontWidth(backgroundMessage[i].font),
		      getFontHeight(backgroundMessage[i].font),
		      getFontGlyphStep(backgroundMessage[i].font));
      if (backgroundMessage[i].displayColor != displayColorYellow) break;
    }
  }
}
Exemplo n.º 7
0
const FontData* FontFallbackList::fontDataAt(const FontDescription& fontDescription, unsigned realizedFontIndex) const
{
    if (realizedFontIndex < m_fontList.size())
        return m_fontList[realizedFontIndex].get(); // This fallback font is already in our list.

    // Make sure we're not passing in some crazy value here.
    ASSERT(realizedFontIndex == m_fontList.size());

    if (m_familyIndex == cAllFamiliesScanned)
        return 0;

    // Ask the font cache for the font data.
    // We are obtaining this font for the first time.  We keep track of the families we've looked at before
    // in |m_familyIndex|, so that we never scan the same spot in the list twice.  getFontData will adjust our
    // |m_familyIndex| as it scans for the right font to make.
    ASSERT(FontCache::fontCache()->generation() == m_generation);
    RefPtr<FontData> result = getFontData(fontDescription, m_familyIndex);
    if (result) {
        m_fontList.append(result);
        if (result->isLoadingFallback())
            m_hasLoadingFallback = true;
    }
    return result.get();
}
Exemplo n.º 8
0
int
LedMatrixFont::getEnd(char c)
{
	const uint8_t *fontChar = getFontData()[c-32];

	if( c == ' ' ) {
		return 6;
	}

	int end = 0;

	for(int b=0;b<8;b++) {
		for(int r=0;r<8;r++) {
			if( (fontChar[r] >> (7-b)) & 0x1 ) {
				end = b;
				break;
			}
		}
	}

	end =  end < 8 ? end+1 : end;

	return end;
}
Exemplo n.º 9
0
 PassRefPtr<SimpleFontData> getFontDataForSize(float size) {
   FontDescription fontDescription;
   fontDescription.setSizeAdjust(size);
   fontDescription.setAdjustedSize(size);
   return getFontData(fontDescription);
 }
Exemplo n.º 10
0
FontFace FontManager::createFontFace(const std::string& name, int sizeX, int sizeY)
{
	auto fontData = getFontData(name);
	return FontFace(this, fontData, sizeX, sizeY);
}
Exemplo n.º 11
0
static void modeMessageFast(DisplayInternalInfo& displayInternalInfo) {
  int boardId, i;

  HT1632Class& HT1632 = displayInternalInfo.ht1632;
  HT1632.clearAll();

  const int currColorEffect = modeMessageDataColorEffect % 3; 
  for (i=0; i < BUFFER_SECONDARY; ++i) {
    if (modeMessageData.blinkBlankInEffect) break;  // blinkBlankInEffect in effect? If so, write no chars

    switch (modeMessageData.displayColor) {
        case displayColorGreen: boardId = 0; break;
        case displayColorRed: boardId = 1; break;
        case displayColorYellow: boardId = i; break;
        case displayColorAlternate:  // fall thru
        default: boardId = currColorEffect == 2 ? i : currColorEffect; break;
    }

    HT1632.drawTarget(BUFFER_BOARD(boardId+1));

    // if bouncing, make sure sure y is within range
    const int wantedY = modeMessageData.currYFactor / INCREMENT_Y_SCALE;
    const int adjustedY = modeMessageData.incrementY ? getAdjustedTextY(modeMessageData.font, wantedY) : wantedY;

    HT1632.drawText(modeMessageData.msg,
		    modeMessageData.incrementX ? (OUT_SIZE - modeMessageData.currX) : modeMessageData.currX /*x*/,
		    adjustedY /*y*/,
		    getFontData(modeMessageData.font),
		    getFontWidth(modeMessageData.font),
		    getFontHeight(modeMessageData.font),
		    getFontGlyphStep(modeMessageData.font));

    if (modeMessageData.displayColor == displayColorAlternate && currColorEffect == 2) continue;
    if (modeMessageData.displayColor != displayColorYellow) break;
  }

  drawBackgroundMessages(displayInternalInfo);
  drawBackgroundImgs(displayInternalInfo);

  // confetti
  if (modeMessageData.confetti > 0) {
    for (boardId=0; boardId < BUFFER_SECONDARY; ++boardId) {
      HT1632.drawTarget(BUFFER_BOARD(boardId+1));
      for (int xx = 0, yy = (int) getRandomNumber(modeMessageData.confetti); xx <= yy ; ++xx) {
	HT1632.setPixel( (int) getRandomNumber(OUT_SIZE), (int) getRandomNumber(COM_SIZE));
      }
    }
  }

  HT1632.renderAll();

  // text wrap
  if (modeMessageData.incrementX && ++modeMessageData.currX >= (modeMessageData.wd + OUT_SIZE)) {
    modeMessageData.currX = 0;
    ++modeMessageDataColorEffect;

    if (modeMessageData.alternateFont) {
      modeMessageData.font = getNextFont(modeMessageData.font);
      modeMessageData.wd = HT1632.getTextWidth(modeMessageData.msg,
					       getFontWidth(modeMessageData.font),
					       getFontHeight(modeMessageData.font));
    }

    // repeats?
    if (modeMessageData.repeats != ~0) {
      // mode exit (1 of 2)
      if (--modeMessageData.repeats < 0) {
	modeMessageData.repeats = ~0;  // avoid getting here again...
	if (modeMessageData.completedCallback != nullptr) {
	  (*(modeMessageData.completedCallback))(displayInternalInfo, modeMessageData.completedCallbackParam);
	  return;
	}
      }
    }
  }

  // Y (bounce effect)
  if (modeMessageData.incrementY != 0) {
    modeMessageData.currYFactor += modeMessageData.incrementY;

    const int maxY = COM_SIZE - getFontHeight(modeMessageData.font);
    if (modeMessageData.incrementY < 0 && modeMessageData.currYFactor < 0) {
      modeMessageData.incrementY *= -1;
    } else if (modeMessageData.incrementY > 0 && (modeMessageData.currYFactor >= maxY * INCREMENT_Y_SCALE)) {
      modeMessageData.incrementY *= -1;

      if (!modeMessageData.incrementX) {
	++modeMessageDataColorEffect;
	if (modeMessageData.alternateFont) {
	  modeMessageData.font = getNextFont(modeMessageData.font);
	  // modeMessageData.wd = HT1632.getTextWidth(modeMessageData.msg,
	  //				  	   getFontWidth(modeMessageData.font),
	  //					   getFontHeight(modeMessageData.font));
	}
      }
    }
  }
}
Exemplo n.º 12
0
void OLED12864::print(uint8_t x, uint8_t line, const char ch[])
{

    // simplified for testing only
    // if (invalidXL(x, line)) return;
    // -- This will introduce a bug if last printing stopped at last position which will not advance the line until next print.

    // Try just valid the line only
    if (invalidLine(line)) return;

    uint8_t j;
    uint16_t c;
    uint16_t bPos;
    uint8_t data;

    _cursor.x = x;
    _cursor.y = line * OLED_LINE_HEIGHT;

    int maxChars, charsWrite;

    j = 0;
    while (ch[j] != '\0')
    {
        adjCursor();
        maxChars = ((OLED_WIDTH - _cursor.x) / _font.width); 	// number of characters can be printed in this line.
        charsWrite = 0;
        if (maxChars > 0)
        {
            line = (_cursor.y / OLED_LINE_HEIGHT);
            for (int k = 0; k < _font.lines; k++)
            {
                setDisplayPos(_cursor.x, line + k);
                bPos = posXL(_cursor.x, line + k);
                for (int l = 0; (( l < maxChars) && (ch[j + l] != '\0')) ; l++)
                {
                    c =ch[j+l] - _font.offset;

                    if (_font.width <= 24) {
                        if (_directDraw) Wire.beginTransmission(_i2cAddress);
                        if (_directDraw) Wire.write(0x40);
                        for (uint8_t i=0; i < _font.width; i++)
                        {
                            data = getFontData(c, 5 + c * _font.bytePerChar + k * _font.width + i);
                            if (_directDraw) Wire.write(data);
                            if (_enableBuffer)
                                _buffer[bPos++] = data;
                        }
                        if (_directDraw) Wire.endTransmission();
                    } else {
                        for (uint8_t i=0; i < _font.width; i += 8)
                        {
                            if (_directDraw) Wire.beginTransmission(_i2cAddress);
                            if (_directDraw) Wire.write(0x40);
                            uint8_t maxX = min(8, _font.width - i);
                            for (uint8_t x=0; x < maxX; x++) {
                                data = getFontData(c, 5 + c * _font.bytePerChar + k * _font.width + i + x);
                                if (_directDraw) Wire.write(data);
                                if (_enableBuffer)
                                    _buffer[bPos++] = data;
                            }
                            if (_directDraw) Wire.endTransmission();
                        }
                    }

                    if (k == 0) charsWrite++;  // only count on first row of chars; it may use l as charsWrite, but will need to check stop condition
                }
            }
        }
        j += charsWrite;
        _cursor.x += charsWrite * _font.width;
        if (ch[j] != '\0')
        {
            // advance to next line
            _cursor.x = 0;
            _cursor.y += _font.height;
        }
    }
}
Exemplo n.º 13
0
PassRefPtr<SimpleFontData> FontCache::getLastResortFallbackFont(const FontDescription& description, ShouldRetain shouldRetain)
{
    FontDescription::GenericFamilyType generic = description.genericFamily();

    // FIXME: Would be even better to somehow get the user's default font here.
    // For now we'll pick the default that the user would get without changing
    // any prefs.
    DEFINE_STATIC_LOCAL(AtomicString, timesStr, "Times New Roman");
    DEFINE_STATIC_LOCAL(AtomicString, courierStr, "Courier New");
    DEFINE_STATIC_LOCAL(AtomicString, arialStr, "Arial");

    AtomicString& fontStr = timesStr;
    if (generic == FontDescription::SansSerifFamily)
        fontStr = arialStr;
    else if (generic == FontDescription::MonospaceFamily)
        fontStr = courierStr;

    RefPtr<SimpleFontData> simpleFont = getFontData(description, fontStr, false, shouldRetain);
    if (simpleFont)
        return simpleFont.release();

    // Fall back to system fonts as Win Safari does because this function must
    // return a valid font. Once we find a valid system font, we save its name
    // to a static variable and use it to prevent trying system fonts again.
    static wchar_t fallbackFontName[LF_FACESIZE] = {0};
    if (fallbackFontName[0])
        return getFontData(description, fallbackFontName, false, shouldRetain);

    // Fall back to the DEFAULT_GUI_FONT if no known Unicode fonts are available.
    if (HFONT defaultGUIFont = static_cast<HFONT>(GetStockObject(DEFAULT_GUI_FONT))) {
        LOGFONT defaultGUILogFont;
        GetObject(defaultGUIFont, sizeof(defaultGUILogFont), &defaultGUILogFont);
        if (simpleFont = fontDataFromDescriptionAndLogFont(description, shouldRetain, defaultGUILogFont, fallbackFontName))
            return simpleFont.release();
    }

    // Fall back to Non-client metrics fonts.
    NONCLIENTMETRICS nonClientMetrics = {0};
    nonClientMetrics.cbSize = sizeof(nonClientMetrics);
    if (SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof(nonClientMetrics), &nonClientMetrics, 0)) {
        if (simpleFont = fontDataFromDescriptionAndLogFont(description, shouldRetain, nonClientMetrics.lfMessageFont, fallbackFontName))
            return simpleFont.release();
        if (simpleFont = fontDataFromDescriptionAndLogFont(description, shouldRetain, nonClientMetrics.lfMenuFont, fallbackFontName))
            return simpleFont.release();
        if (simpleFont = fontDataFromDescriptionAndLogFont(description, shouldRetain, nonClientMetrics.lfStatusFont, fallbackFontName))
            return simpleFont.release();
        if (simpleFont = fontDataFromDescriptionAndLogFont(description, shouldRetain, nonClientMetrics.lfCaptionFont, fallbackFontName))
            return simpleFont.release();
        if (simpleFont = fontDataFromDescriptionAndLogFont(description, shouldRetain, nonClientMetrics.lfSmCaptionFont, fallbackFontName))
            return simpleFont.release();
    }

    // Fall back to all the fonts installed in this PC. When a font has a
    // localized name according to the system locale as well as an English name,
    // both GetTextFace() and EnumFontFamilies() return the localized name. So,
    // FontCache::createFontPlatformData() does not filter out the fonts
    // returned by this EnumFontFamilies() call.
    HWndDC dc(0);
    if (dc) {
        GetLastResortFallbackFontProcData procData(this, &description, shouldRetain, fallbackFontName);
        EnumFontFamilies(dc, 0, getLastResortFallbackFontProc, reinterpret_cast<LPARAM>(&procData));

        if (procData.m_fontData)
            return procData.m_fontData.release();
    }

    ASSERT_NOT_REACHED();
    return 0;
}