FX_BOOL CFPF_SkiaFont::GetGlyphBBox(FX_INT32 iGlyphIndex, FX_RECT &rtBBox) { if (!m_Face) { return FALSE; } if (FXFT_Is_Face_Tricky(m_Face)) { if (FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72)) { return FALSE; } if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { FXFT_Set_Pixel_Sizes(m_Face, 0, 64); return FALSE; } FXFT_Glyph glyph; if (FXFT_Get_Glyph(m_Face->glyph, &glyph)) { FXFT_Set_Pixel_Sizes(m_Face, 0, 64); return FALSE; } FXFT_BBox cbox; FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); FX_INT32 x_ppem = m_Face->size->metrics.x_ppem; FX_INT32 y_ppem = m_Face->size->metrics.y_ppem; rtBBox.left = FPF_EM_ADJUST(x_ppem, cbox.xMin); rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax); rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax); rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin); rtBBox.top = FX_MIN(rtBBox.top, GetAscent()); rtBBox.bottom = FX_MAX(rtBBox.bottom, GetDescent()); FXFT_Done_Glyph(glyph); return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; } if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) { return FALSE; } rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingX(m_Face)); rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingY(m_Face)); rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)); rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)); return TRUE; }
void CText::SizeText(const std::string &text, FontType font, float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end) { start = end = pos; float sw = GetStringWidth(text, font, size); end.x += sw; if (align == TEXT_ALIGN_CENTER) { start.x -= sw/2.0f; end.x -= sw/2.0f; } else if (align == TEXT_ALIGN_RIGHT) { start.x -= sw; end.x -= sw; } start.y -= GetDescent(font, size); end.y += GetAscent(font, size); }
void CText::SizeText(const std::string &text, std::vector<FontMetaChar>::iterator format, std::vector<FontMetaChar>::iterator endFormat, float size, Math::Point pos, TextAlign align, Math::Point &start, Math::Point &end) { start = end = pos; float sw = GetStringWidth(text, format, endFormat, size); end.x += sw; if (align == TEXT_ALIGN_CENTER) { start.x -= sw/2.0f; end.x -= sw/2.0f; } else if (align == TEXT_ALIGN_RIGHT) { start.x -= sw; end.x -= sw; } start.y -= GetDescent(FONT_COLOBOT, size); end.y += GetAscent(FONT_COLOBOT, size); }
void TBFontFace::DrawString(int x, int y, const TBColor &color, const char *str, int len) { if (m_bgFont) m_bgFont->DrawString(x+m_bgX, y+m_bgY, m_bgColor, str, len); if (m_font_renderer) g_renderer->BeginBatchHint(TBRenderer::BATCH_HINT_DRAW_BITMAP_FRAGMENT); int i = 0; while (str[i] && i < len) { UCS4 cp = utf8::decode_next(str, &i, len); if (cp == 0xFFFF) continue; if (TBFontGlyph *glyph = GetGlyph(cp, true)) { if (glyph->frag) { TBRect dst_rect(x + glyph->metrics.x, y + glyph->metrics.y + GetAscent(), glyph->frag->Width(), glyph->frag->Height()); TBRect src_rect(0, 0, glyph->frag->Width(), glyph->frag->Height()); if (glyph->has_rgb) g_renderer->DrawBitmap(dst_rect, src_rect, glyph->frag); else g_renderer->DrawBitmapColored(dst_rect, src_rect, color, glyph->frag); } x += glyph->metrics.advance; } else if (!m_font_renderer) // This is the test font. Use same glyph width as height and draw square. { g_renderer->DrawRect(TBRect(x, y, m_metrics.height / 3, m_metrics.height), color); x += m_metrics.height / 3 + 1; } } if (m_font_renderer) g_renderer->EndBatchHint(); }
int CyaFont::GetHeight() { return( (int) ( GetAscent() + GetDescent() )); }
NS_IMETHODIMP nsLeafBoxFrame::Reflow(nsPresContext* aPresContext, nsHTMLReflowMetrics& aDesiredSize, const nsHTMLReflowState& aReflowState, nsReflowStatus& aStatus) { // This is mostly a copy of nsBoxFrame::Reflow(). // We aren't able to share an implementation because of the frame // class hierarchy. If you make changes here, please keep // nsBoxFrame::Reflow in sync. DO_GLOBAL_REFLOW_COUNT("nsLeafBoxFrame", aReflowState.reason); DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); NS_ASSERTION(aReflowState.mComputedWidth >=0 && aReflowState.mComputedHeight >= 0, "Computed Size < 0"); #ifdef DO_NOISY_REFLOW printf("\n-------------Starting LeafBoxFrame Reflow ----------------------------\n"); printf("%p ** nsLBF::Reflow %d R: ", this, myCounter++); switch (aReflowState.reason) { case eReflowReason_Initial: printf("Ini");break; case eReflowReason_Incremental: printf("Inc");break; case eReflowReason_Resize: printf("Rsz");break; case eReflowReason_StyleChange: printf("Sty");break; case eReflowReason_Dirty: printf("Drt "); break; default:printf("<unknown>%d", aReflowState.reason);break; } printSize("AW", aReflowState.availableWidth); printSize("AH", aReflowState.availableHeight); printSize("CW", aReflowState.mComputedWidth); printSize("CH", aReflowState.mComputedHeight); printf(" *\n"); #endif aStatus = NS_FRAME_COMPLETE; // create the layout state nsBoxLayoutState state(aPresContext, aReflowState, aDesiredSize); // coelesce reflows if we are root. state.HandleReflow(this); nsSize computedSize(aReflowState.mComputedWidth,aReflowState.mComputedHeight); nsMargin m; m = aReflowState.mComputedBorderPadding; //GetBorderAndPadding(m); // this happens sometimes. So lets handle it gracefully. if (aReflowState.mComputedHeight == 0) { nsSize minSize(0,0); GetMinSize(state, minSize); computedSize.height = minSize.height - m.top - m.bottom; } nsSize prefSize(0,0); // if we are told to layout intrinic then get our preferred size. if (computedSize.width == NS_INTRINSICSIZE || computedSize.height == NS_INTRINSICSIZE) { nsSize minSize(0,0); nsSize maxSize(0,0); GetPrefSize(state, prefSize); GetMinSize(state, minSize); GetMaxSize(state, maxSize); BoundsCheck(minSize, prefSize, maxSize); } // get our desiredSize if (aReflowState.mComputedWidth == NS_INTRINSICSIZE) { computedSize.width = prefSize.width; } else { computedSize.width += m.left + m.right; } if (aReflowState.mComputedHeight == NS_INTRINSICSIZE) { computedSize.height = prefSize.height; } else { computedSize.height += m.top + m.bottom; } // handle reflow state min and max sizes if (computedSize.width > aReflowState.mComputedMaxWidth) computedSize.width = aReflowState.mComputedMaxWidth; if (computedSize.height > aReflowState.mComputedMaxHeight) computedSize.height = aReflowState.mComputedMaxHeight; if (computedSize.width < aReflowState.mComputedMinWidth) computedSize.width = aReflowState.mComputedMinWidth; if (computedSize.height < aReflowState.mComputedMinHeight) computedSize.height = aReflowState.mComputedMinHeight; nsRect r(mRect.x, mRect.y, computedSize.width, computedSize.height); SetBounds(state, r); // layout our children Layout(state); // ok our child could have gotten bigger. So lets get its bounds // get the ascent nscoord ascent = mRect.height; // Only call GetAscent when not doing Initial reflow while in PP // or when it is Initial reflow while in PP and a chrome doc // If called again with initial reflow it crashes because the // frames are fully constructed (I think). PRBool isChrome; PRBool isInitialPP = nsBoxFrame::IsInitialReflowForPrintPreview(state, isChrome); if (!isInitialPP || (isInitialPP && isChrome)) { GetAscent(state, ascent); } aDesiredSize.width = mRect.width; aDesiredSize.height = mRect.height; aDesiredSize.ascent = ascent; aDesiredSize.descent = 0; // NS_FRAME_OUTSIDE_CHILDREN is set in SetBounds() above if (mState & NS_FRAME_OUTSIDE_CHILDREN) { nsRect* overflowArea = GetOverflowAreaProperty(); NS_ASSERTION(overflowArea, "Failed to set overflow area property"); aDesiredSize.mOverflowArea = *overflowArea; } // max sure the max element size reflects // our min width nscoord* maxElementWidth = state.GetMaxElementWidth(); if (maxElementWidth) { nsSize minSize(0,0); GetMinSize(state, minSize); if (mRect.width > minSize.width) { if (aReflowState.mComputedWidth == NS_INTRINSICSIZE) { *maxElementWidth = minSize.width; } else { *maxElementWidth = mRect.width; } } else { *maxElementWidth = mRect.width; } } #ifdef DO_NOISY_REFLOW { printf("%p ** nsLBF(done) W:%d H:%d ", this, aDesiredSize.width, aDesiredSize.height); if (maxElementWidth) { printf("MW:%d\n", *maxElementWidth); } else { printf("MW:?\n"); } } #endif return NS_OK; }