diff options
| author | Steve Block <steveblock@google.com> | 2011-05-06 11:45:16 +0100 |
|---|---|---|
| committer | Steve Block <steveblock@google.com> | 2011-05-12 13:44:10 +0100 |
| commit | cad810f21b803229eb11403f9209855525a25d57 (patch) | |
| tree | 29a6fd0279be608e0fe9ffe9841f722f0f4e4269 /Source/WebCore/platform/wx/wxcode | |
| parent | 121b0cf4517156d0ac5111caf9830c51b69bae8f (diff) | |
| download | external_webkit-cad810f21b803229eb11403f9209855525a25d57.zip external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.gz external_webkit-cad810f21b803229eb11403f9209855525a25d57.tar.bz2 | |
Merge WebKit at r75315: Initial merge by git.
Change-Id: I570314b346ce101c935ed22a626b48c2af266b84
Diffstat (limited to 'Source/WebCore/platform/wx/wxcode')
13 files changed, 1638 insertions, 0 deletions
diff --git a/Source/WebCore/platform/wx/wxcode/fontprops.cpp b/Source/WebCore/platform/wx/wxcode/fontprops.cpp new file mode 100644 index 0000000..56d21bd --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/fontprops.cpp @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// this is a hacky way of doing it, but we don't +// currently have info on which platform we're being +// compiled for directly. +#if __WXMAC__ +#include "mac/carbon/fontprops.cpp" +#elif __WXMSW__ +#include "win/fontprops.cpp" +#else +#include "gtk/fontprops.cpp" +#endif diff --git a/Source/WebCore/platform/wx/wxcode/fontprops.h b/Source/WebCore/platform/wx/wxcode/fontprops.h new file mode 100644 index 0000000..7702db2 --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/fontprops.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <wx/defs.h> +#include <wx/font.h> + +void GetTextExtent( const wxFont& font, const wxString& str, wxCoord *width, wxCoord *height, + wxCoord *descent = NULL, wxCoord *externalLeading = NULL ); + +class wxFontProperties{ + +public: + wxFontProperties(wxFont* font); + float GetAscent() { return m_ascent; } + float GetDescent() { return m_descent; } + float GetLineGap() { return m_lineGap; } + float GetLineSpacing() { return m_lineSpacing; } + float GetXHeight() { return m_xHeight; } + +private: + float m_ascent; + float m_descent; + float m_lineGap; + float m_lineSpacing; + float m_xHeight; + +}; + +bool wxFontContainsCharacters(void* font, const UChar* characters, int length); diff --git a/Source/WebCore/platform/wx/wxcode/gtk/fontprops.cpp b/Source/WebCore/platform/wx/wxcode/gtk/fontprops.cpp new file mode 100644 index 0000000..491458d --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/gtk/fontprops.cpp @@ -0,0 +1,172 @@ +/* + * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +// this needs to be included before fontprops.h for UChar* to be defined. +#include <wtf/unicode/Unicode.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 + if ( font && font->Ok() ) + { + pango_layout_set_font_description + ( + layout, + font->GetNativeFontInfo()->description + ); + } + + PangoFontMetrics* metrics = pango_context_get_metrics (context, font->GetNativeFontInfo()->description, NULL); + + int height = font->GetPixelSize().GetHeight(); + + m_ascent = PANGO_PIXELS(pango_font_metrics_get_ascent(metrics)); + m_descent = PANGO_PIXELS(pango_font_metrics_get_descent(metrics)); + + int h; + + const char* x = "x"; + pango_layout_set_text( layout, x, strlen(x) ); + pango_layout_get_pixel_size( layout, NULL, &h ); + + m_xHeight = h; + m_lineGap = (m_ascent + m_descent) / 4; // FIXME: How can we calculate this via Pango? + m_lineSpacing = m_ascent + m_descent; + + pango_font_metrics_unref(metrics); +#endif +} + +bool wxFontContainsCharacters(const wxFont& font, const UChar* characters, int length) +{ + return true; +} + +void GetTextExtent( const wxFont& font, const wxString& str, wxCoord *width, wxCoord *height, + wxCoord *descent, wxCoord *externalLeading ) +{ + if ( width ) + *width = 0; + if ( height ) + *height = 0; + if ( descent ) + *descent = 0; + if ( externalLeading ) + *externalLeading = 0; + + 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 && font->IsOk() ) + { + pango_layout_set_font_description + ( + m_layout, + font->GetNativeFontInfo()->description + ); + } + + // Set layout's text + const wxCharBuffer dataUTF8 = wxConvUTF8.cWX2MB(str); + if ( !dataUTF8 ) + { + // hardly ideal, but what else can we do if conversion failed? + return; + } + + pango_layout_set_text( m_layout, dataUTF8, strlen(dataUTF8) ); + + int h = 0; + pango_layout_get_pixel_size( m_layout, width, &h ); + + if (descent) + { + 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; +#endif +} + diff --git a/Source/WebCore/platform/wx/wxcode/gtk/non-kerned-drawing.cpp b/Source/WebCore/platform/wx/wxcode/gtk/non-kerned-drawing.cpp new file mode 100644 index 0000000..bf745e0 --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/gtk/non-kerned-drawing.cpp @@ -0,0 +1,245 @@ +/* + * Copyright (C) 2007 Kevin Watters, Kevin Ollivier. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "GlyphBuffer.h" +#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(); + + wxFont* wxfont = font->getWxFont(); + if (wxfont && wxfont->IsOk()) + dc->SetFont(*wxfont); + dc->SetTextForeground(color); + + // convert glyphs to wxString + GlyphBufferGlyph* glyphs = const_cast<GlyphBufferGlyph*>(glyphBuffer.glyphs(from)); + int offset = point.x(); + wxString text = wxEmptyString; + for (unsigned i = 0; i < numGlyphs; i++) { + text = text.Append((wxChar)glyphs[i]); + offset += glyphBuffer.advanceAt(from + i); + } + + // the y point is actually the bottom point of the text, turn it into the top + float height = font->ascent() - font->descent(); + wxCoord ypoint = (wxCoord) (point.y() - height); + + dc->DrawText(text, (wxCoord)point.x(), ypoint); +#endif +} + +} diff --git a/Source/WebCore/platform/wx/wxcode/gtk/scrollbar_render.cpp b/Source/WebCore/platform/wx/wxcode/gtk/scrollbar_render.cpp new file mode 100644 index 0000000..3b4daa8 --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/gtk/scrollbar_render.cpp @@ -0,0 +1,177 @@ +/* + * Copyright (C) 2009 Kevin Ollivier All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "scrollbar_render.h" + +#include <wx/defs.h> +#include <wx/dc.h> +#include <wx/dcgraph.h> +#include <wx/renderer.h> +#include <wx/settings.h> +#include <wx/window.h> + +#include <gtk/gtk.h> + +#if wxCHECK_VERSION(2, 9, 0) + #include <wx/gtk/dc.h> +#else + #include "wx/gtk/win_gtk.h" +#endif + +int wxStyleForPart(wxScrollbarPart part, wxScrollbarPart focusPart, wxScrollbarPart hoverPart, int flags) +{ + int style = 0; + if (flags == wxCONTROL_DISABLED) + style = wxCONTROL_DISABLED; + else if (part == focusPart) + style = wxCONTROL_PRESSED; + else if (part == hoverPart) + style = wxCONTROL_CURRENT; + + return style; +} + +GtkWidget* GetButtonWidget() +{ + static GtkWidget *s_button = NULL; + static GtkWidget *s_window = NULL; + + if ( !s_button ) + { + s_window = gtk_window_new( GTK_WINDOW_POPUP ); + gtk_widget_realize( s_window ); + s_button = gtk_button_new(); + gtk_container_add( GTK_CONTAINER(s_window), s_button ); + gtk_widget_realize( s_button ); + } + + return s_button; +} + + +GdkWindow* wxGetGdkWindowForDC(wxWindow* win, wxDC& dc) +{ + GdkWindow* gdk_window = NULL; +#if wxCHECK_VERSION(2, 9, 0) + if ( dc.IsKindOf( CLASSINFO(wxGCDC) ) ) + gdk_window = win->GTKGetDrawingWindow(); + else + { + wxGTKDCImpl *impl = wxDynamicCast(dc.GetImpl(), wxGTKDCImpl); + if ( impl ) + gdk_window = impl->GetGDKWindow(); + } +#else // wx < 2.9 + // The way to get a GdkWindow* from a wxWindow is to use + // GTK_PIZZA(win->m_wxwindow)->bin_window, but this approach + // won't work when drawing to a wxMemoryDC as it has its own + // GdkWindow* for its bitmap. wxWindowDC's GetGDKWindow() was + // designed to create a solution for all DCs, but we can't + // implement it with wxGCDC since it doesn't retain its wxWindow. + // So, to work around this, we use GetGDKWindow whenever possible + // and use bin_window for wxGCDC. +#if wxUSE_GRAPHICS_CONTEXT + if ( dc.IsKindOf( CLASSINFO(wxGCDC) ) ) + gdk_window = GTK_PIZZA(win->m_wxwindow)->bin_window; + else +#endif + gdk_window = dc.GetGDKWindow(); + wxASSERT_MSG( gdk_window, + wxT("cannot use wxRendererNative on wxDC of this type") ); +#endif // wx 2.9/2.8 + + return gdk_window; +} + +void wxRenderer_DrawScrollbar(wxWindow* window, wxDC& dc, const wxRect& rect, wxOrientation orient, + int current, wxScrollbarPart focusPart, wxScrollbarPart hoverPart, int max, int step, int flags) +{ + bool horiz = orient == wxHORIZONTAL; + wxColour scrollbar_colour = wxSystemSettings::GetColour(wxSYS_COLOUR_SCROLLBAR); + dc.SetBrush(wxBrush(scrollbar_colour)); + dc.SetPen(wxPen(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNSHADOW))); + dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height); + + // when going from Cairo -> Gdk, any Cairo context transformations are lost + // so we need to alter the coordinates to reflect their transformed point. + double xtrans = 0; + double ytrans = 0; + + wxGCDC* gcdc = wxDynamicCast(&dc, wxGCDC); + wxGraphicsContext* gc = gcdc->GetGraphicsContext(); + gc->GetTransform().TransformPoint(&xtrans, &ytrans); + + wxRendererNative& renderer = wxRendererNative::Get(); + int x = rect.x + (int)xtrans; + int y = rect.y + (int)ytrans; + + int buttonLength = 16; + + renderer.DrawPushButton(window, dc, wxRect(x,y,buttonLength,buttonLength), wxStyleForPart(wxSCROLLPART_BACKBTNSTART, focusPart, hoverPart, flags)); + + GtkWidget* button = GetButtonWidget(); + GdkWindow* gdk_window = wxGetGdkWindowForDC(window, dc); + + GtkArrowType arrowType = GTK_ARROW_UP; + if (horiz) + arrowType = GTK_ARROW_LEFT; + + gtk_paint_arrow( button->style, gdk_window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, button, "arrow", arrowType, false, x + 4, y + 4, 8, 8); + + wxRect buttonRect = rect; + int physicalLength = horiz ? rect.width : rect.height; + physicalLength -= buttonLength*2; + int thumbStart = 0; + int thumbLength = 0; + calcThumbStartAndLength(physicalLength, max, current, step, &thumbStart, &thumbLength); + + if (horiz) { + buttonRect.x = x + thumbStart + buttonLength; + buttonRect.y = y; + buttonRect.width = thumbLength; + } else { + buttonRect.x = x; + buttonRect.y = y + thumbStart + buttonLength; + buttonRect.height = thumbLength; + } + + renderer.DrawPushButton(window, dc, buttonRect, wxStyleForPart(wxSCROLLPART_THUMB, focusPart, hoverPart, flags)); + + if (horiz) + x += rect.width - buttonLength; + else + y += rect.height - buttonLength; + + renderer.DrawPushButton(window, dc, wxRect(x,y,buttonLength,buttonLength), wxStyleForPart(wxSCROLLPART_FWDBTNEND, focusPart, hoverPart, flags)); + + if (horiz) + arrowType = GTK_ARROW_RIGHT; + else + arrowType = GTK_ARROW_DOWN; + + gtk_paint_arrow( button->style, gdk_window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, NULL, button, "arrow", arrowType, false, x + 4, y + 4, 8, 8); +} diff --git a/Source/WebCore/platform/wx/wxcode/mac/carbon/fontprops.mm b/Source/WebCore/platform/wx/wxcode/mac/carbon/fontprops.mm new file mode 100644 index 0000000..9da47fd --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/mac/carbon/fontprops.mm @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +// this needs to be included before fontprops.h for UChar* to be defined. +#include <wtf/unicode/Unicode.h> + +#include "fontprops.h" +#include "WebCoreSystemInterface.h" + +#include <ApplicationServices/ApplicationServices.h> + +#include <wx/defs.h> +#include <wx/gdicmn.h> +#include <wx/graphics.h> + +const float smallCapsFontSizeMultiplier = 0.7f; +const float contextDPI = 72.0f; +static inline float scaleEmToUnits(float x, unsigned unitsPerEm) { return x * (contextDPI / (contextDPI * unitsPerEm)); } + +wxFontProperties::wxFontProperties(wxFont* font): +m_ascent(0), m_descent(0), m_lineGap(0), m_lineSpacing(0), m_xHeight(0) +{ + CGFontRef cgFont; + +#ifdef wxOSX_USE_CORE_TEXT && wxOSX_USE_CORE_TEXT + cgFont = CTFontCopyGraphicsFont((CTFontRef)font->OSXGetCTFont(), NULL); +#else + ATSFontRef fontRef; + + fontRef = FMGetATSFontRefFromFont(font->MacGetATSUFontID()); + + if (fontRef) + cgFont = CGFontCreateWithPlatformFont((void*)&fontRef); +#endif + + if (cgFont) { + int iAscent; + int iDescent; + int iLineGap; + unsigned unitsPerEm; +#ifdef BUILDING_ON_TIGER + wkGetFontMetrics(cgFont, &iAscent, &iDescent, &iLineGap, &unitsPerEm); +#else + iAscent = CGFontGetAscent(cgFont); + iDescent = CGFontGetDescent(cgFont); + iLineGap = CGFontGetLeading(cgFont); + unitsPerEm = CGFontGetUnitsPerEm(cgFont); +#endif + float pointSize = font->GetPointSize(); + float fAscent = scaleEmToUnits(iAscent, unitsPerEm) * pointSize; + float fDescent = -scaleEmToUnits(iDescent, unitsPerEm) * pointSize; + float fLineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize; + + m_ascent = lroundf(fAscent); + m_descent = lroundf(fDescent); + m_lineGap = lroundf(fLineGap); + wxCoord xHeight = 0; + GetTextExtent(*font, wxT("x"), NULL, &xHeight, NULL, NULL); + m_xHeight = lroundf(xHeight); + m_lineSpacing = m_ascent + m_descent + m_lineGap; + + } + + if (cgFont) + CGFontRelease(cgFont); + +} + +bool wxFontContainsCharacters(void* font, const UChar* characters, int length) +{ + NSString* string = [[NSString alloc] initWithCharactersNoCopy:const_cast<unichar*>(characters) length:length freeWhenDone:NO]; + NSCharacterSet* set = [[(NSFont*)font coveredCharacterSet] invertedSet]; + bool result = set && [string rangeOfCharacterFromSet:set].location == NSNotFound; + [string release]; + return result; +} + +void GetTextExtent( const wxFont& font, const wxString& str, wxCoord *width, wxCoord *height, + wxCoord *descent, wxCoord *externalLeading ) +{ + wxGraphicsContext * const gc = wxGraphicsContext::Create(); + + gc->SetFont(font, *wxBLACK); // colour doesn't matter but must be specified + struct GCTextExtent + { + wxDouble width, height, descent, externalLeading; + } e; + gc->GetTextExtent(str, &e.width, &e.height, &e.descent, &e.externalLeading); + if ( width ) + *width = wxCoord(e.width + .5); + if ( height ) + *height = wxCoord(e.height + .5); + if ( descent ) + *descent = wxCoord(e.descent + .5); + if ( externalLeading ) + *externalLeading = wxCoord(e.externalLeading + .5); + + delete gc; +} diff --git a/Source/WebCore/platform/wx/wxcode/mac/carbon/non-kerned-drawing.cpp b/Source/WebCore/platform/wx/wxcode/mac/carbon/non-kerned-drawing.cpp new file mode 100644 index 0000000..56a5d07 --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/mac/carbon/non-kerned-drawing.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2007 Kevin Watters, Kevin Ollivier. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "FloatSize.h" +#include "GlyphBuffer.h" +#include "GraphicsContext.h" +#include "SimpleFontData.h" +#include <wtf/Vector.h> + +#include <ApplicationServices/ApplicationServices.h> + +#include <dlfcn.h> + +#include <wx/defs.h> +#include <wx/dcclient.h> +#include <wx/dcgraph.h> +#include <wx/gdicmn.h> + +namespace WebCore { + +void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) +{ + graphicsContext->save(); + + wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext()); + + wxFont* wxfont = font->getWxFont(); + graphicsContext->setFillColor(graphicsContext->fillColor(), ColorSpaceDeviceRGB); + + CGContextRef cgContext = static_cast<CGContextRef>(dc->GetGraphicsContext()->GetNativeContext()); + + CGFontRef cgFont = font->platformData().cgFont(); + + CGContextSetFont(cgContext, cgFont); + + CGContextSetFontSize(cgContext, wxfont->GetPointSize()); + + CGFloat red, green, blue, alpha; + graphicsContext->fillColor().getRGBA(red, green, blue, alpha); + CGContextSetRGBFillColor(cgContext, red, green, blue, alpha); + + CGAffineTransform matrix = CGAffineTransformIdentity; + matrix.b = -matrix.b; + matrix.d = -matrix.d; + + CGContextSetTextMatrix(cgContext, matrix); + + CGContextSetTextPosition(cgContext, point.x(), point.y()); + + CGContextShowGlyphsWithAdvances(cgContext, glyphBuffer.glyphs(from), glyphBuffer.advances(from), numGlyphs); + + if (cgFont) + CGFontRelease(cgFont); + graphicsContext->restore(); +} + +} diff --git a/Source/WebCore/platform/wx/wxcode/mac/carbon/scrollbar_render.cpp b/Source/WebCore/platform/wx/wxcode/mac/carbon/scrollbar_render.cpp new file mode 100644 index 0000000..5169601 --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/mac/carbon/scrollbar_render.cpp @@ -0,0 +1,107 @@ +/* + * Copyright (C) 2009 Kevin Ollivier All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + +#include "config.h" + +#include "scrollbar_render.h" + +#include <wx/defs.h> +#include <wx/dc.h> +#include <wx/dcgraph.h> +#include <wx/renderer.h> + +#include <Carbon/Carbon.h> + +static int wxScrollbarPartToHIPressedState(wxScrollbarPart part) +{ + switch (part) { + case wxSCROLLPART_BACKBTNSTART: + return kThemeTopOutsideArrowPressed; + case wxSCROLLPART_BACKBTNEND: + return kThemeTopOutsideArrowPressed; // This does not make much sense. For some reason the outside constant is required. + case wxSCROLLPART_FWDBTNSTART: + return kThemeTopInsideArrowPressed; + case wxSCROLLPART_FWDBTNEND: + return kThemeBottomOutsideArrowPressed; + case wxSCROLLPART_THUMB: + return kThemeThumbPressed; + default: + return 0; + } +} + +void wxRenderer_DrawScrollbar(wxWindow* WXUNUSED(window), wxDC& dc, + const wxRect& rect, wxOrientation orient, int current, + wxScrollbarPart focusPart, wxScrollbarPart hoverPart, int max, int step, int flags) +{ + const wxCoord x = rect.x; + const wxCoord y = rect.y; + const wxCoord w = rect.width; + const wxCoord h = rect.height; + + dc.SetBrush( *wxWHITE_BRUSH ); + dc.SetPen( *wxTRANSPARENT_PEN ); + dc.DrawRectangle(rect); + + dc.SetBrush( *wxTRANSPARENT_BRUSH ); + + HIRect hiRect = CGRectMake( x, y, w, h ); + + CGContextRef cgContext = NULL; + wxGraphicsContext* gc = NULL; +#if wxCHECK_VERSION(2,9,0) + wxGCDCImpl *impl = dynamic_cast<wxGCDCImpl*> (dc.GetImpl()); + if (impl) + gc = impl->GetGraphicsContext(); +#else + gc = dc.GetGraphicsContext(); +#endif + if (gc) + cgContext = (CGContextRef) gc->GetNativeContext(); + + if (cgContext) + { + HIThemeTrackDrawInfo trackInfo; + trackInfo.version = 0; + trackInfo.kind = kThemeMediumScrollBar; + trackInfo.bounds = hiRect; + trackInfo.min = 0; + trackInfo.max = max; + trackInfo.value = current; + trackInfo.trackInfo.scrollbar.viewsize = step; + trackInfo.attributes = 0; + if (orient == wxHORIZONTAL) + trackInfo.attributes |= kThemeTrackHorizontal; + trackInfo.enableState = (flags & wxCONTROL_FOCUSED) ? kThemeTrackActive : kThemeTrackInactive; + trackInfo.trackInfo.scrollbar.pressState = wxScrollbarPartToHIPressedState(focusPart); + trackInfo.attributes |= kThemeTrackShowThumb; + + if (flags & wxCONTROL_DISABLED) + trackInfo.enableState = kThemeTrackDisabled; + + HIThemeDrawTrack(&trackInfo, 0, cgContext, kHIThemeOrientationNormal); + } +} diff --git a/Source/WebCore/platform/wx/wxcode/non-kerned-drawing.h b/Source/WebCore/platform/wx/wxcode/non-kerned-drawing.h new file mode 100644 index 0000000..b995d37 --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/non-kerned-drawing.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2007 Kevin Watters, Kevin Ollivier. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */
+
+#include "Font.h"
+#include "GlyphBuffer.h"
+
+#include <wx/defs.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/Source/WebCore/platform/wx/wxcode/scrollbar_render.h b/Source/WebCore/platform/wx/wxcode/scrollbar_render.h new file mode 100644 index 0000000..5e0ea8e --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/scrollbar_render.h @@ -0,0 +1,68 @@ +/* + * Copyright (C) 2009 Kevin Ollivier All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef scrollbar_render_h +#define scrollbar_render_h + +#include <wx/defs.h> +#include <wx/dc.h> +#include <wx/renderer.h> + +enum wxScrollbarPart { + wxSCROLLPART_NONE = 0, + wxSCROLLPART_BACKBTNSTART = 1, + wxSCROLLPART_FWDBTNSTART = 1 << 1, + wxSCROLLPART_BACKTRACK = 1 << 2, + wxSCROLLPART_THUMB = 1 << 3, + wxSCROLLPART_FWDTRACK = 1 << 4, + wxSCROLLPART_BACKBTNEND = 1 << 5, + wxSCROLLPART_FWDBTNEND = 1 << 6, + wxSCROLLPART_SCROLLBARBG = 1 << 7, + wxSCROLLPART_TRACKBG = 1 << 8, + wxSCROLLPART_ALL = 0xffffffff, +}; + +void wxRenderer_DrawScrollbar(wxWindow* window, wxDC& dc, + const wxRect& rect, + wxOrientation orientation, + int current, wxScrollbarPart focusPart, wxScrollbarPart hoverPart, + int max, int step, int flags=0); + +inline void calcThumbStartAndLength(int physicalLength, int max, int current, + int step, int *thumbStart, int *thumbLength) +{ + float proportion = ((float)physicalLength - 8)/ (max + step); + float thumbSize = proportion * (float)physicalLength; + if (thumbSize < 20) + thumbSize = 20; + + float thumbPos = ((float)current / (float)max) * ((float)physicalLength - thumbSize); + if (thumbStart) + *thumbStart = thumbPos; + + if (thumbLength) + *thumbLength = thumbSize; +} +#endif diff --git a/Source/WebCore/platform/wx/wxcode/win/fontprops.cpp b/Source/WebCore/platform/wx/wxcode/win/fontprops.cpp new file mode 100644 index 0000000..f3e4fda --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/win/fontprops.cpp @@ -0,0 +1,181 @@ +/* + * Copyright (C) 2007 Kevin Ollivier <kevino@theolliviers.com> + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +// this needs to be included before fontprops.h for UChar* to be defined. +#include <wtf/unicode/Unicode.h> + +#include "fontprops.h" +#include "math.h" +#include "MathExtras.h" + +#include <wx/defs.h> +#include <wx/gdicmn.h> +#include <wx/wx.h> +#include "wx/msw/private.h" + +#include <mlang.h> +#include <usp10.h> + +inline long my_round(double x) +{ + return (long)(x < 0 ? x - 0.5 : x + 0.5); +} + +wxFontProperties::wxFontProperties(wxFont* font): +m_ascent(0), m_descent(0), m_lineGap(0), m_lineSpacing(0), m_xHeight(0) +{ + HDC dc = GetDC(0); + WXHFONT hFont = font->GetHFONT(); + ::SelectObject(dc, hFont); + if (font){ + + int height = font->GetPointSize(); + + TEXTMETRIC tm; + GetTextMetrics(dc, &tm); + m_ascent = lroundf(tm.tmAscent); + m_descent = lroundf(tm.tmDescent); + m_xHeight = m_ascent * 0.56f; // Best guess for xHeight for non-Truetype fonts. + m_lineGap = lroundf(tm.tmExternalLeading); + m_lineSpacing = m_lineGap + m_ascent + m_descent; + } + RestoreDC(dc, -1); + ReleaseDC(0, dc); +} + +bool wxFontContainsCharacters(void* font, const UChar* characters, int length) +{ + // FIXME: Microsoft documentation seems to imply that characters can be output using a given font and DC + // merely by testing code page intersection. This seems suspect though. Can't a font only partially + // cover a given code page? + static IMultiLanguage *multiLanguage; + if (!multiLanguage) { + if (CoCreateInstance(CLSID_CMultiLanguage, 0, CLSCTX_ALL, IID_IMultiLanguage, (void**)&multiLanguage) != S_OK) + return true; + } + + static IMLangFontLink2* langFontLink; + if (!langFontLink) { + if (multiLanguage->QueryInterface(&langFontLink) != S_OK) + return true; + } + + HDC dc = GetDC(0); + + DWORD acpCodePages; + langFontLink->CodePageToCodePages(CP_ACP, &acpCodePages); + + DWORD fontCodePages; + langFontLink->GetFontCodePages(dc, (HFONT)font, &fontCodePages); + + DWORD actualCodePages; + long numCharactersProcessed; + long offset = 0; + while (offset < length) { + langFontLink->GetStrCodePages(characters, length, acpCodePages, &actualCodePages, &numCharactersProcessed); + if ((actualCodePages & fontCodePages)) + return false; + offset += numCharactersProcessed; + } + + ReleaseDC(0, dc); + + return true; +} + +void GetTextExtent( const wxFont& font, const wxString& str, wxCoord *width, wxCoord *height, + wxCoord *descent, wxCoord *externalLeading ) +{ + HDC dc = GetDC(0); + WXHFONT hFont = font.GetHFONT(); + ::SelectObject(dc, hFont); + + HFONT hfontOld; + if ( font != wxNullFont ) + { + wxASSERT_MSG( font.Ok(), _T("invalid font in wxDC::GetTextExtent") ); + + hfontOld = (HFONT)::SelectObject(dc, hFont); + } + else // don't change the font + { + hfontOld = 0; + } + + SIZE sizeRect; + const size_t len = str.length(); + if ( !::GetTextExtentPoint32(dc, str, len, &sizeRect) ) + { + wxLogLastError(_T("GetTextExtentPoint32()")); + } + +#if !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) + // the result computed by GetTextExtentPoint32() may be too small as it + // accounts for under/overhang of the first/last character while we want + // just the bounding rect for this string so adjust the width as needed + // (using API not available in 2002 SDKs of WinCE) + if ( len > 1 ) + { + ABC width; + const wxChar chFirst = *str.begin(); + if ( ::GetCharABCWidths(dc, chFirst, chFirst, &width) ) + { + if ( width.abcA < 0 ) + sizeRect.cx -= width.abcA; + + if ( len > 1 ) + { + const wxChar chLast = *str.rbegin(); + ::GetCharABCWidths(dc, chLast, chLast, &width); + } + //else: we already have the width of the last character + + if ( width.abcC < 0 ) + sizeRect.cx -= width.abcC; + } + //else: GetCharABCWidths() failed, not a TrueType font? + } +#endif // !defined(_WIN32_WCE) || (_WIN32_WCE >= 400) + + TEXTMETRIC tm; + ::GetTextMetrics(dc, &tm); + + if (width) + *width = sizeRect.cx; + if (height) + *height = sizeRect.cy; + if (descent) + *descent = tm.tmDescent; + if (externalLeading) + *externalLeading = tm.tmExternalLeading; + + if ( hfontOld ) + { + ::SelectObject(dc, hfontOld); + } + + ReleaseDC(0, dc); +} diff --git a/Source/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp b/Source/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp new file mode 100644 index 0000000..2fcd761 --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/win/non-kerned-drawing.cpp @@ -0,0 +1,136 @@ +/* + * Copyright (C) 2007 Kevin Watters, Kevin Ollivier. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" +#include "GlyphBuffer.h" +#include "GraphicsContext.h" +#include "SimpleFontData.h" + +#include <wx/defs.h> +#include <wx/dcclient.h> +#include <wx/dcgraph.h> +#include <wx/gdicmn.h> +#include <vector> + +using namespace std; + +//----------------------------------------------------------------------------- +// constants +//----------------------------------------------------------------------------- + +const double RAD2DEG = 180.0 / M_PI; + +//----------------------------------------------------------------------------- +// Local functions +//----------------------------------------------------------------------------- + +static inline double dmin(double a, double b) { return a < b ? a : b; } +static inline double dmax(double a, double b) { return a > b ? a : b; } + +static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } +static inline double RadToDeg(double deg) { return (deg * 180.0) / M_PI; } + +#include "wx/msw/private.h" + +// TODO remove this dependency (gdiplus needs the macros) + +#ifndef max +#define max(a,b) (((a) > (b)) ? (a) : (b)) +#endif + +#ifndef min +#define min(a,b) (((a) < (b)) ? (a) : (b)) +#endif + +#include "gdiplus.h" + + +namespace WebCore { + +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()); +#else + wxDC* dc = graphicsContext->platformContext(); +#endif + + // get the native HDC handle to draw using native APIs + HDC hdc = 0; + float y = point.y() - font->ascent(); + float x = point.x(); + +#if USE(WXGC) + // when going from GdiPlus -> Gdi, any GdiPlus transformations are lost + // so we need to alter the coordinates to reflect their transformed point. + double xtrans = 0; + double ytrans = 0; + + wxGraphicsContext* gc = dc->GetGraphicsContext(); + gc->GetTransform().TransformPoint(&xtrans, &ytrans); + Gdiplus::Graphics* g; + if (gc) { + g = (Gdiplus::Graphics*)gc->GetNativeContext(); + hdc = g->GetHDC(); + } + x += (int)xtrans; + y += (int)ytrans; +#else + hdc = static_cast<HDC>(dc->GetHDC()); +#endif + + // ExtTextOut wants the offsets as an array of ints, so extract them + // from the glyph buffer + const GlyphBufferGlyph* glyphs = glyphBuffer.glyphs(from); + const GlyphBufferAdvance* advances = glyphBuffer.advances(from); + + int* spacing = new int[numGlyphs - from]; + for (unsigned i = 0; i < numGlyphs; ++i) + spacing[i] = advances[i].width(); + + wxFont* wxfont = font->getWxFont(); + if (wxfont && wxfont->IsOk()) + ::SelectObject(hdc, GetHfontOf(*wxfont)); + + if (color.Ok()) + ::SetTextColor(hdc, color.GetPixel()); + + // do not draw background behind characters + ::SetBkMode(hdc, TRANSPARENT); + + // draw text with optional character widths array + wxString string = wxString((wxChar*)(&glyphs[from]), numGlyphs); + ::ExtTextOut(hdc, x, y, ETO_GLYPH_INDEX, 0, reinterpret_cast<const WCHAR*>(glyphs), numGlyphs, spacing); + + ::SetBkMode(hdc, TRANSPARENT); + + #if USE(WXGC) + g->ReleaseHDC(hdc); + #endif + + delete [] spacing; +} + +} diff --git a/Source/WebCore/platform/wx/wxcode/win/scrollbar_render.cpp b/Source/WebCore/platform/wx/wxcode/win/scrollbar_render.cpp new file mode 100644 index 0000000..890db00 --- /dev/null +++ b/Source/WebCore/platform/wx/wxcode/win/scrollbar_render.cpp @@ -0,0 +1,213 @@ +/* + * Copyright (C) 2009 Kevin Ollivier All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "config.h" + +#include "scrollbar_render.h" + +#include <wx/defs.h> + +#include <wx/dc.h> +#include <wx/dcgraph.h> +#include <wx/graphics.h> +#include <wx/renderer.h> +#include <wx/window.h> + +#include <wx/msw/private.h> +#include <wx/msw/uxtheme.h> + +// constants +#define SP_BUTTON 1 +#define SP_THUMBHOR 2 +#define SP_THUMBVERT 3 +#define SP_TRACKENDHOR 4 +#define SP_TRACKENDVERT 7 +#define SP_GRIPPERHOR 8 +#define SP_GRIPPERVERT 9 + +#define TS_NORMAL 1 +#define TS_HOVER 2 +#define TS_ACTIVE 3 +#define TS_DISABLED 4 + +#define TS_UP_BUTTON 0 +#define TS_DOWN_BUTTON 4 +#define TS_LEFT_BUTTON 8 +#define TS_RIGHT_BUTTON 12 + +#if wxUSE_GRAPHICS_CONTEXT +// TODO remove this dependency (gdiplus needs the macros) +// we need to undef because the macros are being defined in WebCorePrefix.h +// but GdiPlus.h is not accepting them +#undef max +#define max(a,b) (((a) > (b)) ? (a) : (b)) + +#undef min +#define min(a,b) (((a) < (b)) ? (a) : (b)) + +#include <wx/dcgraph.h> +#include "gdiplus.h" +using namespace Gdiplus; +#endif // wxUSE_GRAPHICS_CONTEXT + +class GraphicsHDC +{ +public: + GraphicsHDC(wxDC* dc) + { +#if wxUSE_GRAPHICS_CONTEXT + m_graphics = NULL; + wxGCDC* gcdc = wxDynamicCast(dc, wxGCDC); + if (gcdc) { + m_graphics = (Graphics*)gcdc->GetGraphicsContext()->GetNativeContext(); + m_hdc = m_graphics->GetHDC(); + } + else +#endif + m_hdc = GetHdcOf(*dc); + } + + ~GraphicsHDC() + { +#if wxUSE_GRAPHICS_CONTEXT + if (m_graphics) + m_graphics->ReleaseHDC(m_hdc); +#endif + } + + operator HDC() const { return m_hdc; } + +private: + HDC m_hdc; +#if wxUSE_GRAPHICS_CONTEXT + Graphics* m_graphics; +#endif +}; + +int getTSStateForPart(wxScrollbarPart part, wxScrollbarPart focusPart, wxScrollbarPart hoverPart, int flags = 0) +{ + int xpState = TS_NORMAL; + if (flags & wxCONTROL_DISABLED) + xpState = TS_DISABLED; + else if (part == focusPart) + xpState = TS_ACTIVE; + else if (part == hoverPart) + xpState = TS_HOVER; + + return xpState; +} + +void wxRenderer_DrawScrollbar(wxWindow* window, wxDC& dc, + const wxRect& rect, wxOrientation orient, int current, wxScrollbarPart focusPart, wxScrollbarPart hoverPart, int max, int step, int flags) +{ + wxUxThemeEngine *engine = wxUxThemeEngine::Get(); + HTHEME hTheme = (HTHEME)engine->OpenThemeData(0, L"SCROLLBAR"); + + bool horiz = orient == wxHORIZONTAL; + int part = 0; + if (horiz) + part = SP_TRACKENDHOR; + else + part = SP_TRACKENDVERT; + + int xpState = TS_NORMAL; + wxRect transRect = rect; + +#if USE(WXGC) + // when going from GdiPlus -> Gdi, any GdiPlus transformations are lost + // so we need to alter the coordinates to reflect their transformed point. + double xtrans = 0; + double ytrans = 0; + + wxGCDC* gcdc = wxDynamicCast(&dc, wxGCDC); + wxGraphicsContext* gc = gcdc->GetGraphicsContext(); + gc->GetTransform().TransformPoint(&xtrans, &ytrans); + + transRect.x += (int)xtrans; + transRect.y += (int)ytrans; +#endif + + RECT r; + wxCopyRectToRECT(transRect, r); + + // Unlike Mac, on MSW you draw the scrollbar piece by piece. + // so we draw the track first, then the buttons + if (hTheme) + { + engine->DrawThemeBackground(hTheme, GraphicsHDC(&dc), part, xpState, &r, 0); + + int buttonSize = 16; + + part = SP_BUTTON; + xpState = getTSStateForPart(wxSCROLLPART_BACKBTNSTART, focusPart, hoverPart, flags); + xpState += horiz ? TS_LEFT_BUTTON : TS_UP_BUTTON; + RECT buttonRect = r; + buttonRect.bottom = buttonRect.top + buttonSize; + buttonRect.right = buttonRect.left + buttonSize; + engine->DrawThemeBackground(hTheme, GraphicsHDC(&dc), part, xpState, &buttonRect, 0); + + xpState = getTSStateForPart(wxSCROLLPART_FWDBTNEND, focusPart, hoverPart, flags); + xpState += horiz ? TS_RIGHT_BUTTON : TS_DOWN_BUTTON; + buttonRect = r; + buttonRect.top = buttonRect.bottom - buttonSize; + buttonRect.left = buttonRect.right - buttonSize; + engine->DrawThemeBackground(hTheme, GraphicsHDC(&dc), part, xpState, &buttonRect, 0); + + part = horiz ? SP_THUMBHOR : SP_THUMBVERT; + + int physicalLength = horiz ? rect.width : rect.height; + physicalLength -= buttonSize*2; + int thumbStart = 0; + int thumbLength = 0; + calcThumbStartAndLength(physicalLength, max, + current, step, &thumbStart, &thumbLength); + buttonRect = r; + if (horiz) { + buttonRect.left = buttonRect.left + thumbStart + buttonSize; + buttonRect.right = buttonRect.left + thumbLength; + } else { + buttonRect.top = buttonRect.top + thumbStart + buttonSize; + buttonRect.bottom = buttonRect.top + thumbLength; + } + + xpState = getTSStateForPart(wxSCROLLPART_THUMB, focusPart, hoverPart, flags); + engine->DrawThemeBackground(hTheme, GraphicsHDC(&dc), part, xpState, &buttonRect, 0); + + // draw the gripper + int thickness = ::GetSystemMetrics(SM_CXVSCROLL) / 2; + + buttonRect.left += ((buttonRect.right - buttonRect.left) - thickness) / 2; + buttonRect.top += ((buttonRect.bottom - buttonRect.top) - thickness) / 2; + buttonRect.right = buttonRect.left + thickness; + buttonRect.bottom = buttonRect.top + thickness; + + if (horiz) + part = SP_GRIPPERHOR; + else + part = SP_GRIPPERVERT; + + engine->DrawThemeBackground(hTheme, GraphicsHDC(&dc), part, xpState, &buttonRect, 0); + } +} |
