diff options
author | Feng Qian <> | 2009-04-10 18:11:29 -0700 |
---|---|---|
committer | The Android Open Source Project <initial-contribution@android.com> | 2009-04-10 18:11:29 -0700 |
commit | 8f72e70a9fd78eec56623b3a62e68f16b7b27e28 (patch) | |
tree | 181bf9a400c30a1bf34ea6d72560e8d00111d549 /WebCore/platform/wx | |
parent | 7ed56f225e0ade046e1c2178977f72b2d896f196 (diff) | |
download | external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.zip external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.gz external_webkit-8f72e70a9fd78eec56623b3a62e68f16b7b27e28.tar.bz2 |
AI 145796: Land the WebKit merge @r42026.
Automated import of CL 145796
Diffstat (limited to 'WebCore/platform/wx')
-rw-r--r-- | WebCore/platform/wx/MouseWheelEventWx.cpp | 7 | ||||
-rw-r--r-- | WebCore/platform/wx/wxcode/fontprops.h | 3 | ||||
-rw-r--r-- | WebCore/platform/wx/wxcode/gtk/fontprops.cpp | 71 | ||||
-rw-r--r-- | WebCore/platform/wx/wxcode/gtk/non-kerned-drawing.cpp | 185 | ||||
-rw-r--r-- | WebCore/platform/wx/wxcode/mac/carbon/fontprops.cpp | 11 | ||||
-rw-r--r-- | WebCore/platform/wx/wxcode/mac/carbon/non-kerned-drawing.cpp | 7 | ||||
-rw-r--r-- | WebCore/platform/wx/wxcode/non-kerned-drawing.h | 21 | ||||
-rw-r--r-- | WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp | 4 |
8 files changed, 276 insertions, 33 deletions
diff --git a/WebCore/platform/wx/MouseWheelEventWx.cpp b/WebCore/platform/wx/MouseWheelEventWx.cpp index 154a710..9f3923d 100644 --- a/WebCore/platform/wx/MouseWheelEventWx.cpp +++ b/WebCore/platform/wx/MouseWheelEventWx.cpp @@ -25,6 +25,7 @@ #include "config.h" #include "PlatformWheelEvent.h" +#include "Scrollbar.h" #include <wx/defs.h> #include <wx/event.h> @@ -34,17 +35,19 @@ namespace WebCore { PlatformWheelEvent::PlatformWheelEvent(const wxMouseEvent& event, const wxPoint& globalPoint) : m_position(event.GetPosition()) , m_globalPosition(globalPoint) - , m_granularity(ScrollByLineWheelEvent) + , m_granularity(ScrollByPixelWheelEvent) , m_shiftKey(event.ShiftDown()) , m_ctrlKey(event.ControlDown()) , m_altKey(event.AltDown()) , m_metaKey(event.MetaDown()) // FIXME: We'll have to test other browsers , m_deltaX(0) // wx doesn't support horizontal mouse wheel scrolling , m_deltaY(event.GetWheelRotation() / event.GetWheelDelta()) + , m_wheelTicksX(m_deltaX) + , m_wheelTicksY(m_deltaY) , m_isAccepted(false) { // FIXME: retrieve the user setting for the number of lines to scroll on each wheel event - m_deltaY *= horizontalLineMultiplier(); + m_deltaY *= static_cast<float>(cScrollbarPixelsPerLineStep); } } diff --git a/WebCore/platform/wx/wxcode/fontprops.h b/WebCore/platform/wx/wxcode/fontprops.h index e6f0b16..7f38bcf 100644 --- a/WebCore/platform/wx/wxcode/fontprops.h +++ b/WebCore/platform/wx/wxcode/fontprops.h @@ -46,4 +46,5 @@ private: float m_lineSpacing; float m_xHeight; -};
\ No newline at end of file +}; + diff --git a/WebCore/platform/wx/wxcode/gtk/fontprops.cpp b/WebCore/platform/wx/wxcode/gtk/fontprops.cpp index 369fcc5..df14812 100644 --- a/WebCore/platform/wx/wxcode/gtk/fontprops.cpp +++ b/WebCore/platform/wx/wxcode/gtk/fontprops.cpp @@ -23,17 +23,42 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include "config.h" + #include <wx/defs.h> #include <wx/gdicmn.h> #include <wx/font.h> #include <wx/fontutil.h> #include "fontprops.h" +#include "non-kerned-drawing.h" #include <gdk/gdk.h> +#include <cairo.h> +#include <pango/pango.h> +#include <pango/pangocairo.h> + wxFontProperties::wxFontProperties(wxFont* font): m_ascent(0), m_descent(0), m_lineGap(0), m_lineSpacing(0), m_xHeight(0) { + ASSERT(font && font->Ok()); + +#if USE(WXGC) + cairo_font_extents_t font_extents; + cairo_text_extents_t text_extents; + cairo_scaled_font_t* scaled_font = WebCore::createScaledFontForFont(font); + + cairo_scaled_font_extents(scaled_font, &font_extents); + m_ascent = static_cast<int>(font_extents.ascent); + m_descent = static_cast<int>(font_extents.descent); + m_lineSpacing = static_cast<int>(font_extents.height); + cairo_scaled_font_text_extents(scaled_font, "x", &text_extents); + m_xHeight = text_extents.height; + cairo_scaled_font_text_extents(scaled_font, " ", &text_extents); + m_lineGap = m_lineSpacing - m_ascent - m_descent; + + cairo_scaled_font_destroy(scaled_font); +#else PangoContext* context = gdk_pango_context_get_for_screen( gdk_screen_get_default() ); PangoLayout* layout = pango_layout_new(context); // and use it if it's valid @@ -64,6 +89,7 @@ m_ascent(0), m_descent(0), m_lineGap(0), m_lineSpacing(0), m_xHeight(0) m_lineSpacing = m_ascent + m_descent; pango_font_metrics_unref(metrics); +#endif } void GetTextExtent( const wxFont& font, const wxString& str, wxCoord *width, wxCoord *height, @@ -80,16 +106,34 @@ void GetTextExtent( const wxFont& font, const wxString& str, wxCoord *width, wxC if (str.empty()) return; - + +// FIXME: Doesn't support height, descent or external leading, though we don't need this for WebKit +// it will need to be implemented before merging into wx unless we craft a new API. +#if USE(WXGC) + PangoFont* pangoFont = WebCore::createPangoFontForFont(&font); + PangoContext* pangoContext = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(WebCore::pangoFontMap())); + PangoGlyph pangoGlyph = WebCore::pango_font_get_glyph(pangoFont, pangoContext, (gunichar)g_utf8_get_char(str.ToUTF8())); + cairo_glyph_t cglyph = { pangoGlyph, 0, 0 }; + cairo_text_extents_t extents; + cairo_scaled_font_t* scaled_font = WebCore::createScaledFontForFont(&font); + cairo_scaled_font_glyph_extents(scaled_font, &cglyph, 1, &extents); + + if (cairo_scaled_font_status(scaled_font) == CAIRO_STATUS_SUCCESS && extents.x_advance != 0) + *width = (wxCoord)extents.x_advance; + + cairo_scaled_font_destroy(scaled_font); + g_object_unref(pangoContext); + g_object_unref(pangoFont); +#else PangoContext* context = gdk_pango_context_get_for_screen( gdk_screen_get_default() ); PangoLayout* m_layout = pango_layout_new(context); // and use it if it's valid - if ( font != wxNullFont ) + if ( font && font->IsOk() ) { pango_layout_set_font_description ( m_layout, - font.GetNativeFontInfo()->description + font->GetNativeFontInfo()->description ); } @@ -103,24 +147,19 @@ void GetTextExtent( const wxFont& font, const wxString& str, wxCoord *width, wxC pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); + int h = 0; + pango_layout_get_pixel_size( m_layout, width, &h ); + if (descent) { - int h; - pango_layout_get_pixel_size( m_layout, width, &h ); PangoLayoutIter *iter = pango_layout_get_iter(m_layout); int baseline = pango_layout_iter_get_baseline(iter); pango_layout_iter_free(iter); *descent = h - PANGO_PIXELS(baseline); - - if (height) - *height = (wxCoord) h; - } - else - { - pango_layout_get_pixel_size( m_layout, width, height ); } - // Reset old font description - //if (font != wxNullFont) - // pango_layout_set_font_description( m_layout, m_fontdesc ); -}
\ No newline at end of file + if (height) + *height = (wxCoord) h; +#endif +} + diff --git a/WebCore/platform/wx/wxcode/gtk/non-kerned-drawing.cpp b/WebCore/platform/wx/wxcode/gtk/non-kerned-drawing.cpp index ed8fb09..bf745e0 100644 --- a/WebCore/platform/wx/wxcode/gtk/non-kerned-drawing.cpp +++ b/WebCore/platform/wx/wxcode/gtk/non-kerned-drawing.cpp @@ -28,25 +28,201 @@ #include "GraphicsContext.h" #include "SimpleFontData.h" +#include <wx/dc.h> #include <wx/dcgraph.h> #include <wx/defs.h> #include <wx/dcclient.h> #include <wx/gdicmn.h> #include <vector> +#if USE(WXGC) +#include <cairo.h> +#include <assert.h> + +#include <pango/pango.h> +#include <pango/pangocairo.h> + +// Use cairo-ft if a recent enough Pango version isn't available +#if !PANGO_VERSION_CHECK(1,18,0) +#include <cairo-ft.h> +#include <pango/pangofc-fontmap.h> +#endif + +#endif + +#include <gtk/gtk.h> + namespace WebCore { +#if USE(WXGC) +static PangoFontMap* g_fontMap; + +PangoFontMap* pangoFontMap() +{ + if (!g_fontMap) + g_fontMap = pango_cairo_font_map_get_default(); + + return g_fontMap; +} + +PangoFont* createPangoFontForFont(const wxFont* wxfont) +{ + ASSERT(wxfont && wxfont->Ok()); + + const char* face = wxfont->GetFaceName().mb_str(wxConvUTF8); + char const* families[] = { + face, + 0 + }; + + switch (wxfont->GetFamily()) { + case wxFONTFAMILY_ROMAN: + families[1] = "serif"; + break; + case wxFONTFAMILY_SWISS: + families[1] = "sans"; + break; + case wxFONTFAMILY_MODERN: + families[1] = "monospace"; + break; + default: + families[1] = "sans"; + } + + PangoFontDescription* description = pango_font_description_new(); + pango_font_description_set_absolute_size(description, wxfont->GetPointSize() * PANGO_SCALE); + + PangoFont* pangoFont = 0; + PangoContext* pangoContext = 0; + + switch (wxfont->GetWeight()) { + case wxFONTWEIGHT_LIGHT: + pango_font_description_set_weight(description, PANGO_WEIGHT_LIGHT); + break; + case wxFONTWEIGHT_NORMAL: + pango_font_description_set_weight(description, PANGO_WEIGHT_NORMAL); + break; + case wxFONTWEIGHT_BOLD: + pango_font_description_set_weight(description, PANGO_WEIGHT_BOLD); + break; + } + + switch (wxfont->GetStyle()) { + case wxFONTSTYLE_NORMAL: + pango_font_description_set_style(description, PANGO_STYLE_NORMAL); + break; + case wxFONTSTYLE_ITALIC: + pango_font_description_set_style(description, PANGO_STYLE_ITALIC); + break; + case wxFONTSTYLE_SLANT: + pango_font_description_set_style(description, PANGO_STYLE_OBLIQUE); + break; + } + + PangoFontMap* fontMap = pangoFontMap(); + + pangoContext = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(fontMap)); + for (unsigned i = 0; !pangoFont && i < G_N_ELEMENTS(families); i++) { + pango_font_description_set_family(description, families[i]); + pango_context_set_font_description(pangoContext, description); + pangoFont = pango_font_map_load_font(fontMap, pangoContext, description); + } + pango_font_description_free(description); + + return pangoFont; +} + +cairo_scaled_font_t* createScaledFontForFont(const wxFont* wxfont) +{ + ASSERT(wxfont && wxfont->Ok()); + + cairo_scaled_font_t* scaledFont = NULL; + PangoFont* pangoFont = createPangoFontForFont(wxfont); + +#if PANGO_VERSION_CHECK(1,18,0) + if (pangoFont) + scaledFont = cairo_scaled_font_reference(pango_cairo_font_get_scaled_font(PANGO_CAIRO_FONT(pangoFont))); +#endif + + return scaledFont; +} + +PangoGlyph pango_font_get_glyph(PangoFont* font, PangoContext* context, gunichar wc) +{ + PangoGlyph result = 0; + gchar buffer[7]; + + gint length = g_unichar_to_utf8(wc, buffer); + g_return_val_if_fail(length, 0); + + GList* items = pango_itemize(context, buffer, 0, length, NULL, NULL); + + if (g_list_length(items) == 1) { + PangoItem* item = static_cast<PangoItem*>(items->data); + PangoFont* tmpFont = item->analysis.font; + item->analysis.font = font; + + PangoGlyphString* glyphs = pango_glyph_string_new(); + pango_shape(buffer, length, &item->analysis, glyphs); + + item->analysis.font = tmpFont; + + if (glyphs->num_glyphs == 1) + result = glyphs->glyphs[0].glyph; + else + g_warning("didn't get 1 glyph but %d", glyphs->num_glyphs); + + pango_glyph_string_free(glyphs); + } + + g_list_foreach(items, (GFunc)pango_item_free, NULL); + g_list_free(items); + + return result; +} +#endif // USE(WXGC) + + void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) { #if USE(WXGC) wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext()); + wxGraphicsContext* gc = dc->GetGraphicsContext(); + gc->PushState(); + cairo_t* cr = (cairo_t*)gc->GetNativeContext(); + + wxFont* wxfont = font->getWxFont(); + PangoFont* pangoFont = createPangoFontForFont(wxfont); + PangoFontMap* fontMap = pangoFontMap(); + PangoContext* pangoContext = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(fontMap)); + cairo_scaled_font_t* scaled_font = createScaledFontForFont(wxfont); + ASSERT(scaled_font); + + cairo_glyph_t* glyphs = NULL; + glyphs = static_cast<cairo_glyph_t*>(malloc(sizeof(cairo_glyph_t) * numGlyphs)); + + float offset = point.x(); + + for (int i = 0; i < numGlyphs; i++) { + glyphs[i].index = pango_font_get_glyph(pangoFont, pangoContext, glyphBuffer.glyphAt(from + i)); + glyphs[i].x = offset; + glyphs[i].y = point.y(); + offset += glyphBuffer.advanceAt(from + i); + } + + cairo_set_source_rgba(cr, color.Red()/255.0, color.Green()/255.0, color.Blue()/255.0, color.Alpha()/255.0); + cairo_set_scaled_font(cr, scaled_font); + + cairo_show_glyphs(cr, glyphs, numGlyphs); + + cairo_scaled_font_destroy(scaled_font); + gc->PopState(); #else wxDC* dc = graphicsContext->platformContext(); -#endif - wxFont wxfont = font->getWxFont(); - if (wxfont.IsOk()) - dc->SetFont(wxfont); + wxFont* wxfont = font->getWxFont(); + if (wxfont && wxfont->IsOk()) + dc->SetFont(*wxfont); dc->SetTextForeground(color); // convert glyphs to wxString @@ -63,6 +239,7 @@ void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* wxCoord ypoint = (wxCoord) (point.y() - height); dc->DrawText(text, (wxCoord)point.x(), ypoint); +#endif } } diff --git a/WebCore/platform/wx/wxcode/mac/carbon/fontprops.cpp b/WebCore/platform/wx/wxcode/mac/carbon/fontprops.cpp index b649eb4..447a3d0 100644 --- a/WebCore/platform/wx/wxcode/mac/carbon/fontprops.cpp +++ b/WebCore/platform/wx/wxcode/mac/carbon/fontprops.cpp @@ -36,14 +36,19 @@ static inline float scaleEmToUnits(float x, unsigned unitsPerEm) { return x * (c wxFontProperties::wxFontProperties(wxFont* font): m_ascent(0), m_descent(0), m_lineGap(0), m_lineSpacing(0), m_xHeight(0) { - ATSFontRef fontRef; CGFontRef cgFont; + +#ifdef wxOSX_USE_CORE_TEXT && wxOSX_USE_CORE_TEXT + cgFont = CTFontCopyGraphicsFont((CTFontRef)font->MacGetCTFont(), NULL); +#else + ATSFontRef fontRef; fontRef = FMGetATSFontRefFromFont(font->MacGetATSUFontID()); if (fontRef) cgFont = CGFontCreateWithPlatformFont((void*)&fontRef); - +#endif + if (cgFont) { int iAscent; int iDescent; @@ -89,7 +94,7 @@ void GetTextExtent( const wxFont& font, const wxString& str, wxCoord *width, wxC // we need the scale here ... - Fixed atsuSize = IntToFixed( int( /*m_scaleY*/ 1 * font.MacGetFontSize()) ) ; + Fixed atsuSize = IntToFixed( int( /*m_scaleY*/ 1 * font.GetPointSize()) ) ; //RGBColor atsuColor = MAC_WXCOLORREF( m_textForegroundColor.GetPixel() ) ; ATSUAttributeTag atsuTags[] = { diff --git a/WebCore/platform/wx/wxcode/mac/carbon/non-kerned-drawing.cpp b/WebCore/platform/wx/wxcode/mac/carbon/non-kerned-drawing.cpp index 126f7ec..6eaa765 100644 --- a/WebCore/platform/wx/wxcode/mac/carbon/non-kerned-drawing.cpp +++ b/WebCore/platform/wx/wxcode/mac/carbon/non-kerned-drawing.cpp @@ -30,6 +30,7 @@ #include <wx/defs.h> #include <wx/dcclient.h> +#include <wx/dcgraph.h> #include <wx/gdicmn.h> #include <vector> @@ -43,9 +44,9 @@ void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* wxDC* dc = graphicsContext->platformContext(); #endif - wxFont wxfont = font->getWxFont(); - if (wxfont.IsOk()) - dc->SetFont(wxfont); + wxFont* wxfont = font->getWxFont(); + if (wxfont->IsOk()) + dc->SetFont(*wxfont); dc->SetTextForeground(color); // convert glyphs to wxString diff --git a/WebCore/platform/wx/wxcode/non-kerned-drawing.h b/WebCore/platform/wx/wxcode/non-kerned-drawing.h index d005985..b995d37 100644 --- a/WebCore/platform/wx/wxcode/non-kerned-drawing.h +++ b/WebCore/platform/wx/wxcode/non-kerned-drawing.h @@ -27,10 +27,25 @@ #include "GlyphBuffer.h"
#include <wx/defs.h>
-#include <wx/dcclient.h>
+#include <wx/dcclient.h> + +#if __WXGTK__ && USE(WXGC) +#include <cairo.h> +#include <pango/pango.h> +#include <pango/pangocairo.h> +#endif
namespace WebCore {
extern void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point);
-
-}
+ +#if __WXGTK__ && USE(WXGC) +PangoFontMap* pangoFontMap(); + +PangoFont* createPangoFontForFont(const wxFont* wxfont); +cairo_scaled_font_t* createScaledFontForFont(const wxFont* wxfont); +PangoGlyph pango_font_get_glyph(PangoFont* font, PangoContext* context, gunichar wc); + +#endif +} + diff --git a/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp b/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp index f05923a..7d1e924 100644 --- a/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp +++ b/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp @@ -101,7 +101,9 @@ void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* for (unsigned i = 0; i < numGlyphs; ++i) spacing[i] = advances[i].width(); - ::SelectObject(hdc, GetHfontOf(font->getWxFont())); + wxFont* wxfont = font->getWxFont(); + if (wxfont && wxfont->IsOk()) + ::SelectObject(hdc, GetHfontOf(*wxfont)); if (color.Ok()) ::SetTextColor(hdc, color.GetPixel()); |