diff options
author | Upstream <upstream-import@none> | 1970-01-12 13:46:40 +0000 |
---|---|---|
committer | Upstream <upstream-import@none> | 1970-01-12 13:46:40 +0000 |
commit | d8543bb6618c17b12da906afa77d216f58cf4058 (patch) | |
tree | c58dc05ed86825bd0ef8d305d58c8205106b540f /WebCore/svg/graphics | |
download | external_webkit-d8543bb6618c17b12da906afa77d216f58cf4058.zip external_webkit-d8543bb6618c17b12da906afa77d216f58cf4058.tar.gz external_webkit-d8543bb6618c17b12da906afa77d216f58cf4058.tar.bz2 |
external/webkit r30707
Diffstat (limited to 'WebCore/svg/graphics')
153 files changed, 12300 insertions, 0 deletions
diff --git a/WebCore/svg/graphics/SVGImage.cpp b/WebCore/svg/graphics/SVGImage.cpp new file mode 100644 index 0000000..de868b7 --- /dev/null +++ b/WebCore/svg/graphics/SVGImage.cpp @@ -0,0 +1,214 @@ +/* + * Copyright (C) 2006 Eric Seidel (eric@webkit.org) + * Copyright (C) 2008 Apple, Inc. 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" +#if ENABLE(SVG) +#include "SVGImage.h" + +#include "CachedPage.h" +#include "DocumentLoader.h" +#include "EditCommand.h" +#include "FloatRect.h" +#include "Frame.h" +#include "FrameLoader.h" +#include "FrameView.h" +#include "GraphicsContext.h" +#include "ImageObserver.h" +#include "NotImplemented.h" +#include "Page.h" +#include "ResourceError.h" +#include "SVGDocument.h" +#include "SVGLength.h" +#include "SVGRenderSupport.h" +#include "SVGSVGElement.h" +#include "Settings.h" + +#include "SVGImageEmptyClients.h" + +namespace WebCore { + +SVGImage::SVGImage(ImageObserver* observer) + : Image(observer) + , m_document(0) + , m_page(0) + , m_frame(0) + , m_frameView(0) +{ +} + +SVGImage::~SVGImage() +{ + if (m_frame) + m_frame->loader()->frameDetached(); // Break both the loader and view references to the frame +} + +void SVGImage::setContainerSize(const IntSize& containerSize) +{ + if (containerSize.width() <= 0 || containerSize.height() <= 0) + return; + + SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); + if (!rootElement) + return; + + rootElement->setContainerSize(containerSize); +} + +bool SVGImage::usesContainerSize() const +{ + SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); + if (!rootElement) + return false; + + return rootElement->hasSetContainerSize(); +} + +IntSize SVGImage::size() const +{ + if (!m_frame || !m_frame->document()) + return IntSize(); + + SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); + if (!rootElement) + return IntSize(); + + SVGLength width = rootElement->width(); + SVGLength height = rootElement->height(); + + IntSize svgSize; + if (width.unitType() == LengthTypePercentage) + svgSize.setWidth(rootElement->relativeWidthValue()); + else + svgSize.setWidth(static_cast<int>(width.value())); + + if (height.unitType() == LengthTypePercentage) + svgSize.setHeight(rootElement->relativeHeightValue()); + else + svgSize.setHeight(static_cast<int>(height.value())); + + return svgSize; +} + +bool SVGImage::hasRelativeWidth() const +{ + SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); + if (!rootElement) + return false; + + return rootElement->width().unitType() == LengthTypePercentage; +} + +bool SVGImage::hasRelativeHeight() const +{ + SVGSVGElement* rootElement = static_cast<SVGDocument*>(m_frame->document())->rootElement(); + if (!rootElement) + return false; + + return rootElement->height().unitType() == LengthTypePercentage; +} + +void SVGImage::draw(GraphicsContext* context, const FloatRect& dstRect, const FloatRect& srcRect, CompositeOperator compositeOp) +{ + if (!m_frame) + return; + + context->save(); + context->clip(enclosingIntRect(dstRect)); + context->translate(dstRect.location().x(), dstRect.location().y()); + context->scale(FloatSize(dstRect.width()/srcRect.width(), dstRect.height()/srcRect.height())); + + if (m_frame->view()->needsLayout()) + m_frame->view()->layout(); + m_frame->paint(context, enclosingIntRect(srcRect)); + + context->restore(); + + if (imageObserver()) + imageObserver()->didDraw(this); +} + +NativeImagePtr SVGImage::nativeImageForCurrentFrame() +{ + // FIXME: In order to support dynamic SVGs we need to have a way to invalidate this + // frame cache, or better yet, not use a cache for tiled drawing at all, instead + // having a tiled drawing callback (hopefully non-virtual). + if (!m_frameCache) { + m_frameCache.set(ImageBuffer::create(size(), false).release()); + if (!m_frameCache) // failed to allocate image + return 0; + renderSubtreeToImage(m_frameCache.get(), m_frame->renderer()); + } +#if PLATFORM(CG) + return m_frameCache->cgImage(); +#elif PLATFORM(QT) + return m_frameCache->pixmap(); +#elif PLATFORM(CAIRO) + return m_frameCache->surface(); +#else + notImplemented(); + return 0; +#endif +} + +bool SVGImage::dataChanged(bool allDataReceived) +{ + int length = m_data->size(); + if (!length) // if this was an empty image + return true; + + if (allDataReceived) { + static ChromeClient* dummyChromeClient = new SVGEmptyChromeClient; + static FrameLoaderClient* dummyFrameLoaderClient = new SVGEmptyFrameLoaderClient; + static EditorClient* dummyEditorClient = new SVGEmptyEditorClient; + static ContextMenuClient* dummyContextMenuClient = new SVGEmptyContextMenuClient; + static DragClient* dummyDragClient = new SVGEmptyDragClient; + static InspectorClient* dummyInspectorClient = new SVGEmptyInspectorClient; + + // FIXME: If this SVG ends up loading itself, we'll leak this Frame (and associated DOM & render trees). + // The Cache code does not know about CachedImages holding Frames and won't know to break the cycle. + m_page.set(new Page(dummyChromeClient, dummyContextMenuClient, dummyEditorClient, dummyDragClient, dummyInspectorClient)); + m_page->settings()->setJavaScriptEnabled(false); + + m_frame = new Frame(m_page.get(), 0, dummyFrameLoaderClient); + m_frame->init(); + m_frameView = new FrameView(m_frame.get()); + m_frameView->deref(); // FIXME: FrameView starts with a refcount of 1 + m_frame->setView(m_frameView.get()); + ResourceRequest fakeRequest(KURL("")); + m_frame->loader()->load(fakeRequest); // Make sure the DocumentLoader is created + m_frame->loader()->cancelContentPolicyCheck(); // cancel any policy checks + m_frame->loader()->commitProvisionalLoad(0); + m_frame->loader()->setResponseMIMEType("image/svg+xml"); + m_frame->loader()->begin(KURL()); // create the empty document + m_frame->loader()->write(m_data->data(), m_data->size()); + m_frame->loader()->end(); + } + return m_frameView; +} + +} + +#endif // ENABLE(SVG) diff --git a/WebCore/svg/graphics/SVGImage.h b/WebCore/svg/graphics/SVGImage.h new file mode 100644 index 0000000..3e67a7c --- /dev/null +++ b/WebCore/svg/graphics/SVGImage.h @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2006 Eric Seidel (eric@webkit.org) + * + * 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 SVGImage_h +#define SVGImage_h + +#if ENABLE(SVG) + +#include "Image.h" +#include "ImageBuffer.h" +#include "IntSize.h" +#include <wtf/OwnPtr.h> + +namespace WebCore { + + class SVGDocument; + class Frame; + class FrameView; + class Page; + + class SVGImage : public Image { + public: + SVGImage(ImageObserver*); + ~SVGImage(); + + virtual void setContainerSize(const IntSize&); + virtual bool usesContainerSize() const; + virtual bool hasRelativeWidth() const; + virtual bool hasRelativeHeight() const; + + virtual IntSize size() const; + + virtual bool dataChanged(bool allDataReceived); + + virtual NativeImagePtr frameAtIndex(size_t) { return 0; } + +private: + virtual void draw(GraphicsContext*, const FloatRect& fromRect, const FloatRect& toRect, CompositeOperator); + + virtual NativeImagePtr nativeImageForCurrentFrame(); + + SVGDocument* m_document; + OwnPtr<Page> m_page; + RefPtr<Frame> m_frame; + RefPtr<FrameView> m_frameView; + IntSize m_minSize; + OwnPtr<ImageBuffer> m_frameCache; + }; +} + +#endif // ENABLE(SVG) + +#endif diff --git a/WebCore/svg/graphics/SVGImageEmptyClients.h b/WebCore/svg/graphics/SVGImageEmptyClients.h new file mode 100644 index 0000000..ce9296a --- /dev/null +++ b/WebCore/svg/graphics/SVGImageEmptyClients.h @@ -0,0 +1,417 @@ +/* + * Copyright (C) 2006 Eric Seidel (eric@webkit.org) + * + * 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 SVGImageEmptyClients_h +#define SVGImageEmptyClients_h + +#if ENABLE(SVG) + +#include "ChromeClient.h" +#include "ContextMenuClient.h" +#include "DragClient.h" +#include "EditorClient.h" +#include "FocusDirection.h" +#include "FrameLoaderClient.h" +#include "InspectorClient.h" +#include "SharedBuffer.h" + +/* + This file holds empty Client stubs for use by SVGImage. + SVGImage needs to create a dummy Page->Frame->FrameView tree for use in parsing an SVGDocument. + This tree depends heavily on Clients (usually provided by WebKit classes). + + SVGImage has no way to access the current Page (nor should it, since Images are not tied to a page). + See http://bugs.webkit.org/show_bug.cgi?id=5971 for more discussion on this issue. + + Ideally, whenever you change a Client class, you should add a stub here. + Brittle, yes. Unfortunate, yes. Hopefully temporary. +*/ + +namespace WebCore { + +class SVGEmptyChromeClient : public ChromeClient { +public: + virtual ~SVGEmptyChromeClient() { } + virtual void chromeDestroyed() { } + + virtual void setWindowRect(const FloatRect&) { } + virtual FloatRect windowRect() { return FloatRect(); } + + virtual FloatRect pageRect() { return FloatRect(); } + + virtual float scaleFactor() { return 1.f; } + + virtual void focus() { } + virtual void unfocus() { } + + virtual bool canTakeFocus(FocusDirection) { return false; } + virtual void takeFocus(FocusDirection) { } + + virtual Page* createWindow(Frame*, const FrameLoadRequest&, const WindowFeatures&) { return 0; } + virtual void show() { } + + virtual bool canRunModal() { return false; } + virtual void runModal() { } + + virtual void setToolbarsVisible(bool) { } + virtual bool toolbarsVisible() { return false; } + + virtual void setStatusbarVisible(bool) { } + virtual bool statusbarVisible() { return false; } + + virtual void setScrollbarsVisible(bool) { } + virtual bool scrollbarsVisible() { return false; } + + virtual void setMenubarVisible(bool) { } + virtual bool menubarVisible() { return false; } + + virtual void setResizable(bool) { } + + virtual void addMessageToConsole(const String& message, unsigned int lineNumber, const String& sourceID) { } + + virtual bool canRunBeforeUnloadConfirmPanel() { return false; } + virtual bool runBeforeUnloadConfirmPanel(const String& message, Frame* frame) { return true; } + + virtual void closeWindowSoon() { } + + virtual void runJavaScriptAlert(Frame*, const String&) { } + virtual bool runJavaScriptConfirm(Frame*, const String&) { return false; } + virtual bool runJavaScriptPrompt(Frame*, const String& message, const String& defaultValue, String& result) { return false; } + virtual bool shouldInterruptJavaScript() { return false; } + + virtual void setStatusbarText(const String&) { } + + virtual bool tabsToLinks() const { return false; } + + virtual IntRect windowResizerRect() const { return IntRect(); } + virtual void addToDirtyRegion(const IntRect&) { } + virtual void scrollBackingStore(int dx, int dy, const IntRect& scrollViewRect, const IntRect& clipRect) { } + virtual void updateBackingStore() { } + + virtual void mouseDidMoveOverElement(const HitTestResult&, unsigned modifierFlags) { } + + virtual void setToolTip(const String&) { } + + virtual void print(Frame*) { } + + virtual void exceededDatabaseQuota(Frame*, const String&) { } +}; + +class SVGEmptyFrameLoaderClient : public FrameLoaderClient { +public: + virtual ~SVGEmptyFrameLoaderClient() { } + virtual void frameLoaderDestroyed() { } + + virtual bool hasWebView() const { return true; } // mainly for assertions + virtual bool hasFrameView() const { return true; } // ditto + + virtual void makeRepresentation(DocumentLoader*) { } + virtual void forceLayout() { } + virtual void forceLayoutForNonHTML() { } + + virtual void updateHistoryForCommit() { } + + virtual void updateHistoryForBackForwardNavigation() { } + virtual void updateHistoryForReload() { } + virtual void updateHistoryForStandardLoad() { } + virtual void updateHistoryForInternalLoad() { } + + virtual void updateHistoryAfterClientRedirect() { } + + virtual void setCopiesOnScroll() { } + + virtual void detachedFromParent2() { } + virtual void detachedFromParent3() { } + virtual void detachedFromParent4() { } + + virtual void download(ResourceHandle*, const ResourceRequest&, const ResourceRequest&, const ResourceResponse&) { } + + virtual void assignIdentifierToInitialRequest(unsigned long identifier, DocumentLoader*, const ResourceRequest&) { } + virtual void dispatchWillSendRequest(DocumentLoader*, unsigned long identifier, ResourceRequest&, const ResourceResponse& redirectResponse) { } + virtual void dispatchDidReceiveAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&) { } + virtual void dispatchDidCancelAuthenticationChallenge(DocumentLoader*, unsigned long identifier, const AuthenticationChallenge&) { } + virtual void dispatchDidReceiveResponse(DocumentLoader*, unsigned long identifier, const ResourceResponse&) { } + virtual void dispatchDidReceiveContentLength(DocumentLoader*, unsigned long identifier, int lengthReceived) { } + virtual void dispatchDidFinishLoading(DocumentLoader*, unsigned long identifier) { } + virtual void dispatchDidFailLoading(DocumentLoader*, unsigned long identifier, const ResourceError&) { } + virtual bool dispatchDidLoadResourceFromMemoryCache(DocumentLoader*, const ResourceRequest&, const ResourceResponse&, int length) { return false; } + + virtual void dispatchDidHandleOnloadEvents() { } + virtual void dispatchDidReceiveServerRedirectForProvisionalLoad() { } + virtual void dispatchDidCancelClientRedirect() { } + virtual void dispatchWillPerformClientRedirect(const KURL&, double interval, double fireDate) { } + virtual void dispatchDidChangeLocationWithinPage() { } + virtual void dispatchWillClose() { } + virtual void dispatchDidReceiveIcon() { } + virtual void dispatchDidStartProvisionalLoad() { } + virtual void dispatchDidReceiveTitle(const String& title) { } + virtual void dispatchDidCommitLoad() { } + virtual void dispatchDidFailProvisionalLoad(const ResourceError&) { } + virtual void dispatchDidFailLoad(const ResourceError&) { } + virtual void dispatchDidFinishDocumentLoad() { } + virtual void dispatchDidFinishLoad() { } + virtual void dispatchDidFirstLayout() { } + + virtual Frame* dispatchCreatePage() { return 0; } + virtual void dispatchShow() { } + + virtual void dispatchDecidePolicyForMIMEType(FramePolicyFunction, const String& MIMEType, const ResourceRequest&) { } + virtual void dispatchDecidePolicyForNewWindowAction(FramePolicyFunction, const NavigationAction&, const ResourceRequest&, const String& frameName) { } + virtual void dispatchDecidePolicyForNavigationAction(FramePolicyFunction, const NavigationAction&, const ResourceRequest&) { } + virtual void cancelPolicyCheck() { } + + virtual void dispatchUnableToImplementPolicy(const ResourceError&) { } + + virtual void dispatchWillSubmitForm(FramePolicyFunction, PassRefPtr<FormState>) { } + + virtual void dispatchDidLoadMainResource(DocumentLoader*) { } + virtual void revertToProvisionalState(DocumentLoader*) { } + virtual void setMainDocumentError(DocumentLoader*, const ResourceError&) { } + virtual void clearUnarchivingState(DocumentLoader*) { } + + virtual void willChangeEstimatedProgress() { } + virtual void didChangeEstimatedProgress() { } + virtual void postProgressStartedNotification() { } + virtual void postProgressEstimateChangedNotification() { } + virtual void postProgressFinishedNotification() { } + + virtual void setMainFrameDocumentReady(bool) { } + + virtual void startDownload(const ResourceRequest&) { } + + virtual void willChangeTitle(DocumentLoader*) { } + virtual void didChangeTitle(DocumentLoader*) { } + + virtual void committedLoad(DocumentLoader*, const char*, int) { } + virtual void finishedLoading(DocumentLoader*) { } + virtual void finalSetupForReplace(DocumentLoader*) { } + + virtual ResourceError cancelledError(const ResourceRequest&) { return ResourceError(); } + virtual ResourceError blockedError(const ResourceRequest&) { return ResourceError(); } + virtual ResourceError cannotShowURLError(const ResourceRequest&) { return ResourceError(); } + virtual ResourceError interruptForPolicyChangeError(const ResourceRequest&) { return ResourceError(); } + + virtual ResourceError cannotShowMIMETypeError(const ResourceResponse&) { return ResourceError(); } + virtual ResourceError fileDoesNotExistError(const ResourceResponse&) { return ResourceError(); } + + virtual bool shouldFallBack(const ResourceError&) { return false; } + + virtual void setDefersLoading(bool) { } + + virtual bool willUseArchive(ResourceLoader*, const ResourceRequest&, const KURL& originalURL) const { return false; } + virtual bool isArchiveLoadPending(ResourceLoader*) const { return false; } + virtual void cancelPendingArchiveLoad(ResourceLoader*) { } + virtual void clearArchivedResources() { } + + virtual bool canHandleRequest(const ResourceRequest&) const { return false; } + virtual bool canShowMIMEType(const String& MIMEType) const { return false; } + virtual bool representationExistsForURLScheme(const String& URLScheme) const { return false; } + virtual String generatedMIMETypeForURLScheme(const String& URLScheme) const { return ""; } + + virtual void frameLoadCompleted() { } + virtual void restoreViewState() { } + virtual void provisionalLoadStarted() { } + virtual bool shouldTreatURLAsSameAsCurrent(const KURL&) const { return false; } + virtual void addHistoryItemForFragmentScroll() { } + virtual void didFinishLoad() { } + virtual void prepareForDataSourceReplacement() { } + + virtual PassRefPtr<DocumentLoader> createDocumentLoader(const ResourceRequest& request, const SubstituteData& substituteData) { return new DocumentLoader(request, substituteData); } + virtual void setTitle(const String& title, const KURL&) { } + + virtual String userAgent(const KURL&) { return ""; } + + virtual void savePlatformDataToCachedPage(CachedPage*) { } + virtual void transitionToCommittedFromCachedPage(CachedPage*) { } + virtual void transitionToCommittedForNewPage() { } + + virtual void updateGlobalHistory(const KURL&) { } + virtual bool shouldGoToHistoryItem(HistoryItem*) const { return false; } + virtual void saveViewStateToItem(HistoryItem*) { } + virtual bool canCachePage() const { return false; } + + virtual PassRefPtr<Frame> createFrame(const KURL& url, const String& name, HTMLFrameOwnerElement* ownerElement, + const String& referrer, bool allowsScrolling, int marginWidth, int marginHeight) { return 0; } + virtual Widget* createPlugin(const IntSize&,Element*, const KURL&, const Vector<String>&, const Vector<String>&, const String&, bool) { return 0; } + virtual Widget* createJavaAppletWidget(const IntSize&, Element*, const KURL&, const Vector<String>&, const Vector<String>&) { return 0; } + + virtual ObjectContentType objectContentType(const KURL& url, const String& mimeType) { return ObjectContentType(); } + virtual String overrideMediaType() const { return String(); } + + virtual void redirectDataToPlugin(Widget*) {} + virtual void windowObjectCleared() {} + virtual void didPerformFirstNavigation() const {} + + virtual void registerForIconNotification(bool listen) {} + +#if PLATFORM(MAC) + virtual NSCachedURLResponse* willCacheResponse(DocumentLoader*, unsigned long identifier, NSCachedURLResponse* response) const { return response; } +#endif + +}; + +class SVGEmptyEditorClient : public EditorClient { +public: + virtual ~SVGEmptyEditorClient() { } + virtual void pageDestroyed() { } + + virtual bool shouldDeleteRange(Range*) { return false; } + virtual bool shouldShowDeleteInterface(HTMLElement*) { return false; } + virtual bool smartInsertDeleteEnabled() { return false; } + virtual bool isContinuousSpellCheckingEnabled() { return false; } + virtual void toggleContinuousSpellChecking() { } + virtual bool isGrammarCheckingEnabled() { return false; } + virtual void toggleGrammarChecking() { } + virtual int spellCheckerDocumentTag() { return -1; } + + virtual bool selectWordBeforeMenuEvent() { return false; } + virtual bool isEditable() { return false; } + + virtual bool shouldBeginEditing(Range*) { return false; } + virtual bool shouldEndEditing(Range*) { return false; } + virtual bool shouldInsertNode(Node*, Range*, EditorInsertAction) { return false; } + // virtual bool shouldInsertNode(Node*, Range* replacingRange, WebViewInsertAction) { return false; } + virtual bool shouldInsertText(String, Range*, EditorInsertAction) { return false; } + virtual bool shouldChangeSelectedRange(Range* fromRange, Range* toRange, EAffinity, bool stillSelecting) { return false; } + + virtual bool shouldApplyStyle(CSSStyleDeclaration*, Range*) { return false; } + virtual bool shouldMoveRangeAfterDelete(Range*, Range*) { return false; } + // virtual bool shouldChangeTypingStyle(CSSStyleDeclaration* fromStyle, CSSStyleDeclaration* toStyle) { return false; } + // virtual bool doCommandBySelector(SEL selector) { return false; } + // + virtual void didBeginEditing() { } + virtual void respondToChangedContents() { } + virtual void respondToChangedSelection() { } + virtual void didEndEditing() { } + virtual void didWriteSelectionToPasteboard() { } + virtual void didSetSelectionTypesForPasteboard() { } + // virtual void webViewDidChangeTypingStyle:(NSNotification *)notification { } + // virtual void webViewDidChangeSelection:(NSNotification *)notification { } + // virtual NSUndoManager* undoManagerForWebView:(WebView *)webView { return 0; } + + virtual void registerCommandForUndo(PassRefPtr<EditCommand>) { } + virtual void registerCommandForRedo(PassRefPtr<EditCommand>) { } + virtual void clearUndoRedoOperations() { } + + virtual bool canUndo() const { return false; } + virtual bool canRedo() const { return false; } + + virtual void undo() { } + virtual void redo() { } + + virtual void handleKeyboardEvent(KeyboardEvent*) { } + virtual void handleInputMethodKeydown(KeyboardEvent*) { } + + virtual void textFieldDidBeginEditing(Element*) { } + virtual void textFieldDidEndEditing(Element*) { } + virtual void textDidChangeInTextField(Element*) { } + virtual bool doTextFieldCommandFromEvent(Element*, KeyboardEvent*) { return false; } + virtual void textWillBeDeletedInTextField(Element*) { } + virtual void textDidChangeInTextArea(Element*) { } + +#if PLATFORM(MAC) + virtual void markedTextAbandoned(Frame*) { } + + // FIXME: This should become SelectionController::toWebArchive() + virtual NSData* dataForArchivedSelection(Frame*) { return 0; } + + virtual NSString* userVisibleString(NSURL*) { return 0; } +#ifdef BUILDING_ON_TIGER + virtual NSArray* pasteboardTypesForSelection(Frame*) { return 0; } +#endif +#endif + virtual void ignoreWordInSpellDocument(const String&) { } + virtual void learnWord(const String&) { } + virtual void checkSpellingOfString(const UChar*, int length, int* misspellingLocation, int* misspellingLength) { } + virtual void checkGrammarOfString(const UChar*, int length, Vector<GrammarDetail>&, int* badGrammarLocation, int* badGrammarLength) { } + virtual void updateSpellingUIWithGrammarString(const String&, const GrammarDetail&) { } + virtual void updateSpellingUIWithMisspelledWord(const String&) { } + virtual void showSpellingUI(bool show) { } + virtual bool spellingUIIsShowing() { return false; } + virtual void getGuessesForWord(const String&, Vector<String>& guesses) { } + virtual void setInputMethodState(bool enabled) { } + + +}; + +class SVGEmptyContextMenuClient : public ContextMenuClient { +public: + virtual ~SVGEmptyContextMenuClient() { } + virtual void contextMenuDestroyed() { } + + virtual PlatformMenuDescription getCustomMenuFromDefaultItems(ContextMenu*) { return 0; } + virtual void contextMenuItemSelected(ContextMenuItem*, const ContextMenu*) { } + + virtual void downloadURL(const KURL& url) { } + virtual void copyImageToClipboard(const HitTestResult&) { } + virtual void searchWithGoogle(const Frame*) { } + virtual void lookUpInDictionary(Frame*) { } + virtual void speak(const String&) { } + virtual void stopSpeaking() { } + +#if PLATFORM(MAC) + virtual void searchWithSpotlight() { } +#endif +}; + +class SVGEmptyDragClient : public DragClient { +public: + virtual ~SVGEmptyDragClient() {} + virtual void willPerformDragDestinationAction(DragDestinationAction, DragData*) { } + virtual void willPerformDragSourceAction(DragSourceAction, const IntPoint&, Clipboard*) { } + virtual DragDestinationAction actionMaskForDrag(DragData*) { return DragDestinationActionNone; } + virtual DragSourceAction dragSourceActionMaskForPoint(const IntPoint&) { return DragSourceActionNone; } + virtual void startDrag(DragImageRef, const IntPoint&, const IntPoint&, Clipboard*, Frame*, bool) { } + virtual DragImageRef createDragImageForLink(KURL&, const String& label, Frame*) { return 0; } + virtual void dragControllerDestroyed() { } +}; + +class SVGEmptyInspectorClient : public InspectorClient { +public: + virtual ~SVGEmptyInspectorClient() {} + + virtual void inspectorDestroyed() {}; + + virtual Page* createPage() { return 0; }; + + virtual String localizedStringsURL() { return String(); }; + + virtual void showWindow() {}; + virtual void closeWindow() {}; + + virtual void attachWindow() {}; + virtual void detachWindow() {}; + + virtual void highlight(Node*) {}; + virtual void hideHighlight() {}; + virtual void inspectedURLChanged(const String& newURL) {}; +}; + +} + +#endif // ENABLE(SVG) + +#endif // SVGImageEmptyClients_h + diff --git a/WebCore/svg/graphics/SVGPaintServer.cpp b/WebCore/svg/graphics/SVGPaintServer.cpp new file mode 100644 index 0000000..9a59683 --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServer.cpp @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * 2007 Rob Buis <buis@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "SVGPaintServer.h" + +#include "RenderObject.h" +#include "RenderStyle.h" +#include "SVGPaintServerSolid.h" +#include "SVGStyledElement.h" +#include "SVGURIReference.h" + +namespace WebCore { + +SVGPaintServer::SVGPaintServer() +{ +} + +SVGPaintServer::~SVGPaintServer() +{ +} + +TextStream& operator<<(TextStream& ts, const SVGPaintServer& paintServer) +{ + return paintServer.externalRepresentation(ts); +} + +SVGPaintServer* getPaintServerById(Document* document, const AtomicString& id) +{ + SVGResource* resource = getResourceById(document, id); + if (resource && resource->isPaintServer()) + return static_cast<SVGPaintServer*>(resource); + + return 0; +} + +SVGPaintServerSolid* SVGPaintServer::sharedSolidPaintServer() +{ + static SVGPaintServerSolid* _sharedSolidPaintServer = SVGPaintServerSolid::create().releaseRef(); + + return _sharedSolidPaintServer; +} + +SVGPaintServer* SVGPaintServer::fillPaintServer(const RenderStyle* style, const RenderObject* item) +{ + if (!style->svgStyle()->hasFill()) + return 0; + + SVGPaint* fill = style->svgStyle()->fillPaint(); + + SVGPaintServer* fillPaintServer = 0; + SVGPaint::SVGPaintType paintType = fill->paintType(); + if (paintType == SVGPaint::SVG_PAINTTYPE_URI || + paintType == SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR) { + AtomicString id(SVGURIReference::getTarget(fill->uri())); + fillPaintServer = getPaintServerById(item->document(), id); + + SVGElement* svgElement = static_cast<SVGElement*>(item->element()); + ASSERT(svgElement && svgElement->document() && svgElement->isStyled()); + + if (item->isRenderPath() && fillPaintServer) + fillPaintServer->addClient(static_cast<SVGStyledElement*>(svgElement)); + else if (!fillPaintServer && paintType == SVGPaint::SVG_PAINTTYPE_URI) + svgElement->document()->accessSVGExtensions()->addPendingResource(id, static_cast<SVGStyledElement*>(svgElement)); + } + if (paintType != SVGPaint::SVG_PAINTTYPE_URI && !fillPaintServer) { + fillPaintServer = sharedSolidPaintServer(); + SVGPaintServerSolid* fillPaintServerSolid = static_cast<SVGPaintServerSolid*>(fillPaintServer); + if (paintType == SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR) + fillPaintServerSolid->setColor(style->color()); + else + fillPaintServerSolid->setColor(fill->color()); + // FIXME: Ideally invalid colors would never get set on the RenderStyle and this could turn into an ASSERT + if (!fillPaintServerSolid->color().isValid()) + fillPaintServer = 0; + } + if (!fillPaintServer) { + // default value (black), see bug 11017 + fillPaintServer = sharedSolidPaintServer(); + static_cast<SVGPaintServerSolid*>(fillPaintServer)->setColor(Color::black); + } + return fillPaintServer; +} + +SVGPaintServer* SVGPaintServer::strokePaintServer(const RenderStyle* style, const RenderObject* item) +{ + if (!style->svgStyle()->hasStroke()) + return 0; + + SVGPaint* stroke = style->svgStyle()->strokePaint(); + + SVGPaintServer* strokePaintServer = 0; + SVGPaint::SVGPaintType paintType = stroke->paintType(); + if (paintType == SVGPaint::SVG_PAINTTYPE_URI || + paintType == SVGPaint::SVG_PAINTTYPE_URI_RGBCOLOR) { + AtomicString id(SVGURIReference::getTarget(stroke->uri())); + strokePaintServer = getPaintServerById(item->document(), id); + + SVGElement* svgElement = static_cast<SVGElement*>(item->element()); + ASSERT(svgElement && svgElement->document() && svgElement->isStyled()); + + if (item->isRenderPath() && strokePaintServer) + strokePaintServer->addClient(static_cast<SVGStyledElement*>(svgElement)); + else if (!strokePaintServer && paintType == SVGPaint::SVG_PAINTTYPE_URI) + svgElement->document()->accessSVGExtensions()->addPendingResource(id, static_cast<SVGStyledElement*>(svgElement)); + } + if (paintType != SVGPaint::SVG_PAINTTYPE_URI && !strokePaintServer) { + strokePaintServer = sharedSolidPaintServer(); + SVGPaintServerSolid* strokePaintServerSolid = static_cast<SVGPaintServerSolid*>(strokePaintServer); + if (paintType == SVGPaint::SVG_PAINTTYPE_CURRENTCOLOR) + strokePaintServerSolid->setColor(style->color()); + else + strokePaintServerSolid->setColor(stroke->color()); + // FIXME: Ideally invalid colors would never get set on the RenderStyle and this could turn into an ASSERT + if (!strokePaintServerSolid->color().isValid()) + strokePaintServer = 0; + } + + return strokePaintServer; +} + +DashArray dashArrayFromRenderingStyle(const RenderStyle* style) +{ + DashArray array; + + CSSValueList* dashes = style->svgStyle()->strokeDashArray(); + if (dashes) { + CSSPrimitiveValue* dash = 0; + unsigned long len = dashes->length(); + for (unsigned long i = 0; i < len; i++) { + dash = static_cast<CSSPrimitiveValue*>(dashes->item(i)); + if (!dash) + continue; + + array.append((float) dash->computeLengthFloat(const_cast<RenderStyle*>(style))); + } + } + + return array; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/SVGPaintServer.h b/WebCore/svg/graphics/SVGPaintServer.h new file mode 100644 index 0000000..2df381e --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServer.h @@ -0,0 +1,112 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 SVGPaintServer_h +#define SVGPaintServer_h + +#if ENABLE(SVG) + +#include "SVGResource.h" + +#if PLATFORM(CG) +#include <ApplicationServices/ApplicationServices.h> +#endif + +#if PLATFORM(QT) +class QPen; +#endif + +#if PLATFORM(CG) + typedef Vector<CGFloat> DashArray; +#else + typedef Vector<float> DashArray; +#endif + +namespace WebCore { + + enum SVGPaintServerType { + // Painting mode + SolidPaintServer = 0, + PatternPaintServer = 1, + LinearGradientPaintServer = 2, + RadialGradientPaintServer = 3 + }; + + enum SVGPaintTargetType { + // Target mode + ApplyToFillTargetType = 1, + ApplyToStrokeTargetType = 2 + }; + + class GraphicsContext; + class RenderObject; + class RenderStyle; + class SVGPaintServerSolid; + + class SVGPaintServer : public SVGResource { + public: + virtual ~SVGPaintServer(); + + virtual SVGResourceType resourceType() const { return PaintServerResourceType; } + + virtual SVGPaintServerType type() const = 0; + virtual TextStream& externalRepresentation(TextStream&) const = 0; + + // To be implemented in platform specific code. + virtual void draw(GraphicsContext*&, const RenderObject*, SVGPaintTargetType) const; + virtual void teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText = false) const; + virtual void renderPath(GraphicsContext*&, const RenderObject*, SVGPaintTargetType) const; + + virtual bool setup(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText = false) const = 0; + + static SVGPaintServer* strokePaintServer(const RenderStyle*, const RenderObject*); + static SVGPaintServer* fillPaintServer(const RenderStyle*, const RenderObject*); + static SVGPaintServerSolid* sharedSolidPaintServer(); + + protected: +#if PLATFORM(CG) + void strokePath(CGContextRef, const RenderObject*) const; + void clipToStrokePath(CGContextRef, const RenderObject*) const; + void fillPath(CGContextRef, const RenderObject*) const; + void clipToFillPath(CGContextRef, const RenderObject*) const; +#endif + +#if PLATFORM(QT) + void setPenProperties(const RenderObject*, const RenderStyle*, QPen&) const; +#endif + protected: + SVGPaintServer(); + }; + + TextStream& operator<<(TextStream&, const SVGPaintServer&); + + SVGPaintServer* getPaintServerById(Document*, const AtomicString&); + + DashArray dashArrayFromRenderingStyle(const RenderStyle* style); +} // namespace WebCore + +#endif + +#endif // SVGPaintServer_h diff --git a/WebCore/svg/graphics/SVGPaintServerGradient.cpp b/WebCore/svg/graphics/SVGPaintServerGradient.cpp new file mode 100644 index 0000000..6a701b8 --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServerGradient.cpp @@ -0,0 +1,143 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "SVGPaintServerGradient.h" + +#include "SVGGradientElement.h" +#include "SVGRenderTreeAsText.h" + +namespace WebCore { + +TextStream& operator<<(TextStream& ts, SVGGradientSpreadMethod m) +{ + switch (m) { + case SPREADMETHOD_PAD: + ts << "PAD"; break; + case SPREADMETHOD_REPEAT: + ts << "REPEAT"; break; + case SPREADMETHOD_REFLECT: + ts << "REFLECT"; break; + } + + return ts; +} + +TextStream& operator<<(TextStream& ts, const Vector<SVGGradientStop>& l) +{ + ts << "["; + for (Vector<SVGGradientStop>::const_iterator it = l.begin(); it != l.end(); ++it) { + ts << "(" << it->first << "," << it->second << ")"; + if (it + 1 != l.end()) + ts << ", "; + } + ts << "]"; + return ts; +} + +SVGPaintServerGradient::SVGPaintServerGradient(const SVGGradientElement* owner) + : m_spreadMethod(SPREADMETHOD_PAD) + , m_boundingBoxMode(true) + , m_ownerElement(owner) + +#if PLATFORM(CG) + , m_stopsCache(0) + , m_shadingCache(0) + , m_savedContext(0) + , m_imageBuffer(0) +#endif +{ + ASSERT(owner); +} + +SVGPaintServerGradient::~SVGPaintServerGradient() +{ +#if PLATFORM(CG) + CGShadingRelease(m_shadingCache); +#endif +} + +const Vector<SVGGradientStop>& SVGPaintServerGradient::gradientStops() const +{ + return m_stops; +} + +void SVGPaintServerGradient::setGradientStops(const Vector<SVGGradientStop>& stops) +{ + m_stops = stops; +} + +SVGGradientSpreadMethod SVGPaintServerGradient::spreadMethod() const +{ + return m_spreadMethod; +} + +void SVGPaintServerGradient::setGradientSpreadMethod(const SVGGradientSpreadMethod& method) +{ + m_spreadMethod = method; +} + +bool SVGPaintServerGradient::boundingBoxMode() const +{ + return m_boundingBoxMode; +} + +void SVGPaintServerGradient::setBoundingBoxMode(bool mode) +{ + m_boundingBoxMode = mode; +} + +AffineTransform SVGPaintServerGradient::gradientTransform() const +{ + return m_gradientTransform; +} + +void SVGPaintServerGradient::setGradientTransform(const AffineTransform& transform) +{ + m_gradientTransform = transform; +} + +TextStream& SVGPaintServerGradient::externalRepresentation(TextStream& ts) const +{ + // Gradients/patterns aren't setup, until they are used for painting. Work around that fact. + m_ownerElement->buildGradient(); + + // abstract, don't stream type + ts << "[stops=" << gradientStops() << "]"; + if (spreadMethod() != SPREADMETHOD_PAD) + ts << "[method=" << spreadMethod() << "]"; + if (!boundingBoxMode()) + ts << " [bounding box mode=" << boundingBoxMode() << "]"; + if (!gradientTransform().isIdentity()) + ts << " [transform=" << gradientTransform() << "]"; + + return ts; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/SVGPaintServerGradient.h b/WebCore/svg/graphics/SVGPaintServerGradient.h new file mode 100644 index 0000000..a4af37b --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServerGradient.h @@ -0,0 +1,146 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 SVGPaintServerGradient_h +#define SVGPaintServerGradient_h + +#if ENABLE(SVG) + +#include "AffineTransform.h" +#include "Color.h" +#include "SVGPaintServer.h" + +#include <wtf/RefCounted.h> +#include <wtf/RefPtr.h> + +#if PLATFORM(QT) +class QGradient; +#endif + +namespace WebCore { + + class ImageBuffer; + class SVGGradientElement; + + // FIXME: Remove the spread method enum in SVGGradientElement + enum SVGGradientSpreadMethod { + SPREADMETHOD_PAD = 1, + SPREADMETHOD_REFLECT = 2, + SPREADMETHOD_REPEAT = 3 + }; + +#if PLATFORM(CG) + typedef std::pair<CGFloat, Color> SVGGradientStop; +#else + typedef std::pair<float, Color> SVGGradientStop; +#endif + + + class SVGPaintServerGradient : public SVGPaintServer { + public: + virtual ~SVGPaintServerGradient(); + + const Vector<SVGGradientStop>& gradientStops() const; + void setGradientStops(const Vector<SVGGradientStop>&); + + SVGGradientSpreadMethod spreadMethod() const; + void setGradientSpreadMethod(const SVGGradientSpreadMethod&); + + // Gradient start and end points are percentages when used in boundingBox mode. + // For instance start point with value (0,0) is top-left and end point with + // value (100, 100) is bottom-right. BoundingBox mode is enabled by default. + bool boundingBoxMode() const; + void setBoundingBoxMode(bool mode = true); + + AffineTransform gradientTransform() const; + void setGradientTransform(const AffineTransform&); + + virtual TextStream& externalRepresentation(TextStream&) const; + + virtual bool setup(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const; +#if PLATFORM(CG) + virtual void teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const; + virtual void renderPath(GraphicsContext*&, const RenderObject*, SVGPaintTargetType) const; + + virtual void invalidate(); + + // Helpers + void updateQuartzGradientStopsCache(const Vector<SVGGradientStop>&); + void updateQuartzGradientCache(const SVGPaintServerGradient*); + void handleBoundingBoxModeAndGradientTransformation(GraphicsContext*, const FloatRect& targetRect) const; +#endif + +#if PLATFORM(QT) + protected: + void fillColorArray(QGradient&, const Vector<SVGGradientStop>&, float opacity) const; + virtual QGradient setupGradient(GraphicsContext*&, const RenderObject*) const = 0; +#endif + + protected: + SVGPaintServerGradient(const SVGGradientElement* owner); + + private: + Vector<SVGGradientStop> m_stops; + SVGGradientSpreadMethod m_spreadMethod; + bool m_boundingBoxMode; + AffineTransform m_gradientTransform; + const SVGGradientElement* m_ownerElement; + +#if PLATFORM(CG) + public: + typedef struct { + CGFloat colorArray[4]; + CGFloat offset; + CGFloat previousDeltaInverse; + } QuartzGradientStop; + + struct SharedStopCache : public RefCounted<SharedStopCache> { + public: + static PassRefPtr<SharedStopCache> create() { return adoptRef(new SharedStopCache); } + + Vector<QuartzGradientStop> m_stops; + + private: + SharedStopCache() { } + }; + + RefPtr<SharedStopCache> m_stopsCache; + + CGShadingRef m_shadingCache; + mutable GraphicsContext* m_savedContext; + mutable ImageBuffer* m_imageBuffer; +#endif + }; + + inline SVGGradientStop makeGradientStop(float offset, const Color& color) + { + return std::make_pair(offset, color); + } + +} // namespace WebCore + +#endif + +#endif // SVGPaintServerGradient_h diff --git a/WebCore/svg/graphics/SVGPaintServerLinearGradient.cpp b/WebCore/svg/graphics/SVGPaintServerLinearGradient.cpp new file mode 100644 index 0000000..08db2d2 --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServerLinearGradient.cpp @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "SVGPaintServerLinearGradient.h" +#include "SVGRenderTreeAsText.h" + +namespace WebCore { + +SVGPaintServerLinearGradient::SVGPaintServerLinearGradient(const SVGGradientElement* owner) + : SVGPaintServerGradient(owner) +{ +} + +SVGPaintServerLinearGradient::~SVGPaintServerLinearGradient() +{ +} + +FloatPoint SVGPaintServerLinearGradient::gradientStart() const +{ + return m_start; +} + +void SVGPaintServerLinearGradient::setGradientStart(const FloatPoint& start) +{ + m_start = start; +} + +FloatPoint SVGPaintServerLinearGradient::gradientEnd() const +{ + return m_end; +} + +void SVGPaintServerLinearGradient::setGradientEnd(const FloatPoint& end) +{ + m_end = end; +} + +TextStream& SVGPaintServerLinearGradient::externalRepresentation(TextStream& ts) const +{ + ts << "[type=LINEAR-GRADIENT] "; + SVGPaintServerGradient::externalRepresentation(ts); + ts << " [start=" << gradientStart() << "]" + << " [end=" << gradientEnd() << "]"; + return ts; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/SVGPaintServerLinearGradient.h b/WebCore/svg/graphics/SVGPaintServerLinearGradient.h new file mode 100644 index 0000000..4b7da32 --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServerLinearGradient.h @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 SVGPaintServerLinearGradient_h +#define SVGPaintServerLinearGradient_h + +#if ENABLE(SVG) + +#include "FloatPoint.h" +#include "SVGPaintServerGradient.h" + +namespace WebCore { + + class SVGPaintServerLinearGradient : public SVGPaintServerGradient { + public: + static PassRefPtr<SVGPaintServerLinearGradient> create(const SVGGradientElement* owner) { return adoptRef(new SVGPaintServerLinearGradient(owner)); } + virtual ~SVGPaintServerLinearGradient(); + + virtual SVGPaintServerType type() const { return LinearGradientPaintServer; } + + FloatPoint gradientStart() const; + void setGradientStart(const FloatPoint&); + + FloatPoint gradientEnd() const; + void setGradientEnd(const FloatPoint&); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(QT) + virtual QGradient setupGradient(GraphicsContext*&, const RenderObject*) const; +#endif + + private: + SVGPaintServerLinearGradient(const SVGGradientElement* owner); + + FloatPoint m_start; + FloatPoint m_end; + }; + +} // namespace WebCore + +#endif + +#endif // SVGPaintServerLinearGradient_h diff --git a/WebCore/svg/graphics/SVGPaintServerPattern.cpp b/WebCore/svg/graphics/SVGPaintServerPattern.cpp new file mode 100644 index 0000000..c0e5b07 --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServerPattern.cpp @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "SVGPaintServerPattern.h" + +#include "ImageBuffer.h" +#include "SVGPatternElement.h" +#include "SVGRenderTreeAsText.h" + +using namespace std; + +namespace WebCore { + +SVGPaintServerPattern::SVGPaintServerPattern(const SVGPatternElement* owner) + : m_ownerElement(owner) +#if PLATFORM(CG) + , m_patternSpace(0) + , m_pattern(0) +#endif +{ + ASSERT(owner); +} + +SVGPaintServerPattern::~SVGPaintServerPattern() +{ +#if PLATFORM(CG) + CGPatternRelease(m_pattern); + CGColorSpaceRelease(m_patternSpace); +#endif +} + +FloatRect SVGPaintServerPattern::patternBoundaries() const +{ + return m_patternBoundaries; +} + +void SVGPaintServerPattern::setPatternBoundaries(const FloatRect& rect) +{ + m_patternBoundaries = rect; +} + +ImageBuffer* SVGPaintServerPattern::tile() const +{ + return m_tile.get(); +} + +void SVGPaintServerPattern::setTile(auto_ptr<ImageBuffer> tile) +{ + m_tile.set(tile.release()); +} + +AffineTransform SVGPaintServerPattern::patternTransform() const +{ + return m_patternTransform; +} + +void SVGPaintServerPattern::setPatternTransform(const AffineTransform& transform) +{ + m_patternTransform = transform; +} + +TextStream& SVGPaintServerPattern::externalRepresentation(TextStream& ts) const +{ + // Gradients/patterns aren't setup, until they are used for painting. Work around that fact. + m_ownerElement->buildPattern(FloatRect(0.0f, 0.0f, 1.0f, 1.0f)); + + ts << "[type=PATTERN]" + << " [bbox=" << patternBoundaries() << "]"; + if (!patternTransform().isIdentity()) + ts << " [pattern transform=" << patternTransform() << "]"; + return ts; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/SVGPaintServerPattern.h b/WebCore/svg/graphics/SVGPaintServerPattern.h new file mode 100644 index 0000000..8f88326 --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServerPattern.h @@ -0,0 +1,92 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 SVGPaintServerPattern_h +#define SVGPaintServerPattern_h + +#if ENABLE(SVG) + +#include "AffineTransform.h" +#include "FloatRect.h" +#include "SVGPaintServer.h" + +#include <memory> + +#include <wtf/OwnPtr.h> + +namespace WebCore { + + class GraphicsContext; + class ImageBuffer; + class SVGPatternElement; + + class SVGPaintServerPattern : public SVGPaintServer { + public: + static PassRefPtr<SVGPaintServerPattern> create(const SVGPatternElement* owner) { return adoptRef(new SVGPaintServerPattern(owner)); } + + virtual ~SVGPaintServerPattern(); + + virtual SVGPaintServerType type() const { return PatternPaintServer; } + + // Pattern boundaries + void setPatternBoundaries(const FloatRect&); + FloatRect patternBoundaries() const; + + ImageBuffer* tile() const; + void setTile(std::auto_ptr<ImageBuffer>); + + AffineTransform patternTransform() const; + void setPatternTransform(const AffineTransform&); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CG) + virtual bool setup(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const; + virtual void teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const; +#endif + +#if PLATFORM(QT) || PLATFORM(CAIRO) + virtual bool setup(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const; +#endif + + private: + SVGPaintServerPattern(const SVGPatternElement*); + + OwnPtr<ImageBuffer> m_tile; + const SVGPatternElement* m_ownerElement; + AffineTransform m_patternTransform; + FloatRect m_patternBoundaries; + +#if PLATFORM(CG) + mutable CGColorSpaceRef m_patternSpace; + mutable CGPatternRef m_pattern; +#endif + }; + +} // namespace WebCore + +#endif + +#endif // SVGPaintServerPattern_h diff --git a/WebCore/svg/graphics/SVGPaintServerRadialGradient.cpp b/WebCore/svg/graphics/SVGPaintServerRadialGradient.cpp new file mode 100644 index 0000000..a795ab5 --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServerRadialGradient.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "SVGPaintServerRadialGradient.h" +#include "SVGRenderTreeAsText.h" + +namespace WebCore { + +SVGPaintServerRadialGradient::SVGPaintServerRadialGradient(const SVGGradientElement* owner) + : SVGPaintServerGradient(owner) + , m_radius(0.0f) +{ +} + +SVGPaintServerRadialGradient::~SVGPaintServerRadialGradient() +{ +} + + +FloatPoint SVGPaintServerRadialGradient::gradientCenter() const +{ + return m_center; +} + +void SVGPaintServerRadialGradient::setGradientCenter(const FloatPoint& center) +{ + m_center = center; +} + +FloatPoint SVGPaintServerRadialGradient::gradientFocal() const +{ + return m_focal; +} + +void SVGPaintServerRadialGradient::setGradientFocal(const FloatPoint& focal) +{ + m_focal = focal; +} + +float SVGPaintServerRadialGradient::gradientRadius() const +{ + return m_radius; +} + +void SVGPaintServerRadialGradient::setGradientRadius(float radius) +{ + m_radius = radius; +} + +TextStream& SVGPaintServerRadialGradient::externalRepresentation(TextStream& ts) const +{ + ts << "[type=RADIAL-GRADIENT] "; + SVGPaintServerGradient::externalRepresentation(ts); + ts << " [center=" << gradientCenter() << "]" + << " [focal=" << gradientFocal() << "]" + << " [radius=" << gradientRadius() << "]"; + return ts; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/SVGPaintServerRadialGradient.h b/WebCore/svg/graphics/SVGPaintServerRadialGradient.h new file mode 100644 index 0000000..265f76b --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServerRadialGradient.h @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 SVGPaintServerRadialGradient_h +#define SVGPaintServerRadialGradient_h + +#if ENABLE(SVG) + +#include "FloatPoint.h" +#include "SVGPaintServerGradient.h" + +namespace WebCore { + + class SVGPaintServerRadialGradient : public SVGPaintServerGradient { + public: + static PassRefPtr<SVGPaintServerRadialGradient> create(const SVGGradientElement* owner) { return adoptRef(new SVGPaintServerRadialGradient(owner)); } + virtual ~SVGPaintServerRadialGradient(); + + virtual SVGPaintServerType type() const { return RadialGradientPaintServer; } + + FloatPoint gradientCenter() const; + void setGradientCenter(const FloatPoint&); + + FloatPoint gradientFocal() const; + void setGradientFocal(const FloatPoint&); + + float gradientRadius() const; + void setGradientRadius(float); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(QT) + virtual QGradient setupGradient(GraphicsContext*&, const RenderObject*) const; +#endif + + private: + SVGPaintServerRadialGradient(const SVGGradientElement* owner); + + float m_radius; + FloatPoint m_center; + FloatPoint m_focal; + }; + +} // namespace WebCore + +#endif + +#endif // SVGPaintServerRadialGradient_h diff --git a/WebCore/svg/graphics/SVGPaintServerSolid.cpp b/WebCore/svg/graphics/SVGPaintServerSolid.cpp new file mode 100644 index 0000000..cb58a3a --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServerSolid.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "SVGPaintServerSolid.h" +#include "SVGRenderTreeAsText.h" + +namespace WebCore { + +SVGPaintServerSolid::SVGPaintServerSolid() +{ +} + +SVGPaintServerSolid::~SVGPaintServerSolid() +{ +} + +Color SVGPaintServerSolid::color() const +{ + return m_color; +} + +void SVGPaintServerSolid::setColor(const Color& color) +{ + m_color = color; +} + +TextStream& SVGPaintServerSolid::externalRepresentation(TextStream& ts) const +{ + ts << "[type=SOLID]" + << " [color="<< color() << "]"; + return ts; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/SVGPaintServerSolid.h b/WebCore/svg/graphics/SVGPaintServerSolid.h new file mode 100644 index 0000000..2dd54ab --- /dev/null +++ b/WebCore/svg/graphics/SVGPaintServerSolid.h @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 SVGPaintServerSolid_h +#define SVGPaintServerSolid_h + +#if ENABLE(SVG) + +#include "Color.h" +#include "SVGPaintServer.h" + +namespace WebCore { + + class SVGPaintServerSolid : public SVGPaintServer { + public: + static PassRefPtr<SVGPaintServerSolid> create() { return adoptRef(new SVGPaintServerSolid); } + virtual ~SVGPaintServerSolid(); + + virtual SVGPaintServerType type() const { return SolidPaintServer; } + + Color color() const; + void setColor(const Color&); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CG) || PLATFORM(QT) || PLATFORM(CAIRO) + virtual bool setup(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const; +#endif + + private: + SVGPaintServerSolid(); + + Color m_color; + }; + +} // namespace WebCore + +#endif + +#endif // SVGPaintServerSolid_h diff --git a/WebCore/svg/graphics/SVGResource.cpp b/WebCore/svg/graphics/SVGResource.cpp new file mode 100644 index 0000000..10d6648 --- /dev/null +++ b/WebCore/svg/graphics/SVGResource.cpp @@ -0,0 +1,182 @@ +/* + * Copyright (C) 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "SVGResource.h" + +#include "RenderPath.h" +#include "SVGElement.h" +#include "SVGStyledElement.h" + +namespace WebCore { + +SVGResource::SVGResource() +{ +} + +struct ResourceSet { + ResourceSet() + { + for (int i = 0; i < _ResourceTypeCount; i++) + resources[i] = 0; + } + SVGResource* resources[_ResourceTypeCount]; +}; + +static HashMap<SVGStyledElement*, ResourceSet*>& clientMap() { + static HashMap<SVGStyledElement*, ResourceSet*> map; + return map; +} + +SVGResource::~SVGResource() +{ + int type = -1; + HashSet<SVGStyledElement*>::iterator itr = m_clients.begin(); + + for (; type < 0 && itr != m_clients.end(); ++itr) { + ResourceSet* target = clientMap().get(*itr); + if (!target) + continue; + + for (int i = 0; i < _ResourceTypeCount; i++) { + if (target->resources[i] != this) + continue; + type = i; + target->resources[i] = 0; + break; + } + } + + if (type < 0) + return; + + for (; itr != m_clients.end(); ++itr) { + ResourceSet* target = clientMap().get(*itr); + if (!target) + continue; + + if (target->resources[type] == this) + target->resources[type] = 0; + } +} + +void SVGResource::invalidate() +{ + HashSet<SVGStyledElement*>::const_iterator it = m_clients.begin(); + const HashSet<SVGStyledElement*>::const_iterator end = m_clients.end(); + + for (; it != end; ++it) { + SVGStyledElement* cur = *it; + + if (cur->renderer()) + cur->renderer()->setNeedsLayout(true); + + cur->invalidateResourcesInAncestorChain(); + } +} + +void SVGResource::invalidateClients(HashSet<SVGStyledElement*> clients) +{ + HashSet<SVGStyledElement*>::const_iterator it = clients.begin(); + const HashSet<SVGStyledElement*>::const_iterator end = clients.end(); + + for (; it != end; ++it) { + SVGStyledElement* cur = *it; + + if (cur->renderer()) + cur->renderer()->setNeedsLayout(true); + + cur->invalidateResourcesInAncestorChain(); + } +} + +void SVGResource::removeClient(SVGStyledElement* item) +{ + HashMap<SVGStyledElement*, ResourceSet*>::iterator resourcePtr = clientMap().find(item); + if (resourcePtr == clientMap().end()) + return; + + ResourceSet* set = resourcePtr->second; + ASSERT(set); + + clientMap().remove(resourcePtr); + + for (int i = 0; i < _ResourceTypeCount; i++) + if (set->resources[i]) + set->resources[i]->m_clients.remove(item); + + delete set; +} + +void SVGResource::addClient(SVGStyledElement* item) +{ + if (m_clients.contains(item)) + return; + + m_clients.add(item); + + ResourceSet* target = clientMap().get(item); + if (!target) + target = new ResourceSet; + + SVGResourceType type = resourceType(); + if (SVGResource* oldResource = target->resources[type]) + oldResource->m_clients.remove(item); + + target->resources[type] = this; + clientMap().set(item, target); +} + +TextStream& SVGResource::externalRepresentation(TextStream& ts) const +{ + return ts; +} + +SVGResource* getResourceById(Document* document, const AtomicString& id) +{ + if (id.isEmpty()) + return 0; + + Element* element = document->getElementById(id); + SVGElement* svgElement = 0; + if (element && element->isSVGElement()) + svgElement = static_cast<SVGElement*>(element); + + if (svgElement && svgElement->isStyled()) + return static_cast<SVGStyledElement*>(svgElement)->canvasResource(); + + return 0; +} + +TextStream& operator<<(TextStream& ts, const SVGResource& r) +{ + return r.externalRepresentation(ts); +} + +} + +#endif diff --git a/WebCore/svg/graphics/SVGResource.h b/WebCore/svg/graphics/SVGResource.h new file mode 100644 index 0000000..7ee98f6 --- /dev/null +++ b/WebCore/svg/graphics/SVGResource.h @@ -0,0 +1,101 @@ +/* + * Copyright (C) 2006, 2008 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 SVGResource_h +#define SVGResource_h + +#if ENABLE(SVG) +#include "PlatformString.h" +#include "StringHash.h" + +#include <wtf/HashMap.h> +#include <wtf/HashSet.h> +#include <wtf/RefCounted.h> + +namespace WebCore { + + class AtomicString; + class Document; + class SVGStyledElement; + class TextStream; + + enum SVGResourceType { + // Painting mode + ClipperResourceType = 0, + MarkerResourceType, + ImageResourceType, + FilterResourceType, + MaskerResourceType, + PaintServerResourceType, + + // For resource tracking we need to know how many types of resource there are + _ResourceTypeCount + }; + + // The SVGResource file represent various graphics resources: + // - Filter resource + // - Clipper resource + // - Masker resource + // - Marker resource + // - Pattern resource + // - Linear/Radial gradient resource + // + // SVG creates/uses these resources. + + class SVGResource : public RefCounted<SVGResource> { + public: + virtual ~SVGResource(); + + virtual void invalidate(); + + void addClient(SVGStyledElement*); + virtual SVGResourceType resourceType() const = 0; + + bool isPaintServer() const { return resourceType() == PaintServerResourceType; } + bool isFilter() const { return resourceType() == FilterResourceType; } + bool isClipper() const { return resourceType() == ClipperResourceType; } + bool isMarker() const { return resourceType() == MarkerResourceType; } + bool isMasker() const { return resourceType() == MaskerResourceType; } + + virtual TextStream& externalRepresentation(TextStream&) const; + + static void invalidateClients(HashSet<SVGStyledElement*>); + static void removeClient(SVGStyledElement*); + + protected: + SVGResource(); + + private: + HashSet<SVGStyledElement*> m_clients; + }; + + SVGResource* getResourceById(Document*, const AtomicString&); + + TextStream& operator<<(TextStream&, const SVGResource&); + +} // namespace WebCore + +#endif +#endif // SVGResource_h diff --git a/WebCore/svg/graphics/SVGResourceClipper.cpp b/WebCore/svg/graphics/SVGResourceClipper.cpp new file mode 100644 index 0000000..f03f5c2 --- /dev/null +++ b/WebCore/svg/graphics/SVGResourceClipper.cpp @@ -0,0 +1,100 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "SVGResourceClipper.h" + +#include "SVGRenderTreeAsText.h" + +namespace WebCore { + +SVGResourceClipper::SVGResourceClipper() + : SVGResource() +{ +} + +SVGResourceClipper::~SVGResourceClipper() +{ +} + +void SVGResourceClipper::resetClipData() +{ + m_clipData.clear(); +} + +void SVGResourceClipper::addClipData(const Path& path, WindRule rule, bool bboxUnits) +{ + m_clipData.addPath(path, rule, bboxUnits); +} + +const ClipDataList& SVGResourceClipper::clipData() const +{ + return m_clipData; +} + +TextStream& SVGResourceClipper::externalRepresentation(TextStream& ts) const +{ + ts << "[type=CLIPPER]"; + ts << " [clip data=" << clipData().clipData() << "]"; + return ts; +} + +TextStream& operator<<(TextStream& ts, WindRule rule) +{ + switch (rule) { + case RULE_NONZERO: + ts << "NON-ZERO"; break; + case RULE_EVENODD: + ts << "EVEN-ODD"; break; + } + + return ts; +} + +TextStream& operator<<(TextStream& ts, const ClipData& d) +{ + ts << "[winding=" << d.windRule << "]"; + + if (d.bboxUnits) + ts << " [bounding box mode=" << d.bboxUnits << "]"; + + ts << " [path=" << d.path.debugString() << "]"; + return ts; +} + +SVGResourceClipper* getClipperById(Document* document, const AtomicString& id) +{ + SVGResource* resource = getResourceById(document, id); + if (resource && resource->isClipper()) + return static_cast<SVGResourceClipper*>(resource); + + return 0; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/SVGResourceClipper.h b/WebCore/svg/graphics/SVGResourceClipper.h new file mode 100644 index 0000000..98c295f --- /dev/null +++ b/WebCore/svg/graphics/SVGResourceClipper.h @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 SVGResourceClipper_h +#define SVGResourceClipper_h + +#if ENABLE(SVG) + +#include "SVGResource.h" +#include "Path.h" + +namespace WebCore { + + struct ClipData { + Path path; + WindRule windRule; + bool bboxUnits : 1; + }; + + class ClipDataList { + public: + void addPath(const Path& pathData, WindRule windRule, bool bboxUnits) + { + ClipData clipData; + + clipData.path = pathData; + clipData.windRule = windRule; + clipData.bboxUnits = bboxUnits; + + m_clipData.append(clipData); + } + + void clear() { m_clipData.clear(); } + const Vector<ClipData>& clipData() const { return m_clipData; } + bool isEmpty() const { return m_clipData.isEmpty(); } + private: + Vector<ClipData> m_clipData; + }; + + class GraphicsContext; + + class SVGResourceClipper : public SVGResource { + public: + static PassRefPtr<SVGResourceClipper> create() { return adoptRef(new SVGResourceClipper); } + virtual ~SVGResourceClipper(); + + void resetClipData(); + void addClipData(const Path&, WindRule, bool bboxUnits); + + const ClipDataList& clipData() const; + + virtual SVGResourceType resourceType() const { return ClipperResourceType; } + virtual TextStream& externalRepresentation(TextStream&) const; + + // To be implemented by the specific rendering devices + void applyClip(GraphicsContext*, const FloatRect& boundingBox) const; + private: + SVGResourceClipper(); + ClipDataList m_clipData; + }; + + TextStream& operator<<(TextStream&, WindRule); + TextStream& operator<<(TextStream&, const ClipData&); + + SVGResourceClipper* getClipperById(Document*, const AtomicString&); + +} // namespace WebCore + +#endif + +#endif // SVGResourceClipper_h diff --git a/WebCore/svg/graphics/SVGResourceFilter.cpp b/WebCore/svg/graphics/SVGResourceFilter.cpp new file mode 100644 index 0000000..8fb2dfa --- /dev/null +++ b/WebCore/svg/graphics/SVGResourceFilter.cpp @@ -0,0 +1,123 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGResourceFilter.h" + +#include "SVGRenderTreeAsText.h" +#include "SVGFilterEffect.h" + +namespace WebCore { + +SVGResourceFilter::SVGResourceFilter() + : m_platformData(createPlatformData()) + , m_filterBBoxMode(false) + , m_effectBBoxMode(false) + , m_xBBoxMode(false) + , m_yBBoxMode(false) +{ +} + +void SVGResourceFilter::clearEffects() +{ + m_effects.clear(); +} + +void SVGResourceFilter::addFilterEffect(SVGFilterEffect* effect) +{ + ASSERT(effect); + + if (effect) { + ASSERT(effect->filter() == this); + m_effects.append(effect); + } +} + +FloatRect SVGResourceFilter::filterBBoxForItemBBox(const FloatRect& itemBBox) const +{ + FloatRect filterBBox = filterRect(); + + float xOffset = 0.0f; + float yOffset = 0.0f; + + if (!effectBoundingBoxMode()) { + xOffset = itemBBox.x(); + yOffset = itemBBox.y(); + } + + if (filterBoundingBoxMode()) { + filterBBox = FloatRect(xOffset + filterBBox.x() * itemBBox.width(), + yOffset + filterBBox.y() * itemBBox.height(), + filterBBox.width() * itemBBox.width(), + filterBBox.height() * itemBBox.height()); + } else { + if (xBoundingBoxMode()) + filterBBox.setX(xOffset + filterBBox.x()); + + if (yBoundingBoxMode()) + filterBBox.setY(yOffset + filterBBox.y()); + } + + return filterBBox; +} + +TextStream& SVGResourceFilter::externalRepresentation(TextStream& ts) const +{ + ts << "[type=FILTER] "; + + FloatRect bbox = filterRect(); + static FloatRect defaultFilterRect(0, 0, 1, 1); + + if (!filterBoundingBoxMode() || bbox != defaultFilterRect) { + ts << " [bounding box="; + if (filterBoundingBoxMode()) { + bbox.scale(100.f); + ts << "at (" << bbox.x() << "%," << bbox.y() << "%) size " << bbox.width() << "%x" << bbox.height() << "%"; + } else + ts << filterRect(); + ts << "]"; + } + + if (!filterBoundingBoxMode()) // default is true + ts << " [bounding box mode=" << filterBoundingBoxMode() << "]"; + if (effectBoundingBoxMode()) // default is false + ts << " [effect bounding box mode=" << effectBoundingBoxMode() << "]"; + if (m_effects.size() > 0) + ts << " [effects=" << m_effects << "]"; + + return ts; +} + +SVGResourceFilter* getFilterById(Document* document, const AtomicString& id) +{ + SVGResource* resource = getResourceById(document, id); + if (resource && resource->isFilter()) + return static_cast<SVGResourceFilter*>(resource); + + return 0; +} + + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/WebCore/svg/graphics/SVGResourceFilter.h b/WebCore/svg/graphics/SVGResourceFilter.h new file mode 100644 index 0000000..646c732 --- /dev/null +++ b/WebCore/svg/graphics/SVGResourceFilter.h @@ -0,0 +1,99 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGResourceFilter_h +#define SVGResourceFilter_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGResource.h" +#include "SVGFilterEffect.h" + +#include "FloatRect.h" + +#include <wtf/OwnPtr.h> + +namespace WebCore { + +class GraphicsContext; +class SVGFilterEffect; + +class SVGResourceFilterPlatformData { +public: + virtual ~SVGResourceFilterPlatformData() {} +}; + +class SVGResourceFilter : public SVGResource { +public: + SVGResourceFilter(); + + virtual SVGResourceType resourceType() const { return FilterResourceType; } + + bool filterBoundingBoxMode() const { return m_filterBBoxMode; } + void setFilterBoundingBoxMode(bool bboxMode) { m_filterBBoxMode = bboxMode; } + + bool effectBoundingBoxMode() const { return m_effectBBoxMode; } + void setEffectBoundingBoxMode(bool bboxMode) { m_effectBBoxMode = bboxMode; } + + bool xBoundingBoxMode() const { return m_xBBoxMode; } + void setXBoundingBoxMode(bool bboxMode) { m_xBBoxMode = bboxMode; } + + bool yBoundingBoxMode() const { return m_yBBoxMode; } + void setYBoundingBoxMode(bool bboxMode) { m_yBBoxMode = bboxMode; } + + FloatRect filterRect() const { return m_filterRect; } + void setFilterRect(const FloatRect& rect) { m_filterRect = rect; } + + FloatRect filterBBoxForItemBBox(const FloatRect& itemBBox) const; + + void clearEffects(); + void addFilterEffect(SVGFilterEffect*); + + virtual TextStream& externalRepresentation(TextStream&) const; + + // To be implemented in platform specific code. + void prepareFilter(GraphicsContext*&, const FloatRect& bbox); + void applyFilter(GraphicsContext*&, const FloatRect& bbox); + + SVGResourceFilterPlatformData* platformData() { return m_platformData.get(); } + const Vector<SVGFilterEffect*>& effects() { return m_effects; } + +private: + SVGResourceFilterPlatformData* createPlatformData(); + + OwnPtr<SVGResourceFilterPlatformData> m_platformData; + + bool m_filterBBoxMode : 1; + bool m_effectBBoxMode : 1; + + bool m_xBBoxMode : 1; + bool m_yBBoxMode : 1; + + FloatRect m_filterRect; + Vector<SVGFilterEffect*> m_effects; +}; + +SVGResourceFilter* getFilterById(Document*, const AtomicString&); + +} // namespace WebCore + +#endif // ENABLE(SVG) + +#endif // SVGResourceFilter_h diff --git a/WebCore/svg/graphics/SVGResourceListener.h b/WebCore/svg/graphics/SVGResourceListener.h new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/WebCore/svg/graphics/SVGResourceListener.h diff --git a/WebCore/svg/graphics/SVGResourceMarker.cpp b/WebCore/svg/graphics/SVGResourceMarker.cpp new file mode 100644 index 0000000..3649321 --- /dev/null +++ b/WebCore/svg/graphics/SVGResourceMarker.cpp @@ -0,0 +1,139 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "SVGResourceMarker.h" + +#include "AffineTransform.h" +#include "GraphicsContext.h" +#include "RenderSVGViewportContainer.h" +#include "TextStream.h" + +namespace WebCore { + +SVGResourceMarker::SVGResourceMarker() + : SVGResource() + , m_refX(0.0) + , m_refY(0.0) + , m_angle(-1) // just like using setAutoAngle() + , m_marker(0) + , m_useStrokeWidth(true) +{ +} + +SVGResourceMarker::~SVGResourceMarker() +{ +} + +void SVGResourceMarker::setMarker(RenderSVGViewportContainer* marker) +{ + m_marker = marker; +} + +void SVGResourceMarker::setRef(double refX, double refY) +{ + m_refX = refX; + m_refY = refY; +} + +void SVGResourceMarker::draw(GraphicsContext* context, const FloatRect& rect, double x, double y, double strokeWidth, double angle) +{ + if (!m_marker) + return; + + static HashSet<SVGResourceMarker*> currentlyDrawingMarkers; + + // avoid drawing circular marker references + if (currentlyDrawingMarkers.contains(this)) + return; + + currentlyDrawingMarkers.add(this); + + AffineTransform transform; + transform.translate(x, y); + transform.rotate(m_angle > -1 ? m_angle : angle); + + // refX and refY are given in coordinates relative to the viewport established by the marker, yet they affect + // the translation performed on the viewport itself. + AffineTransform viewportTransform; + if (m_useStrokeWidth) + viewportTransform.scale(strokeWidth, strokeWidth); + viewportTransform *= m_marker->viewportTransform(); + double refX, refY; + viewportTransform.map(m_refX, m_refY, &refX, &refY); + transform.translate(-refX, -refY); + + if (m_useStrokeWidth) + transform.scale(strokeWidth, strokeWidth); + + // FIXME: PaintInfo should be passed into this method instead of being created here + // FIXME: bounding box fractions are lost + RenderObject::PaintInfo info(context, enclosingIntRect(rect), PaintPhaseForeground, 0, 0, 0); + + context->save(); + context->concatCTM(transform); + m_marker->setDrawsContents(true); + m_marker->paint(info, 0, 0); + m_marker->setDrawsContents(false); + context->restore(); + + m_cachedBounds = transform.mapRect(m_marker->absoluteClippedOverflowRect()); + + currentlyDrawingMarkers.remove(this); +} + +FloatRect SVGResourceMarker::cachedBounds() const +{ + return m_cachedBounds; +} + +TextStream& SVGResourceMarker::externalRepresentation(TextStream& ts) const +{ + ts << "[type=MARKER]" + << " [angle="; + + if (angle() == -1) + ts << "auto" << "]"; + else + ts << angle() << "]"; + + ts << " [ref x=" << refX() << " y=" << refY() << "]"; + return ts; +} + +SVGResourceMarker* getMarkerById(Document* document, const AtomicString& id) +{ + SVGResource* resource = getResourceById(document, id); + if (resource && resource->isMarker()) + return static_cast<SVGResourceMarker*>(resource); + + return 0; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/SVGResourceMarker.h b/WebCore/svg/graphics/SVGResourceMarker.h new file mode 100644 index 0000000..bb4039c --- /dev/null +++ b/WebCore/svg/graphics/SVGResourceMarker.h @@ -0,0 +1,78 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 SVGResourceMarker_h +#define SVGResourceMarker_h + +#if ENABLE(SVG) + +#include "FloatRect.h" +#include "SVGResource.h" + +namespace WebCore { + + class GraphicsContext; + class RenderSVGViewportContainer; + + class SVGResourceMarker : public SVGResource { + public: + static PassRefPtr<SVGResourceMarker> create() { return adoptRef(new SVGResourceMarker); } + virtual ~SVGResourceMarker(); + + void setMarker(RenderSVGViewportContainer*); + + void setRef(double refX, double refY); + double refX() const { return m_refX; } + double refY() const { return m_refY; } + + void setAngle(float angle) { m_angle = angle; } + void setAutoAngle() { m_angle = -1; } + float angle() const { return m_angle; } + + void setUseStrokeWidth(bool useStrokeWidth = true) { m_useStrokeWidth = useStrokeWidth; } + bool useStrokeWidth() const { return m_useStrokeWidth; } + + FloatRect cachedBounds() const; + void draw(GraphicsContext*, const FloatRect&, double x, double y, double strokeWidth = 1, double angle = 0); + + virtual SVGResourceType resourceType() const { return MarkerResourceType; } + virtual TextStream& externalRepresentation(TextStream&) const; + + private: + SVGResourceMarker(); + double m_refX, m_refY; + FloatRect m_cachedBounds; + float m_angle; + RenderSVGViewportContainer* m_marker; + bool m_useStrokeWidth; + }; + + SVGResourceMarker* getMarkerById(Document*, const AtomicString&); + +} // namespace WebCore + +#endif + +#endif // SVGResourceMarker_h diff --git a/WebCore/svg/graphics/SVGResourceMasker.cpp b/WebCore/svg/graphics/SVGResourceMasker.cpp new file mode 100644 index 0000000..842f04f --- /dev/null +++ b/WebCore/svg/graphics/SVGResourceMasker.cpp @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "SVGResourceMasker.h" + +#include "ImageBuffer.h" +#include "TextStream.h" + +using namespace std; + +namespace WebCore { + +SVGResourceMasker::SVGResourceMasker(const SVGMaskElement* ownerElement) + : SVGResource() + , m_ownerElement(ownerElement) +{ +} + +SVGResourceMasker::~SVGResourceMasker() +{ +} + +void SVGResourceMasker::invalidate() +{ + SVGResource::invalidate(); + m_mask.clear(); +} + +TextStream& SVGResourceMasker::externalRepresentation(TextStream& ts) const +{ + ts << "[type=MASKER]"; + return ts; +} + +SVGResourceMasker* getMaskerById(Document* document, const AtomicString& id) +{ + SVGResource* resource = getResourceById(document, id); + if (resource && resource->isMasker()) + return static_cast<SVGResourceMasker*>(resource); + + return 0; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/SVGResourceMasker.h b/WebCore/svg/graphics/SVGResourceMasker.h new file mode 100644 index 0000000..f945f56 --- /dev/null +++ b/WebCore/svg/graphics/SVGResourceMasker.h @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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 SVGResourceMasker_h +#define SVGResourceMasker_h + +#if ENABLE(SVG) + +#include "GraphicsContext.h" +#include "SVGResource.h" + +#include <memory> + +#include <wtf/OwnPtr.h> +#include <wtf/PassRefPtr.h> + +namespace WebCore { + + class FloatRect; + class ImageBuffer; + class SVGMaskElement; + + class SVGResourceMasker : public SVGResource { + public: + static PassRefPtr<SVGResourceMasker> create(const SVGMaskElement* ownerElement) { return adoptRef(new SVGResourceMasker(ownerElement)); } + virtual ~SVGResourceMasker(); + + virtual void invalidate(); + + virtual SVGResourceType resourceType() const { return MaskerResourceType; } + virtual TextStream& externalRepresentation(TextStream&) const; + + // To be implemented by the specific rendering devices + void applyMask(GraphicsContext*, const FloatRect& boundingBox); + + private: + SVGResourceMasker(const SVGMaskElement*); + + const SVGMaskElement* m_ownerElement; + + OwnPtr<ImageBuffer> m_mask; + FloatRect m_maskRect; + }; + + SVGResourceMasker* getMaskerById(Document*, const AtomicString&); + +} // namespace WebCore + +#endif + +#endif // SVGResourceMasker_h diff --git a/WebCore/svg/graphics/cairo/RenderPathCairo.cpp b/WebCore/svg/graphics/cairo/RenderPathCairo.cpp new file mode 100644 index 0000000..72379b5 --- /dev/null +++ b/WebCore/svg/graphics/cairo/RenderPathCairo.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" +#include "RenderPath.h" + +#include "CairoPath.h" +#include "SVGPaintServer.h" + +namespace WebCore { + +bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const +{ + if (requiresStroke && !SVGPaintServer::strokePaintServer(style(), this)) + return false; + + cairo_t* cr = path().platformPath()->m_cr; + + // TODO: set stroke properties + return cairo_in_stroke(cr, point.x(), point.y()); +} + +FloatRect RenderPath::strokeBBox() const +{ + // TODO: this implementation is naive + + cairo_t* cr = path().platformPath()->m_cr; + + double x0, x1, y0, y1; + cairo_stroke_extents(cr, &x0, &y0, &x1, &y1); + FloatRect bbox = FloatRect(x0, y0, x1 - x0, y1 - y0); + + return bbox; +} + +} diff --git a/WebCore/svg/graphics/cairo/SVGPaintServerCairo.cpp b/WebCore/svg/graphics/cairo/SVGPaintServerCairo.cpp new file mode 100644 index 0000000..37cab6f --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGPaintServerCairo.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServer.h" + +#include "GraphicsContext.h" +#include "SVGPaintServer.h" +#include "RenderPath.h" + +#include <cairo.h> + +namespace WebCore { + +void SVGPaintServer::draw(GraphicsContext*& context, const RenderObject* path, SVGPaintTargetType type) const +{ + if (!setup(context, path, type)) + return; + + renderPath(context, path, type); + teardown(context, path, type); +} + +void SVGPaintServer::teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const +{ + // no-op +} + +void SVGPaintServer::renderPath(GraphicsContext*& context, const RenderObject* path, SVGPaintTargetType type) const +{ + cairo_t* cr = context->platformContext(); + const SVGRenderStyle* style = path->style()->svgStyle(); + + cairo_set_fill_rule(cr, style->fillRule() == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING); + + if ((type & ApplyToFillTargetType) && style->hasFill()) + cairo_fill_preserve(cr); + + if ((type & ApplyToStrokeTargetType) && style->hasStroke()) + cairo_stroke_preserve(cr); + + cairo_new_path(cr); +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/cairo/SVGPaintServerGradientCairo.cpp b/WebCore/svg/graphics/cairo/SVGPaintServerGradientCairo.cpp new file mode 100644 index 0000000..7b22f4f --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGPaintServerGradientCairo.cpp @@ -0,0 +1,111 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServerGradient.h" +#include "SVGPaintServerLinearGradient.h" +#include "SVGPaintServerRadialGradient.h" + +#include "GraphicsContext.h" +#include "RenderObject.h" +#include "RenderPath.h" +#include "RenderStyle.h" +#include "SVGGradientElement.h" + +namespace WebCore { + +bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const +{ + m_ownerElement->buildGradient(); + + cairo_t* cr = context->platformContext(); + cairo_pattern_t* pattern; + + cairo_matrix_t matrix; + cairo_matrix_init_identity (&matrix); + const cairo_matrix_t gradient_matrix = gradientTransform(); + + // TODO: revise this code, it is known not to work in many cases + if (this->type() == LinearGradientPaintServer) { + const SVGPaintServerLinearGradient* linear = static_cast<const SVGPaintServerLinearGradient*>(this); + + if (boundingBoxMode()) { + // TODO: use RenderPathCairo's strokeBBox? + double x1, y1, x2, y2; + cairo_fill_extents(cr, &x1, &y1, &x2, &y2); + cairo_matrix_translate(&matrix, x1, y1); + cairo_matrix_scale(&matrix, x2 - x1, y2 - y1); + cairo_matrix_multiply(&matrix, &matrix, &gradient_matrix); + cairo_matrix_invert(&matrix); + } + + double x0, x1, y0, y1; + x0 = linear->gradientStart().x(); + y0 = linear->gradientStart().y(); + x1 = linear->gradientEnd().x(); + y1 = linear->gradientEnd().y(); + pattern = cairo_pattern_create_linear(x0, y0, x1, y1); + + } else if (this->type() == RadialGradientPaintServer) { + // const SVGPaintServerRadialGradient* radial = static_cast<const SVGPaintServerRadialGradient*>(this); + // TODO: pattern = cairo_pattern_create_radial(); + return false; + } else { + return false; + } + + cairo_pattern_set_filter(pattern, CAIRO_FILTER_BILINEAR); + + switch (spreadMethod()) { + case SPREADMETHOD_PAD: + cairo_pattern_set_extend(pattern, CAIRO_EXTEND_PAD); + break; + case SPREADMETHOD_REFLECT: + cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REFLECT); + break; + case SPREADMETHOD_REPEAT: + cairo_pattern_set_extend(pattern, CAIRO_EXTEND_REPEAT); + break; + default: + cairo_pattern_set_extend(pattern, CAIRO_EXTEND_NONE); + break; + } + + cairo_pattern_set_matrix(pattern, &matrix); + + const Vector<SVGGradientStop>& stops = gradientStops(); + + for (unsigned i = 0; i < stops.size(); ++i) { + float offset = stops[i].first; + Color color = stops[i].second; + + cairo_pattern_add_color_stop_rgba(pattern, offset, color.red(), color.green(), color.blue(), color.alpha()); + } + + cairo_set_source(cr, pattern); + cairo_pattern_destroy(pattern); + + return true; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp b/WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp new file mode 100644 index 0000000..6381277 --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGPaintServerPatternCairo.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "NotImplemented.h" +#include "SVGPaintServerPattern.h" + +namespace WebCore { + +bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const +{ + notImplemented(); + return true; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/cairo/SVGPaintServerSolidCairo.cpp b/WebCore/svg/graphics/cairo/SVGPaintServerSolidCairo.cpp new file mode 100644 index 0000000..6acc9b2 --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGPaintServerSolidCairo.cpp @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServerSolid.h" + +#include "GraphicsContext.h" +#include "SVGPaintServer.h" +#include "RenderPath.h" + +namespace WebCore { + +bool SVGPaintServerSolid::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const +{ + // TODO: share this code with other PaintServers + + cairo_t* cr = context->platformContext(); + const SVGRenderStyle* style = object->style()->svgStyle(); + + float red, green, blue, alpha; + color().getRGBA(red, green, blue, alpha); + + if ((type & ApplyToFillTargetType) && style->hasFill()) { + alpha = style->fillOpacity(); + + cairo_set_fill_rule(cr, style->fillRule() == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING); + } + + if ((type & ApplyToStrokeTargetType) && style->hasStroke()) { + alpha = style->strokeOpacity(); + + cairo_set_line_width(cr, SVGRenderStyle::cssPrimitiveToLength(object, style->strokeWidth(), 1.0)); + context->setLineCap(style->capStyle()); + context->setLineJoin(style->joinStyle()); + if (style->joinStyle() == MiterJoin) + context->setMiterLimit(style->strokeMiterLimit()); + + const DashArray& dashes = dashArrayFromRenderingStyle(object->style()); + double* dsh = new double[dashes.size()]; + for (unsigned i = 0 ; i < dashes.size() ; i++) + dsh[i] = dashes[i]; + double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->strokeDashOffset(), 0.0); + cairo_set_dash(cr, dsh, dashes.size(), dashOffset); + delete[] dsh; + } + + cairo_set_source_rgba(cr, red, green, blue, alpha); + + return true; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/cairo/SVGResourceClipperCairo.cpp b/WebCore/svg/graphics/cairo/SVGResourceClipperCairo.cpp new file mode 100644 index 0000000..5900fcd --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGResourceClipperCairo.cpp @@ -0,0 +1,64 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGResourceClipper.h" +#include "AffineTransform.h" +#include "GraphicsContext.h" + +#include <cairo.h> + +namespace WebCore { + +void SVGResourceClipper::applyClip(GraphicsContext* context, const FloatRect& boundingBox) const +{ + Vector<ClipData> data = m_clipData.clipData(); + unsigned int count = data.size(); + if (!count) + return; + + cairo_t* cr = context->platformContext(); + cairo_reset_clip(cr); + + for (unsigned int x = 0; x < count; x++) { + Path path = data[x].path; + if (path.isEmpty()) + continue; + path.closeSubpath(); + + if (data[x].bboxUnits) { + // Make use of the clipping units + AffineTransform transform; + transform.translate(boundingBox.x(), boundingBox.y()); + transform.scale(boundingBox.width(), boundingBox.height()); + path.transform(transform); + } + + cairo_set_fill_rule(cr, data[x].windRule == RULE_EVENODD ? CAIRO_FILL_RULE_EVEN_ODD : CAIRO_FILL_RULE_WINDING); + + // TODO: review this code, clipping may not be having the desired effect + context->clip(path); + } +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/cairo/SVGResourceFilterCairo.cpp b/WebCore/svg/graphics/cairo/SVGResourceFilterCairo.cpp new file mode 100644 index 0000000..a27038a --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGResourceFilterCairo.cpp @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2008 Collabora Ltd. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#include "NotImplemented.h" +#include "SVGResourceFilter.h" + +namespace WebCore { + +SVGResourceFilterPlatformData* SVGResourceFilter::createPlatformData() +{ + notImplemented(); + return 0; +} + +void SVGResourceFilter::prepareFilter(GraphicsContext*&, const FloatRect&) +{ + notImplemented(); +} + +void SVGResourceFilter::applyFilter(GraphicsContext*&, const FloatRect&) +{ + notImplemented(); +} + +} // namespace WebCore + +#endif + diff --git a/WebCore/svg/graphics/cairo/SVGResourceMaskerCairo.cpp b/WebCore/svg/graphics/cairo/SVGResourceMaskerCairo.cpp new file mode 100644 index 0000000..78ea76b --- /dev/null +++ b/WebCore/svg/graphics/cairo/SVGResourceMaskerCairo.cpp @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2007 Alp Toker <alp@atoker.com> + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGResourceMasker.h" +#include "ImageBuffer.h" +#include "GraphicsContext.h" + +#include <cairo.h> + +namespace WebCore { + +void SVGResourceMasker::applyMask(GraphicsContext* context, const FloatRect& boundingBox) +{ + cairo_t* cr = context->platformContext(); + cairo_surface_t* surface = m_mask->surface(); + if (!surface) + return; + cairo_pattern_t* mask = cairo_pattern_create_for_surface(surface); + cairo_mask(cr, mask); + cairo_pattern_destroy(mask); +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/cg/CgSupport.cpp b/WebCore/svg/graphics/cg/CgSupport.cpp new file mode 100644 index 0000000..9d4eec7 --- /dev/null +++ b/WebCore/svg/graphics/cg/CgSupport.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * 2006 Rob Buis <buis@kde.org> + * 2008 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "CgSupport.h" + +#include <ApplicationServices/ApplicationServices.h> +#include "FloatConversion.h" +#include "GraphicsContext.h" +#include "RenderStyle.h" +#include "SVGPaintServer.h" +#include "SVGRenderStyle.h" +#include <wtf/Assertions.h> + +namespace WebCore { + +CGAffineTransform CGAffineTransformMakeMapBetweenRects(CGRect source, CGRect dest) +{ + CGAffineTransform transform = CGAffineTransformMakeTranslation(dest.origin.x - source.origin.x, dest.origin.y - source.origin.y); + transform = CGAffineTransformScale(transform, dest.size.width/source.size.width, dest.size.height/source.size.height); + return transform; +} + +void applyStrokeStyleToContext(GraphicsContext* context, RenderStyle* style, const RenderObject* object) +{ + context->setStrokeThickness(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0f)); + context->setLineCap(style->svgStyle()->capStyle()); + context->setLineJoin(style->svgStyle()->joinStyle()); + context->setMiterLimit(style->svgStyle()->strokeMiterLimit()); + + const DashArray& dashes = dashArrayFromRenderingStyle(style); + double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0f); + + CGContextSetLineDash(context->platformContext(), narrowPrecisionToCGFloat(dashOffset), dashes.data(), dashes.size()); +} + +CGContextRef scratchContext() +{ + static CGContextRef scratch = 0; + if (!scratch) { + CFMutableDataRef empty = CFDataCreateMutable(NULL, 0); + CGDataConsumerRef consumer = CGDataConsumerCreateWithCFData(empty); + scratch = CGPDFContextCreate(consumer, NULL, NULL); + CGDataConsumerRelease(consumer); + CFRelease(empty); + + CGFloat black[4] = {0, 0, 0, 1}; + CGContextSetFillColor(scratch, black); + CGContextSetStrokeColor(scratch, black); + } + return scratch; +} + +FloatRect strokeBoundingBox(const Path& path, RenderStyle* style, const RenderObject* object) + { + // the bbox might grow if the path is stroked. + // and CGPathGetBoundingBox doesn't support that, so we'll have + // to make an alternative call... + + // FIXME: since this is mainly used to decide what to repaint, + // perhaps it would be sufficien to just outset the fill bbox by + // the stroke width - that should be way cheaper and simpler than + // what we do here. + + CGPathRef cgPath = path.platformPath(); + + CGContextRef context = scratchContext(); + CGContextSaveGState(context); + + CGContextBeginPath(context); + CGContextAddPath(context, cgPath); + + GraphicsContext gc(context); + applyStrokeStyleToContext(&gc, style, object); + + CGContextReplacePathWithStrokedPath(context); + if (CGContextIsPathEmpty(context)) { + // CGContextReplacePathWithStrokedPath seems to fail to create a path sometimes, this is not well understood. + // returning here prevents CG from logging to the console from CGContextGetPathBoundingBox + CGContextRestoreGState(context); + return FloatRect(); + } + + CGRect box = CGContextGetPathBoundingBox(context); + CGContextRestoreGState(context); + + return FloatRect(box); +} + +} + +#endif // ENABLE(SVG) + diff --git a/WebCore/svg/graphics/cg/CgSupport.h b/WebCore/svg/graphics/cg/CgSupport.h new file mode 100644 index 0000000..454e5b9 --- /dev/null +++ b/WebCore/svg/graphics/cg/CgSupport.h @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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 CgSupport_h +#define CgSupport_h + +#if ENABLE(SVG) + +#include <ApplicationServices/ApplicationServices.h> +#include "GraphicsTypes.h" + +namespace WebCore { + +typedef struct CGPath *CGMutablePathRef; + +class Path; +class FloatRect; +class RenderStyle; +class RenderObject; +class GraphicsContext; + +CGAffineTransform CGAffineTransformMakeMapBetweenRects(CGRect source, CGRect dest); + +void applyStrokeStyleToContext(GraphicsContext*, RenderStyle*, const RenderObject*); + +CGContextRef scratchContext(); +FloatRect strokeBoundingBox(const Path& path, RenderStyle*, const RenderObject*); + +} + +#endif // ENABLE(SVG) +#endif // !CgSupport_h diff --git a/WebCore/svg/graphics/cg/RenderPathCg.cpp b/WebCore/svg/graphics/cg/RenderPathCg.cpp new file mode 100644 index 0000000..eb8e482 --- /dev/null +++ b/WebCore/svg/graphics/cg/RenderPathCg.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * (C) 2006 Alexander Kellett <lypanov@kde.org> + * 2006 Rob Buis <buis@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "RenderPath.h" + +#include <ApplicationServices/ApplicationServices.h> +#include "CgSupport.h" +#include "GraphicsContext.h" +#include "SVGPaintServer.h" +#include "SVGRenderStyle.h" +#include "SVGStyledElement.h" +#include <wtf/Assertions.h> + +namespace WebCore { + +FloatRect RenderPath::strokeBBox() const +{ + if (style()->svgStyle()->hasStroke()) + return strokeBoundingBox(path(), style(), this); + + return path().boundingRect(); +} + + +bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const +{ + if (path().isEmpty()) + return false; + + if (requiresStroke && !SVGPaintServer::strokePaintServer(style(), this)) + return false; + + CGMutablePathRef cgPath = path().platformPath(); + + CGContextRef context = scratchContext(); + CGContextSaveGState(context); + + CGContextBeginPath(context); + CGContextAddPath(context, cgPath); + + GraphicsContext gc(context); + applyStrokeStyleToContext(&gc, style(), this); + + bool hitSuccess = CGContextPathContainsPoint(context, point, kCGPathStroke); + CGContextRestoreGState(context); + + return hitSuccess; +} + +} + +#endif // ENABLE(SVG) diff --git a/WebCore/svg/graphics/cg/SVGPaintServerCg.cpp b/WebCore/svg/graphics/cg/SVGPaintServerCg.cpp new file mode 100644 index 0000000..35eb239 --- /dev/null +++ b/WebCore/svg/graphics/cg/SVGPaintServerCg.cpp @@ -0,0 +1,89 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServer.h" + +#include "GraphicsContext.h" +#include "RenderObject.h" + +namespace WebCore { + +void SVGPaintServer::draw(GraphicsContext*& context, const RenderObject* path, SVGPaintTargetType type) const +{ + if (!setup(context, path, type)) + return; + + renderPath(context, path, type); + teardown(context, path, type); +} + +void SVGPaintServer::teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const +{ + // no-op +} + +void SVGPaintServer::renderPath(GraphicsContext*& context, const RenderObject* path, SVGPaintTargetType type) const +{ + RenderStyle* style = path ? path->style() : 0; + CGContextRef contextRef = context->platformContext(); + + if ((type & ApplyToFillTargetType) && (!style || style->svgStyle()->hasFill())) + fillPath(contextRef, path); + + if ((type & ApplyToStrokeTargetType) && (!style || style->svgStyle()->hasStroke())) + strokePath(contextRef, path); +} + +void SVGPaintServer::strokePath(CGContextRef context, const RenderObject*) const +{ + CGContextStrokePath(context); +} + +void SVGPaintServer::clipToStrokePath(CGContextRef context, const RenderObject*) const +{ + CGContextReplacePathWithStrokedPath(context); + CGContextClip(context); +} + +void SVGPaintServer::fillPath(CGContextRef context, const RenderObject* path) const +{ + if (!path || path->style()->svgStyle()->fillRule() == RULE_EVENODD) + CGContextEOFillPath(context); + else + CGContextFillPath(context); +} + +void SVGPaintServer::clipToFillPath(CGContextRef context, const RenderObject* path) const +{ + if (!path || path->style()->svgStyle()->fillRule() == RULE_EVENODD) + CGContextEOClip(context); + else + CGContextClip(context); +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/cg/SVGPaintServerGradientCg.cpp b/WebCore/svg/graphics/cg/SVGPaintServerGradientCg.cpp new file mode 100644 index 0000000..4d41d88 --- /dev/null +++ b/WebCore/svg/graphics/cg/SVGPaintServerGradientCg.cpp @@ -0,0 +1,341 @@ +/* + Copyright (C) 2006, 2007, 2008 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServerGradient.h" + +#include "CgSupport.h" +#include "FloatConversion.h" +#include "GraphicsContext.h" +#include "ImageBuffer.h" +#include "RenderObject.h" +#include "SVGGradientElement.h" +#include "SVGPaintServerLinearGradient.h" +#include "SVGPaintServerRadialGradient.h" +#include "SVGRenderSupport.h" + +#include <wtf/MathExtras.h> + +using namespace std; + +namespace WebCore { + +static void releaseCachedStops(void* info) +{ + static_cast<SVGPaintServerGradient::SharedStopCache*>(info)->deref(); +} + +static void cgGradientCallback(void* info, const CGFloat* inValues, CGFloat* outColor) +{ + SVGPaintServerGradient::SharedStopCache* stopsCache = static_cast<SVGPaintServerGradient::SharedStopCache*>(info); + + SVGPaintServerGradient::QuartzGradientStop* stops = stopsCache->m_stops.data(); + + int stopsCount = stopsCache->m_stops.size(); + + CGFloat inValue = inValues[0]; + + if (!stopsCount) { + outColor[0] = 0; + outColor[1] = 0; + outColor[2] = 0; + outColor[3] = 0; + return; + } else if (stopsCount == 1) { + memcpy(outColor, stops[0].colorArray, 4 * sizeof(CGFloat)); + return; + } + + if (!(inValue > stops[0].offset)) + memcpy(outColor, stops[0].colorArray, 4 * sizeof(CGFloat)); + else if (!(inValue < stops[stopsCount - 1].offset)) + memcpy(outColor, stops[stopsCount - 1].colorArray, 4 * sizeof(CGFloat)); + else { + int nextStopIndex = 0; + while ((nextStopIndex < stopsCount) && (stops[nextStopIndex].offset < inValue)) + nextStopIndex++; + + CGFloat* nextColorArray = stops[nextStopIndex].colorArray; + CGFloat* previousColorArray = stops[nextStopIndex - 1].colorArray; + CGFloat diffFromPrevious = inValue - stops[nextStopIndex - 1].offset; + CGFloat percent = diffFromPrevious * stops[nextStopIndex].previousDeltaInverse; + + outColor[0] = ((1.0f - percent) * previousColorArray[0] + percent * nextColorArray[0]); + outColor[1] = ((1.0f - percent) * previousColorArray[1] + percent * nextColorArray[1]); + outColor[2] = ((1.0f - percent) * previousColorArray[2] + percent * nextColorArray[2]); + outColor[3] = ((1.0f - percent) * previousColorArray[3] + percent * nextColorArray[3]); + } + // FIXME: have to handle the spreadMethod()s here SPREADMETHOD_REPEAT, etc. +} + +static CGShadingRef CGShadingRefForLinearGradient(const SVGPaintServerLinearGradient* server) +{ + CGPoint start = CGPoint(server->gradientStart()); + CGPoint end = CGPoint(server->gradientEnd()); + + CGFunctionCallbacks callbacks = {0, cgGradientCallback, releaseCachedStops}; + CGFloat domainLimits[2] = {0, 1}; + CGFloat rangeLimits[8] = {0, 1, 0, 1, 0, 1, 0, 1}; + server->m_stopsCache->ref(); + CGFunctionRef shadingFunction = CGFunctionCreate(server->m_stopsCache.get(), 1, domainLimits, 4, rangeLimits, &callbacks); + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGShadingRef shading = CGShadingCreateAxial(colorSpace, start, end, shadingFunction, true, true); + CGColorSpaceRelease(colorSpace); + CGFunctionRelease(shadingFunction); + return shading; +} + +static CGShadingRef CGShadingRefForRadialGradient(const SVGPaintServerRadialGradient* server) +{ + CGPoint center = CGPoint(server->gradientCenter()); + CGPoint focus = CGPoint(server->gradientFocal()); + double radius = server->gradientRadius(); + + double fdx = focus.x - center.x; + double fdy = focus.y - center.y; + + // Spec: If (fx, fy) lies outside the circle defined by (cx, cy) and r, set (fx, fy) + // to the point of intersection of the line through (fx, fy) and the circle. + if (sqrt(fdx * fdx + fdy * fdy) > radius) { + double angle = atan2(focus.y * 100.0, focus.x * 100.0); + focus.x = narrowPrecisionToCGFloat(cos(angle) * radius); + focus.y = narrowPrecisionToCGFloat(sin(angle) * radius); + } + + CGFunctionCallbacks callbacks = {0, cgGradientCallback, releaseCachedStops}; + CGFloat domainLimits[2] = {0, 1}; + CGFloat rangeLimits[8] = {0, 1, 0, 1, 0, 1, 0, 1}; + server->m_stopsCache->ref(); + CGFunctionRef shadingFunction = CGFunctionCreate(server->m_stopsCache.get(), 1, domainLimits, 4, rangeLimits, &callbacks); + + CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB(); + CGShadingRef shading = CGShadingCreateRadial(colorSpace, focus, 0, center, narrowPrecisionToCGFloat(radius), shadingFunction, true, true); + CGColorSpaceRelease(colorSpace); + CGFunctionRelease(shadingFunction); + return shading; +} + +void SVGPaintServerGradient::updateQuartzGradientStopsCache(const Vector<SVGGradientStop>& stops) +{ + m_stopsCache = SharedStopCache::create(); + Vector<QuartzGradientStop>& stopsCache = m_stopsCache->m_stops; + stopsCache.resize(stops.size()); + CGFloat previousOffset = 0.0f; + for (unsigned i = 0; i < stops.size(); ++i) { + CGFloat currOffset = min(max(stops[i].first, previousOffset), static_cast<CGFloat>(1.0)); + stopsCache[i].offset = currOffset; + stopsCache[i].previousDeltaInverse = 1.0f / (currOffset - previousOffset); + previousOffset = currOffset; + CGFloat* ca = stopsCache[i].colorArray; + stops[i].second.getRGBA(ca[0], ca[1], ca[2], ca[3]); + } +} + +void SVGPaintServerGradient::updateQuartzGradientCache(const SVGPaintServerGradient* server) +{ + // cache our own copy of the stops for faster access. + // this is legacy code, probably could be reworked. + if (!m_stopsCache) + updateQuartzGradientStopsCache(gradientStops()); + + CGShadingRelease(m_shadingCache); + + if (type() == RadialGradientPaintServer) { + const SVGPaintServerRadialGradient* radial = static_cast<const SVGPaintServerRadialGradient*>(server); + m_shadingCache = CGShadingRefForRadialGradient(radial); + } else if (type() == LinearGradientPaintServer) { + const SVGPaintServerLinearGradient* linear = static_cast<const SVGPaintServerLinearGradient*>(server); + m_shadingCache = CGShadingRefForLinearGradient(linear); + } +} + +// Helper function for text painting +static inline const RenderObject* findTextRootObject(const RenderObject* start) +{ + while (start && !start->isSVGText()) + start = start->parent(); + + ASSERT(start); + ASSERT(start->isSVGText()); + + return start; +} + +void SVGPaintServerGradient::teardown(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const +{ + CGShadingRef shading = m_shadingCache; + CGContextRef contextRef = context->platformContext(); + ASSERT(contextRef); + + // As renderPath() is not used when painting text, special logic needed here. + if (isPaintingText) { + if (m_savedContext) { + FloatRect maskBBox = const_cast<RenderObject*>(findTextRootObject(object))->relativeBBox(false); + + // Fixup transformations to be able to clip to mask + AffineTransform transform = object->absoluteTransform(); + FloatRect textBoundary = transform.mapRect(maskBBox); + + IntSize maskSize(lroundf(textBoundary.width()), lroundf(textBoundary.height())); + clampImageBufferSizeToViewport(object->document()->renderer(), maskSize); + + if (maskSize.width() < static_cast<int>(textBoundary.width())) + textBoundary.setWidth(maskSize.width()); + + if (maskSize.height() < static_cast<int>(textBoundary.height())) + textBoundary.setHeight(maskSize.height()); + + // Clip current context to mask image (gradient) + m_savedContext->concatCTM(transform.inverse()); + CGContextClipToMask(m_savedContext->platformContext(), CGRect(textBoundary), m_imageBuffer->cgImage()); + m_savedContext->concatCTM(transform); + + handleBoundingBoxModeAndGradientTransformation(m_savedContext, maskBBox); + + // Restore on-screen drawing context, after we got the image of the gradient + delete m_imageBuffer; + + context = m_savedContext; + contextRef = context->platformContext(); + + m_savedContext = 0; + m_imageBuffer = 0; + } + } + + CGContextDrawShading(contextRef, shading); + context->restore(); +} + +void SVGPaintServerGradient::renderPath(GraphicsContext*& context, const RenderObject* path, SVGPaintTargetType type) const +{ + RenderStyle* style = path->style(); + CGContextRef contextRef = context->platformContext(); + ASSERT(contextRef); + + bool isFilled = (type & ApplyToFillTargetType) && style->svgStyle()->hasFill(); + + // Compute destination object bounding box + FloatRect objectBBox; + if (boundingBoxMode()) { + FloatRect bbox = path->relativeBBox(false); + if (bbox.width() > 0 && bbox.height() > 0) + objectBBox = bbox; + } + + if (isFilled) + clipToFillPath(contextRef, path); + else + clipToStrokePath(contextRef, path); + + handleBoundingBoxModeAndGradientTransformation(context, objectBBox); +} + +void SVGPaintServerGradient::handleBoundingBoxModeAndGradientTransformation(GraphicsContext* context, const FloatRect& targetRect) const +{ + CGContextRef contextRef = context->platformContext(); + + if (boundingBoxMode()) { + // Choose default gradient bounding box + CGRect gradientBBox = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f); + + // Generate a transform to map between both bounding boxes + CGAffineTransform gradientIntoObjectBBox = CGAffineTransformMakeMapBetweenRects(gradientBBox, CGRect(targetRect)); + CGContextConcatCTM(contextRef, gradientIntoObjectBBox); + } + + // Apply the gradient's own transform + CGAffineTransform transform = gradientTransform(); + CGContextConcatCTM(contextRef, transform); +} + +bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const +{ + m_ownerElement->buildGradient(); + + // We need a hook to call this when the gradient gets updated, before drawn. + if (!m_shadingCache) + const_cast<SVGPaintServerGradient*>(this)->updateQuartzGradientCache(this); + + CGContextRef contextRef = context->platformContext(); + ASSERT(contextRef); + + RenderStyle* style = object->style(); + + bool isFilled = (type & ApplyToFillTargetType) && style->svgStyle()->hasFill(); + bool isStroked = (type & ApplyToStrokeTargetType) && style->svgStyle()->hasStroke(); + + ASSERT(isFilled && !isStroked || !isFilled && isStroked); + + context->save(); + CGContextSetAlpha(contextRef, isFilled ? style->svgStyle()->fillOpacity() : style->svgStyle()->strokeOpacity()); + + if (isPaintingText) { + FloatRect maskBBox = const_cast<RenderObject*>(findTextRootObject(object))->relativeBBox(false); + IntRect maskRect = enclosingIntRect(object->absoluteTransform().mapRect(maskBBox)); + + IntSize maskSize(maskRect.width(), maskRect.height()); + clampImageBufferSizeToViewport(object->document()->renderer(), maskSize); + + auto_ptr<ImageBuffer> maskImage = ImageBuffer::create(maskSize, false); + + if (!maskImage.get()) { + context->restore(); + return false; + } + + GraphicsContext* maskImageContext = maskImage->context(); + maskImageContext->save(); + + maskImageContext->setTextDrawingMode(isFilled ? cTextFill : cTextStroke); + maskImageContext->translate(-maskRect.x(), -maskRect.y()); + maskImageContext->concatCTM(object->absoluteTransform()); + + m_imageBuffer = maskImage.release(); + m_savedContext = context; + + context = maskImageContext; + contextRef = context->platformContext(); + } + + if (isStroked) + applyStrokeStyleToContext(context, style, object); + + return true; +} + +void SVGPaintServerGradient::invalidate() +{ + SVGPaintServer::invalidate(); + + // Invalidate caches + CGShadingRelease(m_shadingCache); + + m_stopsCache = 0; + m_shadingCache = 0; +} + +} // namespace WebCore + +#endif diff --git a/WebCore/svg/graphics/cg/SVGPaintServerPatternCg.cpp b/WebCore/svg/graphics/cg/SVGPaintServerPatternCg.cpp new file mode 100644 index 0000000..e12ff77 --- /dev/null +++ b/WebCore/svg/graphics/cg/SVGPaintServerPatternCg.cpp @@ -0,0 +1,126 @@ +/* + Copyright (C) 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServerPattern.h" + +#include "CgSupport.h" +#include "GraphicsContext.h" +#include "ImageBuffer.h" +#include "RenderObject.h" +#include "SVGPatternElement.h" + +namespace WebCore { + +static void patternCallback(void* info, CGContextRef context) +{ + ImageBuffer* patternImage = reinterpret_cast<ImageBuffer*>(info); + CGContextDrawImage(context, CGRect(FloatRect(FloatPoint(), patternImage->size())), patternImage->cgImage()); +} + +bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const +{ + CGContextRef contextRef = context->platformContext(); + + // Build pattern tile, passing destination object bounding box + FloatRect targetRect; + if (isPaintingText) { + IntRect textBoundary = const_cast<RenderObject*>(object)->absoluteBoundingBoxRect(); + targetRect = object->absoluteTransform().inverse().mapRect(textBoundary); + } else + targetRect = object->relativeBBox(false); + + m_ownerElement->buildPattern(targetRect); + + if (!tile()) + return false; + + context->save(); + + // Respect local pattern transformation + context->concatCTM(patternTransform()); + + // Apply pattern space transformation + context->translate(patternBoundaries().x(), patternBoundaries().y()); + + // Crude hack to support overflow="visible". + // When the patternBoundaries() size is smaller than the actual tile() size, we run into a problem: + // Our tile contains content which is larger than the pattern cell size. We just draw the pattern + // "out of" cell boundaries, to draw the overflown content, instead of clipping it away. The uppermost + // cell doesn't include the overflown content of the cell right above it though -> that's why we're moving + // down the phase by a very small amount, so we're sure the "cell right above"'s overflown content gets drawn. + CGContextSetPatternPhase(contextRef, CGSizeMake(0.0f, -0.01f)); + + RenderStyle* style = object->style(); + CGContextSetAlpha(contextRef, style->opacity()); + + CGPatternCallbacks callbacks = {0, patternCallback, 0}; + + ASSERT(!m_pattern); + m_pattern = CGPatternCreate(tile(), + CGRect(FloatRect(FloatPoint(), tile()->size())), + CGContextGetCTM(contextRef), + patternBoundaries().width(), + patternBoundaries().height(), + kCGPatternTilingConstantSpacing, + true, // has color + &callbacks); + + if (!m_patternSpace) + m_patternSpace = CGColorSpaceCreatePattern(0); + + if ((type & ApplyToFillTargetType) && style->svgStyle()->hasFill()) { + CGFloat alpha = style->svgStyle()->fillOpacity(); + CGContextSetFillColorSpace(contextRef, m_patternSpace); + CGContextSetFillPattern(contextRef, m_pattern, &alpha); + + if (isPaintingText) + context->setTextDrawingMode(cTextFill); + } + + if ((type & ApplyToStrokeTargetType) && style->svgStyle()->hasStroke()) { + CGFloat alpha = style->svgStyle()->strokeOpacity(); + CGContextSetStrokeColorSpace(contextRef, m_patternSpace); + CGContextSetStrokePattern(contextRef, m_pattern, &alpha); + applyStrokeStyleToContext(context, style, object); + + if (isPaintingText) + context->setTextDrawingMode(cTextStroke); + } + + return true; +} + +void SVGPaintServerPattern::teardown(GraphicsContext*& context, const RenderObject*, SVGPaintTargetType, bool) const +{ + CGPatternRelease(m_pattern); + m_pattern = 0; + + context->restore(); +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/cg/SVGPaintServerSolidCg.cpp b/WebCore/svg/graphics/cg/SVGPaintServerSolidCg.cpp new file mode 100644 index 0000000..706f39c --- /dev/null +++ b/WebCore/svg/graphics/cg/SVGPaintServerSolidCg.cpp @@ -0,0 +1,78 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServerSolid.h" + +#include "GraphicsContext.h" +#include "RenderObject.h" +#include "CgSupport.h" + +namespace WebCore { + +bool SVGPaintServerSolid::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const +{ + CGContextRef contextRef = context->platformContext(); + RenderStyle* style = object ? object->style() : 0; + + static CGColorSpaceRef deviceRGBColorSpace = CGColorSpaceCreateDeviceRGB(); // This should be shared from GraphicsContext, or some other central location + + if ((type & ApplyToFillTargetType) && (!style || style->svgStyle()->hasFill())) { + CGFloat colorComponents[4]; + color().getRGBA(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]); + ASSERT(!color().hasAlpha()); + if (style) + colorComponents[3] = style->svgStyle()->fillOpacity(); // SVG/CSS colors are not specified w/o alpha + + CGContextSetFillColorSpace(contextRef, deviceRGBColorSpace); + CGContextSetFillColor(contextRef, colorComponents); + + if (isPaintingText) + context->setTextDrawingMode(cTextFill); + } + + if ((type & ApplyToStrokeTargetType) && (!style || style->svgStyle()->hasStroke())) { + CGFloat colorComponents[4]; + color().getRGBA(colorComponents[0], colorComponents[1], colorComponents[2], colorComponents[3]); + ASSERT(!color().hasAlpha()); + if (style) + colorComponents[3] = style->svgStyle()->strokeOpacity(); // SVG/CSS colors are not specified w/o alpha + + CGContextSetStrokeColorSpace(contextRef, deviceRGBColorSpace); + CGContextSetStrokeColor(contextRef, colorComponents); + + if (style) + applyStrokeStyleToContext(context, style, object); + + if (isPaintingText) + context->setTextDrawingMode(cTextStroke); + } + + return true; +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/cg/SVGResourceClipperCg.cpp b/WebCore/svg/graphics/cg/SVGResourceClipperCg.cpp new file mode 100644 index 0000000..071afe2 --- /dev/null +++ b/WebCore/svg/graphics/cg/SVGResourceClipperCg.cpp @@ -0,0 +1,83 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * 2005 Alexander Kellett <lypanov@kde.org> + * + * 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" + +#if ENABLE(SVG) +#include "SVGResourceClipper.h" + +#include "GraphicsContext.h" +#include "CgSupport.h" + +namespace WebCore { + +void SVGResourceClipper::applyClip(GraphicsContext* context, const FloatRect& boundingBox) const +{ + CGContextRef cgContext = context->platformContext(); + if (m_clipData.clipData().size() < 1) + return; + + bool heterogenousClipRules = false; + WindRule clipRule = m_clipData.clipData()[0].windRule; + + context->beginPath(); + + CGAffineTransform bboxTransform = CGAffineTransformMakeMapBetweenRects(CGRectMake(0,0,1,1), CGRect(boundingBox)); + + for (unsigned x = 0; x < m_clipData.clipData().size(); x++) { + ClipData data = m_clipData.clipData()[x]; + if (data.windRule != clipRule) + heterogenousClipRules = true; + + CGPathRef clipPath = data.path.platformPath(); + + if (data.bboxUnits) { + CGMutablePathRef transformedPath = CGPathCreateMutable(); + CGPathAddPath(transformedPath, &bboxTransform, clipPath); + CGContextAddPath(cgContext, transformedPath); + CGPathRelease(transformedPath); + } else + CGContextAddPath(cgContext, clipPath); + } + + if (m_clipData.clipData().size()) { + // FIXME! + // We don't currently allow for heterogenous clip rules. + // we would have to detect such, draw to a mask, and then clip + // to that mask + if (!CGContextIsPathEmpty(cgContext)) { + if (clipRule == RULE_EVENODD) + CGContextEOClip(cgContext); + else + CGContextClip(cgContext); + } + } +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/WebCore/svg/graphics/cg/SVGResourceFilterCg.cpp b/WebCore/svg/graphics/cg/SVGResourceFilterCg.cpp new file mode 100644 index 0000000..ecfcdd8 --- /dev/null +++ b/WebCore/svg/graphics/cg/SVGResourceFilterCg.cpp @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2005, 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2006 Dave MacLachlan (dmaclach@mac.com) + * 2006 Rob Buis <buis@kde.org> + * + * 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" +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "NotImplemented.h" +#include "SVGResourceFilter.h" + +namespace WebCore { + +SVGResourceFilterPlatformData* SVGResourceFilter::createPlatformData() +{ + return 0; +} + +void SVGResourceFilter::prepareFilter(GraphicsContext*&, const FloatRect&) +{ + notImplemented(); +} + +void SVGResourceFilter::applyFilter(GraphicsContext*&, const FloatRect&) +{ + notImplemented(); +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/cg/SVGResourceFilterCg.mm b/WebCore/svg/graphics/cg/SVGResourceFilterCg.mm new file mode 100644 index 0000000..f3dc819 --- /dev/null +++ b/WebCore/svg/graphics/cg/SVGResourceFilterCg.mm @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. All rights reserved. + * (C) 2007 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGResourceFilter.h" + +#include "AffineTransform.h" +#include "FoundationExtras.h" +#include "GraphicsContext.h" + +#include "SVGResourceFilterPlatformDataMac.h" + +#include <QuartzCore/CoreImage.h> + +// Setting to a value > 0 allows to dump the output image as JPEG. +#define DEBUG_OUTPUT_IMAGE 0 + +namespace WebCore { + +SVGResourceFilterPlatformData* SVGResourceFilter::createPlatformData() +{ + return new SVGResourceFilterPlatformDataMac(this); +} + +void SVGResourceFilter::prepareFilter(GraphicsContext*& context, const FloatRect& bbox) +{ + if (bbox.isEmpty() || m_effects.isEmpty()) + return; + + SVGResourceFilterPlatformDataMac* platform = static_cast<SVGResourceFilterPlatformDataMac*>(platformData()); + + CGContextRef cgContext = context->platformContext(); + + // Use of CGBegin/EndTransparencyLayer around this call causes over release + // of cgContext due to it being created on an autorelease pool, and released + // after CGEndTransparencyLayer. Create local pool to fix. + // <http://bugs.webkit.org/show_bug.cgi?id=8425> + // <http://bugs.webkit.org/show_bug.cgi?id=6947> + // <rdar://problem/4647735> + NSAutoreleasePool* filterContextPool = [[NSAutoreleasePool alloc] init]; + platform->m_filterCIContext = HardRetain([CIContext contextWithCGContext:cgContext options:nil]); + [filterContextPool drain]; + + FloatRect filterRect = filterBBoxForItemBBox(bbox); + + // TODO: Ensure the size is not greater than the nearest <svg> size and/or the window size. + // This is also needed for masking & gradients-on-stroke-of-text. File a bug on this. + float width = filterRect.width(); + float height = filterRect.height(); + + platform->m_filterCGLayer = [platform->m_filterCIContext createCGLayerWithSize:CGSizeMake(width, height) info:NULL]; + + context = new GraphicsContext(CGLayerGetContext(platform->m_filterCGLayer)); + context->save(); + + context->translate(-filterRect.x(), -filterRect.y()); +} + +#ifndef NDEBUG +// Extremly helpful debugging utilities for any paint server / resource that creates +// internal image buffers (ie. gradients on text, masks, filters...) +void dumpCIOutputImage(CIImage* outputImage, NSString* fileName) +{ + CGSize extentSize = [outputImage extent].size; + NSImage* image = [[[NSImage alloc] initWithSize:NSMakeSize(extentSize.width, extentSize.height)] autorelease]; + [image addRepresentation:[NSCIImageRep imageRepWithCIImage:outputImage]]; + + NSData* imageData = [image TIFFRepresentation]; + NSBitmapImageRep* imageRep = [NSBitmapImageRep imageRepWithData:imageData]; + imageData = [imageRep representationUsingType:NSJPEGFileType properties:nil]; + + [imageData writeToFile:fileName atomically:YES]; +} + +void dumpCGOutputImage(CGImage* outputImage, NSString* fileName) +{ + if (CIImage* ciOutputImage = [CIImage imageWithCGImage:outputImage]) + dumpCIOutputImage(ciOutputImage, fileName); +} +#endif + +void SVGResourceFilter::applyFilter(GraphicsContext*& context, const FloatRect& bbox) +{ + if (bbox.isEmpty() || m_effects.isEmpty()) + return; + + SVGResourceFilterPlatformDataMac* platform = static_cast<SVGResourceFilterPlatformDataMac*>(platformData()); + + // actually apply the filter effects + CIImage* inputImage = [CIImage imageWithCGLayer:platform->m_filterCGLayer]; + NSArray* filterStack = platform->getCIFilterStack(inputImage, bbox); + if ([filterStack count]) { + CIImage* outputImage = [[filterStack lastObject] valueForKey:@"outputImage"]; + + if (outputImage) { +#if DEBUG_OUTPUT_IMAGE > 0 + dumpOutputImage(outputImage); +#endif + + FloatRect filterRect = filterBBoxForItemBBox(bbox); + FloatPoint destOrigin = filterRect.location(); + filterRect.setLocation(FloatPoint(0.0f, 0.0f)); + + [platform->m_filterCIContext drawImage:outputImage atPoint:CGPoint(destOrigin) fromRect:filterRect]; + } + } + + CGLayerRelease(platform->m_filterCGLayer); + platform->m_filterCGLayer = 0; + + HardRelease(platform->m_filterCIContext); + platform->m_filterCIContext = 0; + + delete context; + context = 0; +} + +} + +#endif // ENABLE(SVG) ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/cg/SVGResourceMaskerCg.cpp b/WebCore/svg/graphics/cg/SVGResourceMaskerCg.cpp new file mode 100644 index 0000000..4d2100b --- /dev/null +++ b/WebCore/svg/graphics/cg/SVGResourceMaskerCg.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2007 Apple Inc. + * + * 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" + +#if ENABLE(SVG) +#include "SVGResourceMasker.h" +#include "NotImplemented.h" + +namespace WebCore { + +void SVGResourceMasker::applyMask(GraphicsContext*, const FloatRect&) +{ + notImplemented(); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/WebCore/svg/graphics/cg/SVGResourceMaskerCg.mm b/WebCore/svg/graphics/cg/SVGResourceMaskerCg.mm new file mode 100644 index 0000000..00e62e7 --- /dev/null +++ b/WebCore/svg/graphics/cg/SVGResourceMaskerCg.mm @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2005, 2006 Alexander Kellett <lypanov@kde.org> + * Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + * + * 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" + +#if ENABLE(SVG) +#import "SVGResourceMasker.h" + +#import "BlockExceptions.h" +#import "CgSupport.h" +#import "GraphicsContext.h" +#import "ImageBuffer.h" +#import "SVGMaskElement.h" +#import "SVGRenderSupport.h" +#import "SVGRenderStyle.h" +#import "SVGResourceFilter.h" +#import <QuartzCore/CIFilter.h> +#import <QuartzCore/CoreImage.h> + +using namespace std; + +namespace WebCore { + +static CIImage* applyLuminanceToAlphaFilter(CIImage* inputImage) +{ + CIFilter* luminanceToAlpha = [CIFilter filterWithName:@"CIColorMatrix"]; + [luminanceToAlpha setDefaults]; + CGFloat alpha[4] = {0.2125f, 0.7154f, 0.0721f, 0.0f}; + CGFloat zero[4] = {0.0f, 0.0f, 0.0f, 0.0f}; + [luminanceToAlpha setValue:inputImage forKey:@"inputImage"]; + [luminanceToAlpha setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputRVector"]; + [luminanceToAlpha setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputGVector"]; + [luminanceToAlpha setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputBVector"]; + [luminanceToAlpha setValue:[CIVector vectorWithValues:alpha count:4] forKey:@"inputAVector"]; + [luminanceToAlpha setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputBiasVector"]; + return [luminanceToAlpha valueForKey:@"outputImage"]; +} + +static CIImage* applyExpandAlphatoGrayscaleFilter(CIImage* inputImage) +{ + CIFilter* alphaToGrayscale = [CIFilter filterWithName:@"CIColorMatrix"]; + CGFloat zero[4] = {0, 0, 0, 0}; + [alphaToGrayscale setDefaults]; + [alphaToGrayscale setValue:inputImage forKey:@"inputImage"]; + [alphaToGrayscale setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputRVector"]; + [alphaToGrayscale setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputGVector"]; + [alphaToGrayscale setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputBVector"]; + [alphaToGrayscale setValue:[CIVector vectorWithX:0.0f Y:0.0f Z:0.0f W:1.0f] forKey:@"inputAVector"]; + [alphaToGrayscale setValue:[CIVector vectorWithX:1.0f Y:1.0f Z:1.0f W:0.0f] forKey:@"inputBiasVector"]; + return [alphaToGrayscale valueForKey:@"outputImage"]; +} + +static CIImage* transformImageIntoGrayscaleMask(CIImage* inputImage) +{ + CIFilter* blackBackground = [CIFilter filterWithName:@"CIConstantColorGenerator"]; + [blackBackground setValue:[CIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:1.0f] forKey:@"inputColor"]; + + CIFilter* layerOverBlack = [CIFilter filterWithName:@"CISourceOverCompositing"]; + [layerOverBlack setValue:[blackBackground valueForKey:@"outputImage"] forKey:@"inputBackgroundImage"]; + [layerOverBlack setValue:inputImage forKey:@"inputImage"]; + + CIImage* luminanceAlpha = applyLuminanceToAlphaFilter([layerOverBlack valueForKey:@"outputImage"]); + CIImage* luminanceAsGrayscale = applyExpandAlphatoGrayscaleFilter(luminanceAlpha); + CIImage* alphaAsGrayscale = applyExpandAlphatoGrayscaleFilter(inputImage); + + CIFilter* multipliedGrayscale = [CIFilter filterWithName:@"CIMultiplyCompositing"]; + [multipliedGrayscale setValue:luminanceAsGrayscale forKey:@"inputBackgroundImage"]; + [multipliedGrayscale setValue:alphaAsGrayscale forKey:@"inputImage"]; + return [multipliedGrayscale valueForKey:@"outputImage"]; +} + +void SVGResourceMasker::applyMask(GraphicsContext* context, const FloatRect& boundingBox) +{ + if (!m_mask) + m_mask.set(m_ownerElement->drawMaskerContent(boundingBox, m_maskRect).release()); + if (!m_mask) + return; + + IntSize maskSize(static_cast<int>(m_maskRect.width()), static_cast<int>(m_maskRect.height())); + clampImageBufferSizeToViewport(m_ownerElement->document()->renderer(), maskSize); + + // Create new graphics context in gray scale mode for image rendering + auto_ptr<ImageBuffer> grayScaleImage(ImageBuffer::create(maskSize, true)); + if (!grayScaleImage.get()) + return; + + BEGIN_BLOCK_OBJC_EXCEPTIONS + CGContextRef grayScaleContext = grayScaleImage->context()->platformContext(); + CIContext* ciGrayscaleContext = [CIContext contextWithCGContext:grayScaleContext options:nil]; + + // Transform colorized mask to gray scale + CIImage* colorMask = [CIImage imageWithCGImage:m_mask->cgImage()]; + if (!colorMask) + return; + CIImage* grayScaleMask = transformImageIntoGrayscaleMask(colorMask); + [ciGrayscaleContext drawImage:grayScaleMask atPoint:CGPointZero fromRect:CGRectMake(0, 0, maskSize.width(), maskSize.height())]; + + CGContextClipToMask(context->platformContext(), m_maskRect, grayScaleImage->cgImage()); + END_BLOCK_OBJC_EXCEPTIONS +} + +} // namespace WebCore + +#endif // ENABLE(SVG) diff --git a/WebCore/svg/graphics/filters/SVGDistantLightSource.h b/WebCore/svg/graphics/filters/SVGDistantLightSource.h new file mode 100644 index 0000000..c4ff9b7 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGDistantLightSource.h @@ -0,0 +1,52 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGDistantLightSource_h +#define SVGDistantLightSource_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGLightSource.h" + +namespace WebCore { + +class SVGDistantLightSource : public SVGLightSource { +public: + SVGDistantLightSource(float azimuth, float elevation) + : SVGLightSource(LS_DISTANT) + , m_azimuth(azimuth) + , m_elevation(elevation) + { } + + float azimuth() const { return m_azimuth; } + float elevation() const { return m_elevation; } + + virtual TextStream& externalRepresentation(TextStream&) const; + +private: + float m_azimuth; + float m_elevation; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGDistantLightSource_h diff --git a/WebCore/svg/graphics/filters/SVGFEBlend.cpp b/WebCore/svg/graphics/filters/SVGFEBlend.cpp new file mode 100644 index 0000000..a1f2e5b --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEBlend.cpp @@ -0,0 +1,87 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEBlend.h" + +namespace WebCore { + +SVGFEBlend::SVGFEBlend(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_mode(SVG_FEBLEND_MODE_UNKNOWN) +{ +} + +String SVGFEBlend::in2() const +{ + return m_in2; +} + +void SVGFEBlend::setIn2(const String& in2) +{ + m_in2 = in2; +} + +SVGBlendModeType SVGFEBlend::blendMode() const +{ + return m_mode; +} + +void SVGFEBlend::setBlendMode(SVGBlendModeType mode) +{ + m_mode = mode; +} + +static TextStream& operator<<(TextStream& ts, SVGBlendModeType t) +{ + switch (t) + { + case SVG_FEBLEND_MODE_UNKNOWN: + ts << "UNKNOWN"; break; + case SVG_FEBLEND_MODE_NORMAL: + ts << "NORMAL"; break; + case SVG_FEBLEND_MODE_MULTIPLY: + ts << "MULTIPLY"; break; + case SVG_FEBLEND_MODE_SCREEN: + ts << "SCREEN"; break; + case SVG_FEBLEND_MODE_DARKEN: + ts << "DARKEN"; break; + case SVG_FEBLEND_MODE_LIGHTEN: + ts << "LIGHTEN"; break; + } + return ts; +} + +TextStream& SVGFEBlend::externalRepresentation(TextStream& ts) const +{ + ts << "[type=BLEND] "; + SVGFilterEffect::externalRepresentation(ts); + if (!m_in2.isEmpty()) + ts << " [in2=\"" << m_in2 << "\"]"; + ts << " [blend mode=" << m_mode << "]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEBlend.h b/WebCore/svg/graphics/filters/SVGFEBlend.h new file mode 100644 index 0000000..f8063f7 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEBlend.h @@ -0,0 +1,64 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEBlend_h +#define SVGFEBlend_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" + +namespace WebCore { + +enum SVGBlendModeType { + SVG_FEBLEND_MODE_UNKNOWN = 0, + SVG_FEBLEND_MODE_NORMAL = 1, + SVG_FEBLEND_MODE_MULTIPLY = 2, + SVG_FEBLEND_MODE_SCREEN = 3, + SVG_FEBLEND_MODE_DARKEN = 4, + SVG_FEBLEND_MODE_LIGHTEN = 5 +}; + +class SVGFEBlend : public SVGFilterEffect { +public: + SVGFEBlend(SVGResourceFilter*); + + String in2() const; + void setIn2(const String&); + + SVGBlendModeType blendMode() const; + void setBlendMode(SVGBlendModeType); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + +private: + SVGBlendModeType m_mode; + String m_in2; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEBlend_h diff --git a/WebCore/svg/graphics/filters/SVGFEColorMatrix.cpp b/WebCore/svg/graphics/filters/SVGFEColorMatrix.cpp new file mode 100644 index 0000000..8eb2572 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEColorMatrix.cpp @@ -0,0 +1,84 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEColorMatrix.h" + +namespace WebCore { + +SVGFEColorMatrix::SVGFEColorMatrix(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_type(SVG_FECOLORMATRIX_TYPE_UNKNOWN) +{ +} + +SVGColorMatrixType SVGFEColorMatrix::type() const +{ + return m_type; +} + +void SVGFEColorMatrix::setType(SVGColorMatrixType type) +{ + m_type = type; +} + +const Vector<float>& SVGFEColorMatrix::values() const +{ + return m_values; +} + +void SVGFEColorMatrix::setValues(const Vector<float> &values) +{ + m_values = values; +} + +static TextStream& operator<<(TextStream& ts, SVGColorMatrixType t) +{ + switch (t) + { + case SVG_FECOLORMATRIX_TYPE_UNKNOWN: + ts << "UNKNOWN"; break; + case SVG_FECOLORMATRIX_TYPE_MATRIX: + ts << "CMT_MATRIX"; break; + case SVG_FECOLORMATRIX_TYPE_SATURATE: + ts << "CMT_SATURATE"; break; + case SVG_FECOLORMATRIX_TYPE_HUEROTATE: + ts << "HUE-ROTATE"; break; + case SVG_FECOLORMATRIX_TYPE_LUMINANCETOALPHA: + ts << "LUMINANCE-TO-ALPHA"; break; + } + return ts; +} + +TextStream& SVGFEColorMatrix::externalRepresentation(TextStream& ts) const +{ + ts << "[type=COLOR-MATRIX] "; + SVGFilterEffect::externalRepresentation(ts); + ts << " [color matrix type=" << type() << "]" + << " [values=" << values() << "]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEColorMatrix.h b/WebCore/svg/graphics/filters/SVGFEColorMatrix.h new file mode 100644 index 0000000..0d4eb23 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEColorMatrix.h @@ -0,0 +1,64 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEColorMatrix_h +#define SVGFEColorMatrix_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" +#include "SVGRenderTreeAsText.h" + +namespace WebCore { + +enum SVGColorMatrixType { + SVG_FECOLORMATRIX_TYPE_UNKNOWN = 0, + SVG_FECOLORMATRIX_TYPE_MATRIX = 1, + SVG_FECOLORMATRIX_TYPE_SATURATE = 2, + SVG_FECOLORMATRIX_TYPE_HUEROTATE = 3, + SVG_FECOLORMATRIX_TYPE_LUMINANCETOALPHA = 4 +}; + +class SVGFEColorMatrix : public SVGFilterEffect { +public: + SVGFEColorMatrix(SVGResourceFilter*); + + SVGColorMatrixType type() const; + void setType(SVGColorMatrixType); + + const Vector<float>& values() const; + void setValues(const Vector<float>&); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + +private: + SVGColorMatrixType m_type; + Vector<float> m_values; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEColorMatrix_h diff --git a/WebCore/svg/graphics/filters/SVGFEComponentTransfer.cpp b/WebCore/svg/graphics/filters/SVGFEComponentTransfer.cpp new file mode 100644 index 0000000..d937c63 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEComponentTransfer.cpp @@ -0,0 +1,141 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEComponentTransfer.h" + +namespace WebCore { + +SVGFEComponentTransfer::SVGFEComponentTransfer(SVGResourceFilter* filter) + : SVGFilterEffect(filter) +{ +} + +SVGComponentTransferFunction SVGFEComponentTransfer::redFunction() const +{ + return m_redFunc; +} + +void SVGFEComponentTransfer::setRedFunction(const SVGComponentTransferFunction& func) +{ + m_redFunc = func; +} + +SVGComponentTransferFunction SVGFEComponentTransfer::greenFunction() const +{ + return m_greenFunc; +} + +void SVGFEComponentTransfer::setGreenFunction(const SVGComponentTransferFunction& func) +{ + m_greenFunc = func; +} + +SVGComponentTransferFunction SVGFEComponentTransfer::blueFunction() const +{ + return m_blueFunc; +} + +void SVGFEComponentTransfer::setBlueFunction(const SVGComponentTransferFunction& func) +{ + m_blueFunc = func; +} + +SVGComponentTransferFunction SVGFEComponentTransfer::alphaFunction() const +{ + return m_alphaFunc; +} + +void SVGFEComponentTransfer::setAlphaFunction(const SVGComponentTransferFunction& func) +{ + m_alphaFunc = func; +} + +static TextStream& operator<<(TextStream& ts, SVGComponentTransferType t) +{ + switch (t) + { + case SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN: + ts << "UNKNOWN"; break; + case SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY: + ts << "IDENTITY"; break; + case SVG_FECOMPONENTTRANSFER_TYPE_TABLE: + ts << "TABLE"; break; + case SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE: + ts << "DISCRETE"; break; + case SVG_FECOMPONENTTRANSFER_TYPE_LINEAR: + ts << "LINEAR"; break; + case SVG_FECOMPONENTTRANSFER_TYPE_GAMMA: + ts << "GAMMA"; break; + } + return ts; +} + +static TextStream& operator<<(TextStream& ts, const SVGComponentTransferFunction &func) +{ + ts << "[type=" << func.type << "]"; + switch (func.type) { + case SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN: + case SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY: + break; + case SVG_FECOMPONENTTRANSFER_TYPE_TABLE: + case SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE: + { + ts << " [table values="; + Vector<float>::const_iterator itr=func.tableValues.begin(); + if (itr != func.tableValues.end()) { + ts << *itr++; + for (; itr!=func.tableValues.end(); itr++) { + ts << " " << *itr; + } + } + ts << "]"; + break; + } + case SVG_FECOMPONENTTRANSFER_TYPE_LINEAR: + ts << " [slope=" << func.slope << "]" + << " [intercept=" << func.intercept << "]"; + break; + case SVG_FECOMPONENTTRANSFER_TYPE_GAMMA: + ts << " [amplitude=" << func.amplitude << "]" + << " [exponent=" << func.exponent << "]" + << " [offset=" << func.offset << "]"; + break; + } + return ts; +} + +TextStream& SVGFEComponentTransfer::externalRepresentation(TextStream& ts) const +{ + ts << "[type=COMPONENT-TRANSFER] "; + SVGFilterEffect::externalRepresentation(ts); + ts << " [red func=" << redFunction() << "]" + << " [green func=" << greenFunction() << "]" + << " [blue func=" << blueFunction() << "]" + << " [alpha func=" << alphaFunction() << "]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEComponentTransfer.h b/WebCore/svg/graphics/filters/SVGFEComponentTransfer.h new file mode 100644 index 0000000..32d5e14 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEComponentTransfer.h @@ -0,0 +1,110 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEComponentTransfer_h +#define SVGFEComponentTransfer_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include <wtf/Vector.h> + +#include "SVGFilterEffect.h" +#include "SVGFEDisplacementMap.h" + +#if PLATFORM(CI) +#ifdef __OBJC__ +@class CIImage; +@class CIFilter; +#else +class CIImage; +class CIFilter; +#endif +#endif + +namespace WebCore { + +enum SVGComponentTransferType { + SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN = 0, + SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY = 1, + SVG_FECOMPONENTTRANSFER_TYPE_TABLE = 2, + SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE = 3, + SVG_FECOMPONENTTRANSFER_TYPE_LINEAR = 4, + SVG_FECOMPONENTTRANSFER_TYPE_GAMMA = 5 +}; + +struct SVGComponentTransferFunction { + SVGComponentTransferFunction() + : type(SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN) + , slope(0.0f) + , intercept(0.0f) + , amplitude(0.0f) + , exponent(0.0f) + , offset(0.0f) + { + } + + SVGComponentTransferType type; + + float slope; + float intercept; + float amplitude; + float exponent; + float offset; + + Vector<float> tableValues; +}; + +class SVGFEComponentTransfer : public SVGFilterEffect { +public: + SVGFEComponentTransfer(SVGResourceFilter*); + + SVGComponentTransferFunction redFunction() const; + void setRedFunction(const SVGComponentTransferFunction&); + + SVGComponentTransferFunction greenFunction() const; + void setGreenFunction(const SVGComponentTransferFunction&); + + SVGComponentTransferFunction blueFunction() const; + void setBlueFunction(const SVGComponentTransferFunction&); + + SVGComponentTransferFunction alphaFunction() const; + void setAlphaFunction(const SVGComponentTransferFunction&); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; + +private: + CIFilter* getFunctionFilter(SVGChannelSelectorType, CIImage* inputImage) const; +#endif + +private: + SVGComponentTransferFunction m_redFunc; + SVGComponentTransferFunction m_greenFunc; + SVGComponentTransferFunction m_blueFunc; + SVGComponentTransferFunction m_alphaFunc; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEComponentTransfer_h diff --git a/WebCore/svg/graphics/filters/SVGFEComposite.cpp b/WebCore/svg/graphics/filters/SVGFEComposite.cpp new file mode 100644 index 0000000..0be84f9 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEComposite.cpp @@ -0,0 +1,111 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEComposite.h" + +namespace WebCore { + +SVGFEComposite::SVGFEComposite(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_operation(SVG_FECOMPOSITE_OPERATOR_UNKNOWN) + , m_k1(0.0f) + , m_k2(0.0f) + , m_k3(0.0f) + , m_k4(0.0f) +{ +} + +String SVGFEComposite::in2() const +{ + return m_in2; +} + +void SVGFEComposite::setIn2(const String& in2) +{ + m_in2 = in2; +} + +SVGCompositeOperationType SVGFEComposite::operation() const +{ + return m_operation; +} + +void SVGFEComposite::setOperation(SVGCompositeOperationType oper) +{ + m_operation = oper; +} + +float SVGFEComposite::k1() const +{ + return m_k1; +} + +void SVGFEComposite::setK1(float k1) +{ + m_k1 = k1; +} + +float SVGFEComposite::k2() const +{ + return m_k2; +} + +void SVGFEComposite::setK2(float k2) +{ + m_k2 = k2; +} + +float SVGFEComposite::k3() const +{ + return m_k3; +} + +void SVGFEComposite::setK3(float k3) +{ + m_k3 = k3; +} + +float SVGFEComposite::k4() const +{ + return m_k4; +} + +void SVGFEComposite::setK4(float k4) +{ + m_k4 = k4; +} + +TextStream& SVGFEComposite::externalRepresentation(TextStream& ts) const +{ + ts << "[type=COMPOSITE] "; + SVGFilterEffect::externalRepresentation(ts); + if (!in2().isEmpty()) + ts << " [in2=\"" << in2() << "\"]"; + ts << " [k1=" << k1() << " k2=" << k2() << " k3=" << k3() << " k4=" << k4() << "]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEComposite.h b/WebCore/svg/graphics/filters/SVGFEComposite.h new file mode 100644 index 0000000..7a18047 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEComposite.h @@ -0,0 +1,81 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEComposite_h +#define SVGFEComposite_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" + +namespace WebCore { + +enum SVGCompositeOperationType { + SVG_FECOMPOSITE_OPERATOR_UNKNOWN = 0, + SVG_FECOMPOSITE_OPERATOR_OVER = 1, + SVG_FECOMPOSITE_OPERATOR_IN = 2, + SVG_FECOMPOSITE_OPERATOR_OUT = 3, + SVG_FECOMPOSITE_OPERATOR_ATOP = 4, + SVG_FECOMPOSITE_OPERATOR_XOR = 5, + SVG_FECOMPOSITE_OPERATOR_ARITHMETIC = 6 +}; + +class SVGFEComposite : public SVGFilterEffect { +public: + SVGFEComposite(SVGResourceFilter*); + + String in2() const; + void setIn2(const String&); + + SVGCompositeOperationType operation() const; + void setOperation(SVGCompositeOperationType); + + float k1() const; + void setK1(float); + + float k2() const; + void setK2(float); + + float k3() const; + void setK3(float); + + float k4() const; + void setK4(float); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + +private: + SVGCompositeOperationType m_operation; + float m_k1; + float m_k2; + float m_k3; + float m_k4; + String m_in2; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEComposite_h diff --git a/WebCore/svg/graphics/filters/SVGFEConvolveMatrix.cpp b/WebCore/svg/graphics/filters/SVGFEConvolveMatrix.cpp new file mode 100644 index 0000000..af2b693 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEConvolveMatrix.cpp @@ -0,0 +1,155 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGRenderTreeAsText.h" +#include "SVGFEConvolveMatrix.h" + +namespace WebCore { + +SVGFEConvolveMatrix::SVGFEConvolveMatrix(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_kernelSize() + , m_divisor(0.0f) + , m_bias(0.0f) + , m_targetOffset() + , m_edgeMode(SVG_EDGEMODE_UNKNOWN) + , m_kernelUnitLength() + , m_preserveAlpha(false) +{ +} + +FloatSize SVGFEConvolveMatrix::kernelSize() const +{ + return m_kernelSize; +} + +void SVGFEConvolveMatrix::setKernelSize(FloatSize kernelSize) +{ + m_kernelSize = kernelSize; +} + +const Vector<float>& SVGFEConvolveMatrix::kernel() const +{ + return m_kernelMatrix; +} + +void SVGFEConvolveMatrix::setKernel(const Vector<float>& kernel) +{ + m_kernelMatrix = kernel; +} + +float SVGFEConvolveMatrix::divisor() const +{ + return m_divisor; +} + +void SVGFEConvolveMatrix::setDivisor(float divisor) +{ + m_divisor = divisor; +} + +float SVGFEConvolveMatrix::bias() const +{ + return m_bias; +} + +void SVGFEConvolveMatrix::setBias(float bias) +{ + m_bias = bias; +} + +FloatSize SVGFEConvolveMatrix::targetOffset() const +{ + return m_targetOffset; +} + +void SVGFEConvolveMatrix::setTargetOffset(FloatSize targetOffset) +{ + m_targetOffset = targetOffset; +} + +SVGEdgeModeType SVGFEConvolveMatrix::edgeMode() const +{ + return m_edgeMode; +} + +void SVGFEConvolveMatrix::setEdgeMode(SVGEdgeModeType edgeMode) +{ + m_edgeMode = edgeMode; +} + +FloatPoint SVGFEConvolveMatrix::kernelUnitLength() const +{ + return m_kernelUnitLength; +} + +void SVGFEConvolveMatrix::setKernelUnitLength(FloatPoint kernelUnitLength) +{ + m_kernelUnitLength = kernelUnitLength; +} + +bool SVGFEConvolveMatrix::preserveAlpha() const +{ + return m_preserveAlpha; +} + +void SVGFEConvolveMatrix::setPreserveAlpha(bool preserveAlpha) +{ + m_preserveAlpha = preserveAlpha; +} + +static TextStream& operator<<(TextStream& ts, SVGEdgeModeType t) +{ + switch (t) + { + case SVG_EDGEMODE_UNKNOWN: + ts << "UNKNOWN";break; + case SVG_EDGEMODE_DUPLICATE: + ts << "DUPLICATE";break; + case SVG_EDGEMODE_WRAP: + ts << "WRAP"; break; + case SVG_EDGEMODE_NONE: + ts << "NONE"; break; + } + return ts; +} + +TextStream& SVGFEConvolveMatrix::externalRepresentation(TextStream& ts) const +{ + ts << "[type=CONVOLVE-MATRIX] "; + SVGFilterEffect::externalRepresentation(ts); + ts << " [order " << m_kernelSize << "]" + << " [kernel matrix=" << m_kernelMatrix << "]" + << " [divisor=" << m_divisor << "]" + << " [bias=" << m_bias << "]" + << " [target " << m_targetOffset << "]" + << " [edge mode=" << m_edgeMode << "]" + << " [kernel unit length " << m_kernelUnitLength << "]" + << " [preserve alpha=" << m_preserveAlpha << "]"; + return ts; +} + +}; // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEConvolveMatrix.h b/WebCore/svg/graphics/filters/SVGFEConvolveMatrix.h new file mode 100644 index 0000000..b9744fa --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEConvolveMatrix.h @@ -0,0 +1,82 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEConvolveMatrix_h +#define SVGFEConvolveMatrix_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" + +namespace WebCore { + +enum SVGEdgeModeType { + SVG_EDGEMODE_UNKNOWN = 0, + SVG_EDGEMODE_DUPLICATE = 1, + SVG_EDGEMODE_WRAP = 2, + SVG_EDGEMODE_NONE = 3 +}; + +class SVGFEConvolveMatrix : public SVGFilterEffect { +public: + SVGFEConvolveMatrix(SVGResourceFilter*); + + FloatSize kernelSize() const; + void setKernelSize(FloatSize); + + const Vector<float>& kernel() const; + void setKernel(const Vector<float>&); + + float divisor() const; + void setDivisor(float); + + float bias() const; + void setBias(float); + + FloatSize targetOffset() const; + void setTargetOffset(FloatSize); + + SVGEdgeModeType edgeMode() const; + void setEdgeMode(SVGEdgeModeType); + + FloatPoint kernelUnitLength() const; + void setKernelUnitLength(FloatPoint); + + bool preserveAlpha() const; + void setPreserveAlpha(bool); + + virtual TextStream& externalRepresentation(TextStream&) const; + +private: + FloatSize m_kernelSize; + float m_divisor; + float m_bias; + FloatSize m_targetOffset; + SVGEdgeModeType m_edgeMode; + FloatPoint m_kernelUnitLength; + bool m_preserveAlpha; + Vector<float> m_kernelMatrix; // maybe should be a real matrix? +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEConvolveMatrix_h diff --git a/WebCore/svg/graphics/filters/SVGFEDiffuseLighting.cpp b/WebCore/svg/graphics/filters/SVGFEDiffuseLighting.cpp new file mode 100644 index 0000000..937dfb9 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEDiffuseLighting.cpp @@ -0,0 +1,121 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGLightSource.h" +#include "SVGFEDiffuseLighting.h" + +namespace WebCore { + +SVGFEDiffuseLighting::SVGFEDiffuseLighting(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_lightingColor() + , m_surfaceScale(0.0f) + , m_diffuseConstant(0.0f) + , m_kernelUnitLengthX(0.0f) + , m_kernelUnitLengthY(0.0f) + , m_lightSource(0) +{ +} + +SVGFEDiffuseLighting::~SVGFEDiffuseLighting() +{ + delete m_lightSource; +} + +Color SVGFEDiffuseLighting::lightingColor() const +{ + return m_lightingColor; +} + +void SVGFEDiffuseLighting::setLightingColor(const Color& lightingColor) +{ + m_lightingColor = lightingColor; +} + +float SVGFEDiffuseLighting::surfaceScale() const +{ + return m_surfaceScale; +} + +void SVGFEDiffuseLighting::setSurfaceScale(float surfaceScale) +{ + m_surfaceScale = surfaceScale; +} + +float SVGFEDiffuseLighting::diffuseConstant() const +{ + return m_diffuseConstant; +} + +void SVGFEDiffuseLighting::setDiffuseConstant(float diffuseConstant) +{ + m_diffuseConstant = diffuseConstant; +} + +float SVGFEDiffuseLighting::kernelUnitLengthX() const +{ + return m_kernelUnitLengthX; +} + +void SVGFEDiffuseLighting::setKernelUnitLengthX(float kernelUnitLengthX) +{ + m_kernelUnitLengthX = kernelUnitLengthX; +} + +float SVGFEDiffuseLighting::kernelUnitLengthY() const +{ + return m_kernelUnitLengthY; +} + +void SVGFEDiffuseLighting::setKernelUnitLengthY(float kernelUnitLengthY) +{ + m_kernelUnitLengthY = kernelUnitLengthY; +} + +const SVGLightSource* SVGFEDiffuseLighting::lightSource() const +{ + return m_lightSource; +} + +void SVGFEDiffuseLighting::setLightSource(SVGLightSource* lightSource) +{ + if (m_lightSource != lightSource) { + delete m_lightSource; + m_lightSource = lightSource; + } +} + +TextStream& SVGFEDiffuseLighting::externalRepresentation(TextStream& ts) const +{ + ts << "[type=DIFFUSE-LIGHTING] "; + SVGFilterEffect::externalRepresentation(ts); + ts << " [surface scale=" << m_surfaceScale << "]" + << " [diffuse constant=" << m_diffuseConstant << "]" + << " [kernel unit length " << m_kernelUnitLengthX << ", " << m_kernelUnitLengthY << "]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEDiffuseLighting.h b/WebCore/svg/graphics/filters/SVGFEDiffuseLighting.h new file mode 100644 index 0000000..a2ed775 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEDiffuseLighting.h @@ -0,0 +1,75 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEDiffuseLighting_h +#define SVGFEDiffuseLighting_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "Color.h" +#include "SVGFilterEffect.h" + +namespace WebCore { + +class SVGLightSource; + +class SVGFEDiffuseLighting : public SVGFilterEffect { +public: + SVGFEDiffuseLighting(SVGResourceFilter*); + virtual ~SVGFEDiffuseLighting(); + + Color lightingColor() const; + void setLightingColor(const Color&); + + float surfaceScale() const; + void setSurfaceScale(float); + + float diffuseConstant() const; + void setDiffuseConstant(float); + + float kernelUnitLengthX() const; + void setKernelUnitLengthX(float); + + float kernelUnitLengthY() const; + void setKernelUnitLengthY(float); + + const SVGLightSource* lightSource() const; + void setLightSource(SVGLightSource*); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + +private: + Color m_lightingColor; + float m_surfaceScale; + float m_diffuseConstant; + float m_kernelUnitLengthX; + float m_kernelUnitLengthY; + SVGLightSource* m_lightSource; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEDiffuseLighting_h diff --git a/WebCore/svg/graphics/filters/SVGFEDisplacementMap.cpp b/WebCore/svg/graphics/filters/SVGFEDisplacementMap.cpp new file mode 100644 index 0000000..39b012b --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEDisplacementMap.cpp @@ -0,0 +1,110 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGRenderTreeAsText.h" +#include "SVGFEDisplacementMap.h" + +namespace WebCore { + +SVGFEDisplacementMap::SVGFEDisplacementMap(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_xChannelSelector(SVG_CHANNEL_UNKNOWN) + , m_yChannelSelector(SVG_CHANNEL_UNKNOWN) + , m_scale(0) +{ +} + +String SVGFEDisplacementMap::in2() const +{ + return m_in2; +} + +void SVGFEDisplacementMap::setIn2(const String &in2) +{ + m_in2 = in2; +} + +SVGChannelSelectorType SVGFEDisplacementMap::xChannelSelector() const +{ + return m_xChannelSelector; +} + +void SVGFEDisplacementMap::setXChannelSelector(const SVGChannelSelectorType xChannelSelector) +{ + m_xChannelSelector = xChannelSelector; +} + +SVGChannelSelectorType SVGFEDisplacementMap::yChannelSelector() const +{ + return m_yChannelSelector; +} + +void SVGFEDisplacementMap::setYChannelSelector(const SVGChannelSelectorType yChannelSelector) +{ + m_yChannelSelector = yChannelSelector; +} + +float SVGFEDisplacementMap::scale() const +{ + return m_scale; +} + +void SVGFEDisplacementMap::setScale(float scale) +{ + m_scale = scale; +} + +static TextStream& operator<<(TextStream& ts, SVGChannelSelectorType t) +{ + switch (t) + { + case SVG_CHANNEL_UNKNOWN: + ts << "UNKNOWN"; break; + case SVG_CHANNEL_R: + ts << "RED"; break; + case SVG_CHANNEL_G: + ts << "GREEN"; break; + case SVG_CHANNEL_B: + ts << "BLUE"; break; + case SVG_CHANNEL_A: + ts << "ALPHA"; break; + } + return ts; +} + +TextStream& SVGFEDisplacementMap::externalRepresentation(TextStream& ts) const +{ + ts << "[type=DISPLACEMENT-MAP] "; + SVGFilterEffect::externalRepresentation(ts); + if (!in2().isEmpty()) + ts << " [in2=" << in2() << "]"; + ts << " [scale=" << m_scale << "]" + << " [x channel selector=" << m_xChannelSelector << "]" + << " [y channel selector=" << m_yChannelSelector << "]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEDisplacementMap.h b/WebCore/svg/graphics/filters/SVGFEDisplacementMap.h new file mode 100644 index 0000000..bc45728 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEDisplacementMap.h @@ -0,0 +1,71 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEDisplacementMap_h +#define SVGFEDisplacementMap_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" + +namespace WebCore { + +enum SVGChannelSelectorType { + SVG_CHANNEL_UNKNOWN = 0, + SVG_CHANNEL_R = 1, + SVG_CHANNEL_G = 2, + SVG_CHANNEL_B = 3, + SVG_CHANNEL_A = 4 +}; + +class SVGFEDisplacementMap : public SVGFilterEffect { +public: + SVGFEDisplacementMap(SVGResourceFilter*); + + String in2() const; + void setIn2(const String&); + + SVGChannelSelectorType xChannelSelector() const; + void setXChannelSelector(const SVGChannelSelectorType); + + SVGChannelSelectorType yChannelSelector() const; + void setYChannelSelector(const SVGChannelSelectorType); + + float scale() const; + void setScale(float scale); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + +private: + SVGChannelSelectorType m_xChannelSelector; + SVGChannelSelectorType m_yChannelSelector; + float m_scale; + String m_in2; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEDisplacementMap_h diff --git a/WebCore/svg/graphics/filters/SVGFEFlood.cpp b/WebCore/svg/graphics/filters/SVGFEFlood.cpp new file mode 100644 index 0000000..2baeb2e --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEFlood.cpp @@ -0,0 +1,68 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGRenderTreeAsText.h" +#include "SVGFEFlood.h" + +namespace WebCore { + +SVGFEFlood::SVGFEFlood(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_floodColor() + , m_floodOpacity(0.0f) +{ +} + +Color SVGFEFlood::floodColor() const +{ + return m_floodColor; +} + +void SVGFEFlood::setFloodColor(const Color& color) +{ + m_floodColor = color; +} + +float SVGFEFlood::floodOpacity() const +{ + return m_floodOpacity; +} + +void SVGFEFlood::setFloodOpacity(float floodOpacity) +{ + m_floodOpacity = floodOpacity; +} + +TextStream& SVGFEFlood::externalRepresentation(TextStream& ts) const +{ + ts << "[type=FLOOD] "; + SVGFilterEffect::externalRepresentation(ts); + ts << " [color=" << floodColor() << "]" + << " [opacity=" << floodOpacity() << "]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEFlood.h b/WebCore/svg/graphics/filters/SVGFEFlood.h new file mode 100644 index 0000000..4cadf9a --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEFlood.h @@ -0,0 +1,56 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEFlood_h +#define SVGFEFlood_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "Color.h" +#include "SVGFilterEffect.h" + +namespace WebCore { + +class SVGFEFlood : public SVGFilterEffect { +public: + SVGFEFlood(SVGResourceFilter*); + + Color floodColor() const; + void setFloodColor(const Color &); + + float floodOpacity() const; + void setFloodOpacity(float); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + +private: + Color m_floodColor; + float m_floodOpacity; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEFlood_h diff --git a/WebCore/svg/graphics/filters/SVGFEGaussianBlur.cpp b/WebCore/svg/graphics/filters/SVGFEGaussianBlur.cpp new file mode 100644 index 0000000..a893f9d --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEGaussianBlur.cpp @@ -0,0 +1,66 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEGaussianBlur.h" + +namespace WebCore { + +SVGFEGaussianBlur::SVGFEGaussianBlur(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_x(0.0f) + , m_y(0.0f) +{ +} + +float SVGFEGaussianBlur::stdDeviationX() const +{ + return m_x; +} + +void SVGFEGaussianBlur::setStdDeviationX(float x) +{ + m_x = x; +} + +float SVGFEGaussianBlur::stdDeviationY() const +{ + return m_y; +} + +void SVGFEGaussianBlur::setStdDeviationY(float y) +{ + m_y = y; +} + +TextStream& SVGFEGaussianBlur::externalRepresentation(TextStream& ts) const +{ + ts << "[type=GAUSSIAN-BLUR] "; + SVGFilterEffect::externalRepresentation(ts); + ts << " [std dev. x=" << stdDeviationX() << " y=" << stdDeviationY() << "]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEGaussianBlur.h b/WebCore/svg/graphics/filters/SVGFEGaussianBlur.h new file mode 100644 index 0000000..28cb9e0 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEGaussianBlur.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEGaussianBlur_h +#define SVGFEGaussianBlur_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" + +namespace WebCore { + +class SVGFEGaussianBlur : public SVGFilterEffect { +public: + SVGFEGaussianBlur(SVGResourceFilter*); + + float stdDeviationX() const; + void setStdDeviationX(float); + + float stdDeviationY() const; + void setStdDeviationY(float); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + +private: + float m_x; + float m_y; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEGaussianBlur_h diff --git a/WebCore/svg/graphics/filters/SVGFEImage.cpp b/WebCore/svg/graphics/filters/SVGFEImage.cpp new file mode 100644 index 0000000..d7520be --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEImage.cpp @@ -0,0 +1,79 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEImage.h" + +#include "SVGResourceFilter.h" + +namespace WebCore { + +SVGFEImage::SVGFEImage(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_cachedImage(0) +{ +} + +SVGFEImage::~SVGFEImage() +{ + if (m_cachedImage) + m_cachedImage->deref(this); +} + +CachedImage* SVGFEImage::cachedImage() const +{ + return m_cachedImage; +} + +void SVGFEImage::setCachedImage(CachedImage* image) +{ + if (m_cachedImage == image) + return; + + if (m_cachedImage) + m_cachedImage->deref(this); + + m_cachedImage = image; + + if (m_cachedImage) + m_cachedImage->ref(this); +} + +TextStream& SVGFEImage::externalRepresentation(TextStream& ts) const +{ + ts << "[type=IMAGE] "; + SVGFilterEffect::externalRepresentation(ts); + // FIXME: should this dump also object returned by SVGFEImage::image() ? + return ts; + +} + +void SVGFEImage::imageChanged(CachedImage*) +{ + if (SVGResourceFilter* filterResource = filter()) + filterResource->invalidate(); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEImage.h b/WebCore/svg/graphics/filters/SVGFEImage.h new file mode 100644 index 0000000..8245d10 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEImage.h @@ -0,0 +1,59 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEImage_h +#define SVGFEImage_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "CachedImage.h" +#include "CachedResourceClient.h" +#include "SVGFilterEffect.h" + +namespace WebCore { + +class SVGFEImage : public SVGFilterEffect + , public CachedResourceClient { +public: + SVGFEImage(SVGResourceFilter*); + virtual ~SVGFEImage(); + + // FIXME: We need to support <svg> (RenderObject*) as well as image data. + + CachedImage* cachedImage() const; + void setCachedImage(CachedImage*); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + + virtual void imageChanged(CachedImage*); + +private: + CachedImage* m_cachedImage; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEImage_h diff --git a/WebCore/svg/graphics/filters/SVGFEMerge.cpp b/WebCore/svg/graphics/filters/SVGFEMerge.cpp new file mode 100644 index 0000000..ff92eaa --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEMerge.cpp @@ -0,0 +1,58 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEMerge.h" + +namespace WebCore { + +const Vector<String>& SVGFEMerge::mergeInputs() const +{ + return m_mergeInputs; +} + +void SVGFEMerge::setMergeInputs(const Vector<String>& mergeInputs) +{ + m_mergeInputs = mergeInputs; +} + +TextStream& SVGFEMerge::externalRepresentation(TextStream& ts) const +{ + ts << "[type=MERGE] "; + SVGFilterEffect::externalRepresentation(ts); + ts << "[merge inputs=["; + unsigned x = 0; + unsigned size = m_mergeInputs.size(); + while (x < size) { + ts << m_mergeInputs[x]; + x++; + if (x < m_mergeInputs.size()) + ts << ", "; + } + ts << "]]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEMerge.h b/WebCore/svg/graphics/filters/SVGFEMerge.h new file mode 100644 index 0000000..9a0e867 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEMerge.h @@ -0,0 +1,51 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEMerge_h +#define SVGFEMerge_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" + +namespace WebCore { + +class SVGFEMerge : public SVGFilterEffect { +public: + SVGFEMerge(SVGResourceFilter* filter) : SVGFilterEffect(filter) { } + + const Vector<String>& mergeInputs() const; + void setMergeInputs(const Vector<String>& mergeInputs); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + +private: + Vector<String> m_mergeInputs; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEMerge_h diff --git a/WebCore/svg/graphics/filters/SVGFEMorphology.cpp b/WebCore/svg/graphics/filters/SVGFEMorphology.cpp new file mode 100644 index 0000000..06157ca --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEMorphology.cpp @@ -0,0 +1,92 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEMorphology.h" + +namespace WebCore { + +SVGFEMorphology::SVGFEMorphology(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_operator(SVG_MORPHOLOGY_OPERATOR_UNKNOWN) + , m_radiusX(0.0f) + , m_radiusY(0.0f) +{ +} + +SVGMorphologyOperatorType SVGFEMorphology::morphologyOperator() const +{ + return m_operator; +} + +void SVGFEMorphology::setMorphologyOperator(SVGMorphologyOperatorType _operator) +{ + m_operator = _operator; +} + +float SVGFEMorphology::radiusX() const +{ + return m_radiusX; +} + +void SVGFEMorphology::setRadiusX(float radiusX) +{ + m_radiusX = radiusX; +} + +float SVGFEMorphology::radiusY() const +{ + return m_radiusY; +} + +void SVGFEMorphology::setRadiusY(float radiusY) +{ + m_radiusY = radiusY; +} + +static TextStream& operator<<(TextStream& ts, SVGMorphologyOperatorType t) +{ + switch (t) + { + case SVG_MORPHOLOGY_OPERATOR_UNKNOWN: + ts << "UNKNOWN"; break; + case SVG_MORPHOLOGY_OPERATOR_ERODE: + ts << "ERODE"; break; + case SVG_MORPHOLOGY_OPERATOR_DIALATE: + ts << "DIALATE"; break; + } + return ts; +} + +TextStream& SVGFEMorphology::externalRepresentation(TextStream& ts) const +{ + ts << "[type=MORPHOLOGY-OPERATOR] "; + SVGFilterEffect::externalRepresentation(ts); + ts << " [operator type=" << morphologyOperator() << "]" + << " [radius x=" << radiusX() << " y=" << radiusY() << "]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEMorphology.h b/WebCore/svg/graphics/filters/SVGFEMorphology.h new file mode 100644 index 0000000..4ba7131 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEMorphology.h @@ -0,0 +1,61 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEMorphology_h +#define SVGFEMorphology_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" + +namespace WebCore { + +enum SVGMorphologyOperatorType { + SVG_MORPHOLOGY_OPERATOR_UNKNOWN = 0, + SVG_MORPHOLOGY_OPERATOR_ERODE = 1, + SVG_MORPHOLOGY_OPERATOR_DIALATE = 2 +}; + +class SVGFEMorphology : public SVGFilterEffect { +public: + SVGFEMorphology(SVGResourceFilter*); + + SVGMorphologyOperatorType morphologyOperator() const; + void setMorphologyOperator(SVGMorphologyOperatorType); + + float radiusX() const; + void setRadiusX(float); + + float radiusY() const; + void setRadiusY(float); + + virtual TextStream& externalRepresentation(TextStream&) const; + +private: + SVGMorphologyOperatorType m_operator; + float m_radiusX; + float m_radiusY; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEMorphology_h diff --git a/WebCore/svg/graphics/filters/SVGFEOffset.cpp b/WebCore/svg/graphics/filters/SVGFEOffset.cpp new file mode 100644 index 0000000..6ac0d17 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEOffset.cpp @@ -0,0 +1,65 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEOffset.h" + +namespace WebCore { + +SVGFEOffset::SVGFEOffset(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_dx(0.0f) + , m_dy(0.0f) +{ +} + +float SVGFEOffset::dx() const +{ + return m_dx; +} + +void SVGFEOffset::setDx(float dx) +{ + m_dx = dx; +} + +float SVGFEOffset::dy() const +{ + return m_dy; +} + +void SVGFEOffset::setDy(float dy) +{ + m_dy = dy; +} + +TextStream& SVGFEOffset::externalRepresentation(TextStream& ts) const +{ + ts << "[type=OFFSET] "; SVGFilterEffect::externalRepresentation(ts) + << " [dx=" << dx() << " dy=" << dy() << "]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFEOffset.h b/WebCore/svg/graphics/filters/SVGFEOffset.h new file mode 100644 index 0000000..05b427d --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFEOffset.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFEOffset_h +#define SVGFEOffset_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" + +namespace WebCore { + +class SVGFEOffset : public SVGFilterEffect { +public: + SVGFEOffset(SVGResourceFilter*); + + float dx() const; + void setDx(float); + + float dy() const; + void setDy(float); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + +private: + float m_dx; + float m_dy; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFEOffset_h diff --git a/WebCore/svg/graphics/filters/SVGFESpecularLighting.cpp b/WebCore/svg/graphics/filters/SVGFESpecularLighting.cpp new file mode 100644 index 0000000..a68c31d --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFESpecularLighting.cpp @@ -0,0 +1,131 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFESpecularLighting.h" + +namespace WebCore { + +SVGFESpecularLighting::SVGFESpecularLighting(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_lightingColor() + , m_surfaceScale(0.0f) + , m_specularConstant(0.0f) + , m_specularExponent(0.0f) + , m_kernelUnitLengthX(0.0f) + , m_kernelUnitLengthY(0.0f) + , m_lightSource(0) +{ +} + +SVGFESpecularLighting::~SVGFESpecularLighting() +{ + delete m_lightSource; +} + +Color SVGFESpecularLighting::lightingColor() const +{ + return m_lightingColor; +} + +void SVGFESpecularLighting::setLightingColor(const Color& lightingColor) +{ + m_lightingColor = lightingColor; +} + +float SVGFESpecularLighting::surfaceScale() const +{ + return m_surfaceScale; +} + +void SVGFESpecularLighting::setSurfaceScale(float surfaceScale) +{ + m_surfaceScale = surfaceScale; +} + +float SVGFESpecularLighting::specularConstant() const +{ + return m_specularConstant; +} + +void SVGFESpecularLighting::setSpecularConstant(float specularConstant) +{ + m_specularConstant = specularConstant; +} + +float SVGFESpecularLighting::specularExponent() const +{ + return m_specularExponent; +} + +void SVGFESpecularLighting::setSpecularExponent(float specularExponent) +{ + m_specularExponent = specularExponent; +} + +float SVGFESpecularLighting::kernelUnitLengthX() const +{ + return m_kernelUnitLengthX; +} + +void SVGFESpecularLighting::setKernelUnitLengthX(float kernelUnitLengthX) +{ + m_kernelUnitLengthX = kernelUnitLengthX; +} + +float SVGFESpecularLighting::kernelUnitLengthY() const +{ + return m_kernelUnitLengthY; +} + +void SVGFESpecularLighting::setKernelUnitLengthY(float kernelUnitLengthY) +{ + m_kernelUnitLengthY = kernelUnitLengthY; +} + +const SVGLightSource* SVGFESpecularLighting::lightSource() const +{ + return m_lightSource; +} + +void SVGFESpecularLighting::setLightSource(SVGLightSource* lightSource) +{ + if (m_lightSource != lightSource) { + delete m_lightSource; + m_lightSource = lightSource; + } +} + +TextStream& SVGFESpecularLighting::externalRepresentation(TextStream& ts) const +{ + ts << "[type=SPECULAR-LIGHTING] "; + SVGFilterEffect::externalRepresentation(ts); + ts << " [surface scale=" << m_surfaceScale << "]" + << " [specual constant=" << m_specularConstant << "]" + << " [specular exponent=" << m_specularExponent << "]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFESpecularLighting.h b/WebCore/svg/graphics/filters/SVGFESpecularLighting.h new file mode 100644 index 0000000..66e1561 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFESpecularLighting.h @@ -0,0 +1,78 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFESpecularLighting_h +#define SVGFESpecularLighting_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "Color.h" +#include "SVGLightSource.h" +#include "SVGFilterEffect.h" + +namespace WebCore { + +class SVGFESpecularLighting : public SVGFilterEffect { +public: + SVGFESpecularLighting(SVGResourceFilter*); + virtual ~SVGFESpecularLighting(); + + Color lightingColor() const; + void setLightingColor(const Color&); + + float surfaceScale() const; + void setSurfaceScale(float); + + float specularConstant() const; + void setSpecularConstant(float); + + float specularExponent() const; + void setSpecularExponent(float); + + float kernelUnitLengthX() const; + void setKernelUnitLengthX(float); + + float kernelUnitLengthY() const; + void setKernelUnitLengthY(float); + + const SVGLightSource* lightSource() const; + void setLightSource(SVGLightSource*); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + +private: + Color m_lightingColor; + float m_surfaceScale; + float m_specularConstant; + float m_specularExponent; + float m_kernelUnitLengthX; + float m_kernelUnitLengthY; + SVGLightSource* m_lightSource; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFESpecularLighting_h diff --git a/WebCore/svg/graphics/filters/SVGFETile.h b/WebCore/svg/graphics/filters/SVGFETile.h new file mode 100644 index 0000000..1c3922f --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFETile.h @@ -0,0 +1,44 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFETile_h +#define SVGFETile_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" + +namespace WebCore { + +class SVGFETile : public SVGFilterEffect +{ +public: + SVGFETile(SVGResourceFilter* filter) : SVGFilterEffect(filter) { } + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFETile_h diff --git a/WebCore/svg/graphics/filters/SVGFETurbulence.cpp b/WebCore/svg/graphics/filters/SVGFETurbulence.cpp new file mode 100644 index 0000000..9432a0a --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFETurbulence.cpp @@ -0,0 +1,129 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFETurbulence.h" + +namespace WebCore { + +SVGFETurbulence::SVGFETurbulence(SVGResourceFilter* filter) + : SVGFilterEffect(filter) + , m_baseFrequencyX(0.0f) + , m_baseFrequencyY(0.0f) + , m_numOctaves(0) + , m_seed(0) + , m_stitchTiles(false) + , m_type(SVG_TURBULENCE_TYPE_UNKNOWN) +{ +} + +SVGTurbulanceType SVGFETurbulence::type() const +{ + return m_type; +} + +void SVGFETurbulence::setType(SVGTurbulanceType type) +{ + m_type = type; +} + +float SVGFETurbulence::baseFrequencyY() const +{ + return m_baseFrequencyY; +} + +void SVGFETurbulence::setBaseFrequencyY(float baseFrequencyY) +{ + m_baseFrequencyY = baseFrequencyY; +} + +float SVGFETurbulence::baseFrequencyX() const +{ + return m_baseFrequencyX; +} + +void SVGFETurbulence::setBaseFrequencyX(float baseFrequencyX) +{ + m_baseFrequencyX = baseFrequencyX; +} + +float SVGFETurbulence::seed() const +{ + return m_seed; +} + +void SVGFETurbulence::setSeed(float seed) +{ + m_seed = seed; +} + +int SVGFETurbulence::numOctaves() const +{ + return m_numOctaves; +} + +void SVGFETurbulence::setNumOctaves(bool numOctaves) +{ + m_numOctaves = numOctaves; +} + +bool SVGFETurbulence::stitchTiles() const +{ + return m_stitchTiles; +} + +void SVGFETurbulence::setStitchTiles(bool stitch) +{ + m_stitchTiles = stitch; +} + +static TextStream& operator<<(TextStream& ts, SVGTurbulanceType t) +{ + switch (t) + { + case SVG_TURBULENCE_TYPE_UNKNOWN: + ts << "UNKNOWN"; break; + case SVG_TURBULENCE_TYPE_TURBULENCE: + ts << "TURBULANCE"; break; + case SVG_TURBULENCE_TYPE_FRACTALNOISE: + ts << "NOISE"; break; + } + return ts; +} + +TextStream& SVGFETurbulence::externalRepresentation(TextStream& ts) const +{ + ts << "[type=TURBULENCE] "; + SVGFilterEffect::externalRepresentation(ts); + ts << " [turbulence type=" << type() << "]" + << " [base frequency x=" << baseFrequencyX() << " y=" << baseFrequencyY() << "]" + << " [seed=" << seed() << "]" + << " [num octaves=" << numOctaves() << "]" + << " [stitch tiles=" << stitchTiles() << "]"; + return ts; + +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFETurbulence.h b/WebCore/svg/graphics/filters/SVGFETurbulence.h new file mode 100644 index 0000000..b871416 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFETurbulence.h @@ -0,0 +1,73 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFETurbulence_h +#define SVGFETurbulence_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" + +namespace WebCore { + +enum SVGTurbulanceType { + SVG_TURBULENCE_TYPE_UNKNOWN = 0, + SVG_TURBULENCE_TYPE_FRACTALNOISE = 1, + SVG_TURBULENCE_TYPE_TURBULENCE = 2 +}; + +class SVGFETurbulence : public SVGFilterEffect { +public: + SVGFETurbulence(SVGResourceFilter*); + + SVGTurbulanceType type() const; + void setType(SVGTurbulanceType); + + float baseFrequencyY() const; + void setBaseFrequencyY(float); + + float baseFrequencyX() const; + void setBaseFrequencyX(float); + + float seed() const; + void setSeed(float); + + int numOctaves() const; + void setNumOctaves(bool); + + bool stitchTiles() const; + void setStitchTiles(bool); + + virtual TextStream& externalRepresentation(TextStream&) const; + +private: + float m_baseFrequencyX; + float m_baseFrequencyY; + int m_numOctaves; + float m_seed; + bool m_stitchTiles; + SVGTurbulanceType m_type; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFETurbulence_h diff --git a/WebCore/svg/graphics/filters/SVGFilterEffect.cpp b/WebCore/svg/graphics/filters/SVGFilterEffect.cpp new file mode 100644 index 0000000..f8e246f --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFilterEffect.cpp @@ -0,0 +1,133 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFilterEffect.h" + +#include "SVGRenderTreeAsText.h" +#include "SVGResourceFilter.h" + +namespace WebCore { + +SVGFilterEffect::SVGFilterEffect(SVGResourceFilter* filter) + : m_filter(filter) + , m_xBBoxMode(false) + , m_yBBoxMode(false) + , m_widthBBoxMode(false) + , m_heightBBoxMode(false) +{ +} + +FloatRect SVGFilterEffect::primitiveBBoxForFilterBBox(const FloatRect& filterBBox, const FloatRect& itemBBox) const +{ + FloatRect subRegionBBox = subRegion(); + FloatRect useBBox = filterBBox; + + ASSERT(m_filter); + if (!m_filter) + return FloatRect(); + + if (m_filter->effectBoundingBoxMode()) { + if (!m_filter->filterBoundingBoxMode()) + useBBox = itemBBox; + + subRegionBBox = FloatRect(useBBox.x() + subRegionBBox.x() * useBBox.width(), + useBBox.y() + subRegionBBox.y() * useBBox.height(), + subRegionBBox.width() * useBBox.width(), + subRegionBBox.height() * useBBox.height()); + } else { + if (xBoundingBoxMode()) + subRegionBBox.setX(useBBox.x() + subRegionBBox.x() * useBBox.width()); + + if (yBoundingBoxMode()) + subRegionBBox.setY(useBBox.y() + subRegionBBox.y() * useBBox.height()); + + if (widthBoundingBoxMode()) + subRegionBBox.setWidth(subRegionBBox.width() * useBBox.width()); + + if (heightBoundingBoxMode()) + subRegionBBox.setHeight(subRegionBBox.height() * useBBox.height()); + } + + return subRegionBBox; +} + +FloatRect SVGFilterEffect::subRegion() const +{ + return m_subRegion; +} + +void SVGFilterEffect::setSubRegion(const FloatRect& subRegion) +{ + m_subRegion = subRegion; +} + +String SVGFilterEffect::in() const +{ + return m_in; +} + +void SVGFilterEffect::setIn(const String& in) +{ + m_in = in; +} + +String SVGFilterEffect::result() const +{ + return m_result; +} + +void SVGFilterEffect::setResult(const String& result) +{ + m_result = result; +} + +SVGResourceFilter* SVGFilterEffect::filter() const +{ + return m_filter; +} + +void SVGFilterEffect::setFilter(SVGResourceFilter* filter) +{ + m_filter = filter; +} + +TextStream& SVGFilterEffect::externalRepresentation(TextStream& ts) const +{ + if (!in().isEmpty()) + ts << "[in=\"" << in() << "\"]"; + if (!result().isEmpty()) + ts << " [result=\"" << result() << "\"]"; + if (!subRegion().isEmpty()) + ts << " [subregion=\"" << subRegion() << "\"]"; + return ts; +} + +TextStream& operator<<(TextStream& ts, const SVGFilterEffect& e) +{ + return e.externalRepresentation(ts); +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGFilterEffect.h b/WebCore/svg/graphics/filters/SVGFilterEffect.h new file mode 100644 index 0000000..f7128fc --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGFilterEffect.h @@ -0,0 +1,99 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGFilterEffect_h +#define SVGFilterEffect_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "FloatRect.h" +#include "PlatformString.h" + +#if PLATFORM(CI) +#ifdef __OBJC__ +@class CIFilter; +#else +class CIFilter; +#endif +#endif + +namespace WebCore { + +class SVGResourceFilter; +class TextStream; + +class SVGFilterEffect { +public: + SVGFilterEffect(SVGResourceFilter*); + virtual ~SVGFilterEffect() { } + + bool xBoundingBoxMode() const { return m_xBBoxMode; } + void setXBoundingBoxMode(bool bboxMode) { m_xBBoxMode = bboxMode; } + + bool yBoundingBoxMode() const { return m_yBBoxMode; } + void setYBoundingBoxMode(bool bboxMode) { m_yBBoxMode = bboxMode; } + + bool widthBoundingBoxMode() const { return m_widthBBoxMode; } + void setWidthBoundingBoxMode(bool bboxMode) { m_widthBBoxMode = bboxMode; } + + bool heightBoundingBoxMode() const { return m_heightBBoxMode; } + void setHeightBoundingBoxMode(bool bboxMode) { m_heightBBoxMode = bboxMode; } + + FloatRect primitiveBBoxForFilterBBox(const FloatRect& filterBBox, const FloatRect& itemBBox) const; + + FloatRect subRegion() const; + void setSubRegion(const FloatRect&); + + String in() const; + void setIn(const String&); + + String result() const; + void setResult(const String&); + + SVGResourceFilter* filter() const; + void setFilter(SVGResourceFilter*); + + virtual TextStream& externalRepresentation(TextStream&) const; + +#if PLATFORM(CI) + virtual CIFilter* getCIFilter(const FloatRect& bbox) const; +#endif + +private: + SVGResourceFilter* m_filter; + + bool m_xBBoxMode : 1; + bool m_yBBoxMode : 1; + bool m_widthBBoxMode : 1; + bool m_heightBBoxMode : 1; + + FloatRect m_subRegion; + + String m_in; + String m_result; +}; + +TextStream& operator<<(TextStream&, const SVGFilterEffect&); + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGFilterEffect_h diff --git a/WebCore/svg/graphics/filters/SVGLightSource.cpp b/WebCore/svg/graphics/filters/SVGLightSource.cpp new file mode 100644 index 0000000..517ed50 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGLightSource.cpp @@ -0,0 +1,65 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGPointLightSource.h" +#include "SVGRenderTreeAsText.h" +#include "SVGSpotLightSource.h" +#include "SVGDistantLightSource.h" + +namespace WebCore { + +static TextStream& operator<<(TextStream& ts, const FloatPoint3D& p) +{ + ts << "x=" << p.x() << " y=" << p.y() << " z=" << p.z(); + return ts; +} + +TextStream& SVGPointLightSource::externalRepresentation(TextStream& ts) const +{ + ts << "[type=POINT-LIGHT] "; + ts << "[position=\"" << position() << "\"]"; + return ts; +} + +TextStream& SVGSpotLightSource::externalRepresentation(TextStream& ts) const +{ + ts << "[type=SPOT-LIGHT] "; + ts << "[position=\"" << position() << "\"]"; + ts << "[direction=\"" << direction() << "\"]"; + ts << "[specularExponent=\"" << specularExponent() << "\"]"; + ts << "[limitingConeAngle=\"" << limitingConeAngle() << "\"]"; + return ts; +} + +TextStream& SVGDistantLightSource::externalRepresentation(TextStream& ts) const +{ + ts << "[type=DISTANT-LIGHT] "; + ts << "[azimuth=\"" << azimuth() << "\"]"; + ts << "[elevation=\"" << elevation() << "\"]"; + return ts; +} + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/SVGLightSource.h b/WebCore/svg/graphics/filters/SVGLightSource.h new file mode 100644 index 0000000..12cf3d0 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGLightSource.h @@ -0,0 +1,57 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGLightSource_h +#define SVGLightSource_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +namespace WebCore { + +enum SVGLightType { + LS_DISTANT, + LS_POINT, + LS_SPOT +}; + +class TextStream; + +class SVGLightSource { +public: + SVGLightSource(SVGLightType type) + : m_type(type) + { } + + virtual ~SVGLightSource() { } + + SVGLightType type() const { return m_type; } + virtual TextStream& externalRepresentation(TextStream&) const = 0; + +private: + SVGLightType m_type; +}; + + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGLightSource_h diff --git a/WebCore/svg/graphics/filters/SVGPointLightSource.h b/WebCore/svg/graphics/filters/SVGPointLightSource.h new file mode 100644 index 0000000..71b8f70 --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGPointLightSource.h @@ -0,0 +1,50 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGPointLightSource_h +#define SVGPointLightSource_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "FloatPoint3D.h" +#include "SVGLightSource.h" + +namespace WebCore { + +class SVGPointLightSource : public SVGLightSource { +public: + SVGPointLightSource(const FloatPoint3D& position) + : SVGLightSource(LS_POINT) + , m_position(position) + { } + + const FloatPoint3D& position() const { return m_position; } + + virtual TextStream& externalRepresentation(TextStream&) const; + +private: + FloatPoint3D m_position; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGPointLightSource_h diff --git a/WebCore/svg/graphics/filters/SVGSpotLightSource.h b/WebCore/svg/graphics/filters/SVGSpotLightSource.h new file mode 100644 index 0000000..850a5fa --- /dev/null +++ b/WebCore/svg/graphics/filters/SVGSpotLightSource.h @@ -0,0 +1,61 @@ +/* + Copyright (C) 2004, 2005, 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + 2004, 2005 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric@webkit.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SVGSpotLightSource_h +#define SVGSpotLightSource_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "FloatPoint3D.h" +#include "SVGLightSource.h" + +namespace WebCore { + +class SVGSpotLightSource : public SVGLightSource { +public: + SVGSpotLightSource(const FloatPoint3D& position, const FloatPoint3D& direction, float specularExponent, float limitingConeAngle) + : SVGLightSource(LS_SPOT) + , m_position(position) + , m_direction(direction) + , m_specularExponent(specularExponent) + , m_limitingConeAngle(limitingConeAngle) + { } + + const FloatPoint3D& position() const { return m_position; } + const FloatPoint3D& direction() const { return m_direction; } + + float specularExponent() const { return m_specularExponent; } + float limitingConeAngle() const { return m_limitingConeAngle; } + + virtual TextStream& externalRepresentation(TextStream&) const; + +private: + FloatPoint3D m_position; + FloatPoint3D m_direction; + + float m_specularExponent; + float m_limitingConeAngle; +}; + +} // namespace WebCore + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGSpotLightSource_h diff --git a/WebCore/svg/graphics/filters/cg/SVGFEBlendCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEBlendCg.mm new file mode 100644 index 0000000..29caaa0 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEBlendCg.mm @@ -0,0 +1,77 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEBlend.h" +#include "SVGFEHelpersCg.h" + +namespace WebCore { + +CIFilter* SVGFEBlend::getCIFilter(const FloatRect& bbox) const +{ + SVGResourceFilter* svgFilter = filter(); + SVGResourceFilterPlatformDataMac* filterPlatformData = static_cast<SVGResourceFilterPlatformDataMac*>(svgFilter->platformData()); + CIFilter* filter = nil; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + + switch (blendMode()) { + case SVG_FEBLEND_MODE_UNKNOWN: + return nil; + case SVG_FEBLEND_MODE_NORMAL: + // FIXME: I think this is correct.... + filter = [CIFilter filterWithName:@"CISourceOverCompositing"]; + break; + case SVG_FEBLEND_MODE_MULTIPLY: + filter = [CIFilter filterWithName:@"CIMultiplyBlendMode"]; + break; + case SVG_FEBLEND_MODE_SCREEN: + filter = [CIFilter filterWithName:@"CIScreenBlendMode"]; + break; + case SVG_FEBLEND_MODE_DARKEN: + filter = [CIFilter filterWithName:@"CIDarkenBlendMode"]; + break; + case SVG_FEBLEND_MODE_LIGHTEN: + filter = [CIFilter filterWithName:@"CILightenBlendMode"]; + break; + default: + LOG_ERROR("Unhandled blend mode: %i", blendMode()); + return nil; + } + + [filter setDefaults]; + + CIImage* inputImage = filterPlatformData->inputImage(this); + FE_QUARTZ_CHECK_INPUT(inputImage); + [filter setValue:inputImage forKey:@"inputImage"]; + + CIImage* backgroundImage = filterPlatformData->imageForName(in2()); + FE_QUARTZ_CHECK_INPUT(backgroundImage); + [filter setValue:backgroundImage forKey:@"inputBackgroundImage"]; + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEColorMatrixCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEColorMatrixCg.mm new file mode 100644 index 0000000..ae6e4aa --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEColorMatrixCg.mm @@ -0,0 +1,111 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEColorMatrix.h" +#include "SVGFEHelpersCg.h" + +#include <wtf/MathExtras.h> + +namespace WebCore { + +#define CMValuesCheck(expected, type) \ + if (values().size() != expected) { \ + NSLog(@"Error, incorrect number of values in ColorMatrix for type \"%s\", expected: %i actual: %i, ignoring filter. Values:", type, expected, values().size()); \ + for (unsigned x=0; x < values().size(); x++) fprintf(stderr, " %f", values()[x]); \ + fprintf(stderr, "\n"); \ + return nil; \ + } + +CIFilter* SVGFEColorMatrix::getCIFilter(const FloatRect& bbox) const +{ + SVGResourceFilter* svgFilter = filter(); + SVGResourceFilterPlatformDataMac* filterPlatformData = static_cast<SVGResourceFilterPlatformDataMac*>(svgFilter->platformData()); + CIFilter* filter = nil; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + switch (type()) { + case SVG_FECOLORMATRIX_TYPE_UNKNOWN: + return nil; + case SVG_FECOLORMATRIX_TYPE_MATRIX: + { + CMValuesCheck(20, "matrix"); + filter = [CIFilter filterWithName:@"CIColorMatrix"]; + [filter setDefaults]; + const Vector<float>& v = values(); + [filter setValue:[CIVector vectorWithX:v[0] Y:v[1] Z:v[2] W:v[3]] forKey:@"inputRVector"]; + [filter setValue:[CIVector vectorWithX:v[5] Y:v[6] Z:v[7] W:v[8]] forKey:@"inputGVector"]; + [filter setValue:[CIVector vectorWithX:v[10] Y:v[11] Z:v[12] W:v[13]] forKey:@"inputBVector"]; + [filter setValue:[CIVector vectorWithX:v[15] Y:v[16] Z:v[17] W:v[18]] forKey:@"inputAVector"]; + [filter setValue:[CIVector vectorWithX:v[4] Y:v[9] Z:v[14] W:v[19]] forKey:@"inputBiasVector"]; + break; + } + case SVG_FECOLORMATRIX_TYPE_SATURATE: + { + CMValuesCheck(1, "saturate"); + filter = [CIFilter filterWithName:@"CIColorControls"]; + [filter setDefaults]; + float saturation = values()[0]; + if ((saturation < 0.0) || (saturation > 3.0)) + NSLog(@"WARNING: Saturation adjustment: %f outside supported range."); + [filter setValue:[NSNumber numberWithFloat:saturation] forKey:@"inputSaturation"]; + break; + } + case SVG_FECOLORMATRIX_TYPE_HUEROTATE: + { + CMValuesCheck(1, "hueRotate"); + filter = [CIFilter filterWithName:@"CIHueAdjust"]; + [filter setDefaults]; + float radians = deg2rad(values()[0]); + [filter setValue:[NSNumber numberWithFloat:radians] forKey:@"inputAngle"]; + break; + } + case SVG_FECOLORMATRIX_TYPE_LUMINANCETOALPHA: + { + CMValuesCheck(0, "luminanceToAlpha"); + // FIXME: I bet there is an easy filter to do this. + filter = [CIFilter filterWithName:@"CIColorMatrix"]; + [filter setDefaults]; + CGFloat zero[4] = {0, 0, 0, 0}; + CGFloat alpha[4] = {0.2125f, 0.7154f, 0.0721f, 0}; + [filter setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputRVector"]; + [filter setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputGVector"]; + [filter setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputBVector"]; + [filter setValue:[CIVector vectorWithValues:alpha count:4] forKey:@"inputAVector"]; + [filter setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputBiasVector"]; + break; + } + default: + LOG_ERROR("Unhandled ColorMatrix type: %i", type()); + return nil; + } + CIImage *inputImage = filterPlatformData->inputImage(this); + FE_QUARTZ_CHECK_INPUT(inputImage); + [filter setValue:inputImage forKey:@"inputImage"]; + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEComponentTransferCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEComponentTransferCg.mm new file mode 100644 index 0000000..61515db --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEComponentTransferCg.mm @@ -0,0 +1,167 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEComponentTransfer.h" +#include "SVGFEHelpersCg.h" + +#import "WKComponentMergeFilter.h" +#import "WKIdentityTransferFilter.h" +#import "WKTableTransferFilter.h" +#import "WKDiscreteTransferFilter.h" +#import "WKLinearTransferFilter.h" +#import "WKGammaTransferFilter.h" + +namespace WebCore { + +static CIImage* genImageFromTable(const Vector<float>& table) +{ + int length = table.size(); + int nBytes = length * 4 * sizeof(float); + float* tableStore = (float *) malloc(nBytes); + NSData* bitmapData = [NSData dataWithBytesNoCopy:tableStore length:nBytes]; + for (Vector<float>::const_iterator it = table.begin(); it != table.end(); it++) { + const float value = *it; + *tableStore++ = value; + *tableStore++ = value; + *tableStore++ = value; + *tableStore++ = value; + } + return [CIImage imageWithBitmapData:bitmapData bytesPerRow:nBytes size:CGSizeMake(length, 1) format:kCIFormatRGBAf colorSpace:nil]; +} + +static void setParametersForComponentFunc(CIFilter* filter, const SVGComponentTransferFunction& func, CIVector* channelSelector) +{ + switch (func.type) { + case SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN: + return; + case SVG_FECOMPONENTTRANSFER_TYPE_TABLE: + [filter setValue:genImageFromTable(func.tableValues) forKey:@"inputTable"]; + [filter setValue:channelSelector forKey:@"inputSelector"]; + break; + case SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE: + [filter setValue:genImageFromTable(func.tableValues) forKey:@"inputTable"]; + [filter setValue:channelSelector forKey:@"inputSelector"]; + break; + case SVG_FECOMPONENTTRANSFER_TYPE_LINEAR: + [filter setValue:[NSNumber numberWithFloat:func.slope] forKey:@"inputSlope"]; + [filter setValue:[NSNumber numberWithFloat:func.intercept] forKey:@"inputIntercept"]; + break; + case SVG_FECOMPONENTTRANSFER_TYPE_GAMMA: + [filter setValue:[NSNumber numberWithFloat:func.amplitude] forKey:@"inputAmplitude"]; + [filter setValue:[NSNumber numberWithFloat:func.exponent] forKey:@"inputExponent"]; + [filter setValue:[NSNumber numberWithFloat:func.offset] forKey:@"inputOffset"]; + break; + default: + // identity has no args + break; + } +} + +static CIFilter* filterForComponentFunc(const SVGComponentTransferFunction& func) +{ + CIFilter *filter; + switch (func.type) { + case SVG_FECOMPONENTTRANSFER_TYPE_UNKNOWN: + case SVG_FECOMPONENTTRANSFER_TYPE_IDENTITY: + filter = [CIFilter filterWithName:@"WKIdentityTransfer"]; + break; + case SVG_FECOMPONENTTRANSFER_TYPE_TABLE: + filter = [CIFilter filterWithName:@"WKTableTransferFilter"]; + break; + case SVG_FECOMPONENTTRANSFER_TYPE_DISCRETE: + filter = [CIFilter filterWithName:@"WKDiscreteTransferFilter"]; + break; + case SVG_FECOMPONENTTRANSFER_TYPE_LINEAR: + filter = [CIFilter filterWithName:@"WKLinearTransfer"]; + break; + case SVG_FECOMPONENTTRANSFER_TYPE_GAMMA: + filter = [CIFilter filterWithName:@"WKGammaTransfer"]; + break; + default: + NSLog(@"WARNING: Unknown function type for feComponentTransfer"); + //and to prevent the entire svg from failing as a result + filter = [CIFilter filterWithName:@"WKIdentityTransfer"]; + break; + } + return filter; +} + +static CIFilter* getFilterForFunc(const SVGComponentTransferFunction& func, CIImage* inputImage, CIVector* channelSelector) +{ + CIFilter* filter = filterForComponentFunc(func); + [filter setDefaults]; + + setParametersForComponentFunc(filter, func, channelSelector); + [filter setValue:inputImage forKey:@"inputImage"]; + return filter; +} + +CIFilter* SVGFEComponentTransfer::getFunctionFilter(SVGChannelSelectorType channel, CIImage* inputImage) const +{ + switch (channel) { + case SVG_CHANNEL_R: + return [getFilterForFunc(redFunction(), inputImage, getVectorForChannel(channel)) valueForKey:@"outputImage"]; + case SVG_CHANNEL_G: + return [getFilterForFunc(greenFunction(), inputImage, getVectorForChannel(channel)) valueForKey:@"outputImage"]; + case SVG_CHANNEL_B: + return [getFilterForFunc(blueFunction(), inputImage, getVectorForChannel(channel)) valueForKey:@"outputImage"]; + case SVG_CHANNEL_A: + return [getFilterForFunc(alphaFunction(), inputImage, getVectorForChannel(channel)) valueForKey:@"outputImage"]; + default: + return nil; + } +} + +CIFilter* SVGFEComponentTransfer::getCIFilter(const FloatRect& bbox) const +{ + [WKComponentMergeFilter class]; + [WKIdentityTransferFilter class]; + [WKTableTransferFilter class]; + [WKDiscreteTransferFilter class]; + [WKLinearTransferFilter class]; + [WKGammaTransferFilter class]; + + SVGResourceFilter* svgFilter = filter(); + SVGResourceFilterPlatformDataMac* filterPlatformData = static_cast<SVGResourceFilterPlatformDataMac*>(svgFilter->platformData()); + CIFilter* filter = nil; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + filter = [CIFilter filterWithName:@"WKComponentMerge"]; + if (!filter) + return nil; + [filter setDefaults]; + CIImage* inputImage = filterPlatformData->inputImage(this); + FE_QUARTZ_CHECK_INPUT(inputImage); + + [filter setValue:getFunctionFilter(SVG_CHANNEL_R, inputImage) forKey:@"inputFuncR"]; + [filter setValue:getFunctionFilter(SVG_CHANNEL_G, inputImage) forKey:@"inputFuncG"]; + [filter setValue:getFunctionFilter(SVG_CHANNEL_B, inputImage) forKey:@"inputFuncB"]; + [filter setValue:getFunctionFilter(SVG_CHANNEL_A, inputImage) forKey:@"inputFuncA"]; + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFECompositeCg.mm b/WebCore/svg/graphics/filters/cg/SVGFECompositeCg.mm new file mode 100644 index 0000000..624612c --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFECompositeCg.mm @@ -0,0 +1,85 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEComposite.h" +#include "SVGFEHelpersCg.h" + +#import "WKArithmeticFilter.h" + +namespace WebCore { + +CIFilter* SVGFEComposite::getCIFilter(const FloatRect& bbox) const +{ + SVGResourceFilter* svgFilter = filter(); + SVGResourceFilterPlatformDataMac* filterPlatformData = static_cast<SVGResourceFilterPlatformDataMac*>(svgFilter->platformData()); + CIFilter* filter = nil; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + + switch (operation()) { + case SVG_FECOMPOSITE_OPERATOR_UNKNOWN: + return nil; + case SVG_FECOMPOSITE_OPERATOR_OVER: + filter = [CIFilter filterWithName:@"CISourceOverCompositing"]; + break; + case SVG_FECOMPOSITE_OPERATOR_IN: + filter = [CIFilter filterWithName:@"CISourceInCompositing"]; + break; + case SVG_FECOMPOSITE_OPERATOR_OUT: + filter = [CIFilter filterWithName:@"CISourceOutCompositing"]; + break; + case SVG_FECOMPOSITE_OPERATOR_ATOP: + filter = [CIFilter filterWithName:@"CISourceAtopCompositing"]; + break; + case SVG_FECOMPOSITE_OPERATOR_XOR: + //FIXME: I'm not sure this is right... + filter = [CIFilter filterWithName:@"CIExclusionBlendMode"]; + break; + case SVG_FECOMPOSITE_OPERATOR_ARITHMETIC: + [WKArithmeticFilter class]; + filter = [CIFilter filterWithName:@"WKArithmeticFilter"]; + break; + } + + [filter setDefaults]; + CIImage* inputImage = filterPlatformData->inputImage(this); + CIImage* backgroundImage = filterPlatformData->imageForName(in2()); + FE_QUARTZ_CHECK_INPUT(inputImage); + FE_QUARTZ_CHECK_INPUT(backgroundImage); + [filter setValue:inputImage forKey:@"inputImage"]; + [filter setValue:backgroundImage forKey:@"inputBackgroundImage"]; + //FIXME: this seems ugly + if (operation() == SVG_FECOMPOSITE_OPERATOR_ARITHMETIC) { + [filter setValue:[NSNumber numberWithFloat:k1()] forKey:@"inputK1"]; + [filter setValue:[NSNumber numberWithFloat:k2()] forKey:@"inputK2"]; + [filter setValue:[NSNumber numberWithFloat:k3()] forKey:@"inputK3"]; + [filter setValue:[NSNumber numberWithFloat:k4()] forKey:@"inputK4"]; + } + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEDiffuseLightingCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEDiffuseLightingCg.mm new file mode 100644 index 0000000..981b88b --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEDiffuseLightingCg.mm @@ -0,0 +1,74 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEDiffuseLighting.h" +#include "SVGFEHelpersCg.h" + +#import "WKDiffuseLightingFilter.h" + +namespace WebCore { + +CIFilter* SVGFEDiffuseLighting::getCIFilter(const FloatRect& bbox) const +{ + const SVGLightSource* light = lightSource(); + if (!light) + return nil; + + [WKDiffuseLightingFilter class]; + + SVGResourceFilter* svgFilter = filter(); + SVGResourceFilterPlatformDataMac* filterPlatformData = static_cast<SVGResourceFilterPlatformDataMac*>(svgFilter->platformData()); + + CIFilter* filter; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + filter = [CIFilter filterWithName:@"WKDiffuseLighting"]; + if (!filter) + return nil; + + [filter setDefaults]; + CIImage* inputImage = filterPlatformData->inputImage(this); + FE_QUARTZ_CHECK_INPUT(inputImage); + CIFilter* normals = getNormalMap(inputImage, surfaceScale()); + if (!normals) + return nil; + + CIFilter* lightVectors = getLightVectors(normals, light, surfaceScale()); + if (!lightVectors) + return nil; + + [filter setValue:[normals valueForKey:@"outputImage"] forKey:@"inputNormalMap"]; + [filter setValue:[lightVectors valueForKey:@"outputImage"] forKey:@"inputLightVectors"]; + [filter setValue:ciColor(lightingColor()) forKey:@"inputLightingColor"]; + [filter setValue:[NSNumber numberWithFloat:surfaceScale()] forKey:@"inputSurfaceScale"]; + [filter setValue:[NSNumber numberWithFloat:diffuseConstant()] forKey:@"inputDiffuseConstant"]; + [filter setValue:[NSNumber numberWithFloat:kernelUnitLengthX()] forKey:@"inputKernelUnitLengthX"]; + [filter setValue:[NSNumber numberWithFloat:kernelUnitLengthY()] forKey:@"inputKernelUnitLengthY"]; + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEDisplacementMapCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEDisplacementMapCg.mm new file mode 100644 index 0000000..9d482e2 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEDisplacementMapCg.mm @@ -0,0 +1,58 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEDisplacementMap.h" +#include "SVGFEHelpersCg.h" + +#import "WKDisplacementMapFilter.h" + +namespace WebCore { + +CIFilter* SVGFEDisplacementMap::getCIFilter(const FloatRect& bbox) const +{ + SVGResourceFilter* svgFilter = filter(); + SVGResourceFilterPlatformDataMac* filterPlatformData = static_cast<SVGResourceFilterPlatformDataMac*>(svgFilter->platformData()); + + CIFilter* filter = nil; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + [WKDisplacementMapFilter class]; + filter = [CIFilter filterWithName:@"WKDisplacementMapFilter"]; + [filter setDefaults]; + CIImage* inputImage = filterPlatformData->inputImage(this); + CIImage* displacementMap = filterPlatformData->imageForName(in2()); + FE_QUARTZ_CHECK_INPUT(inputImage); + FE_QUARTZ_CHECK_INPUT(displacementMap); + [filter setValue:inputImage forKey:@"inputImage"]; + [filter setValue:displacementMap forKey:@"inputDisplacementMap"]; + [filter setValue:getVectorForChannel(xChannelSelector()) forKey:@"inputXChannelSelector"]; + [filter setValue:getVectorForChannel(yChannelSelector()) forKey:@"inputYChannelSelector"]; + [filter setValue:[NSNumber numberWithFloat:scale()] forKey:@"inputScale"]; + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEFloodCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEFloodCg.mm new file mode 100644 index 0000000..db46f5b --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEFloodCg.mm @@ -0,0 +1,54 @@ +/* + Copyright (C) 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEFlood.h" + +#include "AffineTransform.h" +#include "SVGFEHelpersCg.h" +#include "CgSupport.h" + +namespace WebCore { + +CIFilter* SVGFEFlood::getCIFilter(const FloatRect& bbox) const +{ + SVGResourceFilter* svgFilter = filter(); + SVGResourceFilterPlatformDataMac* filterPlatformData = static_cast<SVGResourceFilterPlatformDataMac*>(svgFilter->platformData()); + CIFilter* filter; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + filter = [CIFilter filterWithName:@"CIConstantColorGenerator"]; + [filter setDefaults]; + CGColorRef color = cgColor(floodColor()); + CGColorRef withAlpha = CGColorCreateCopyWithAlpha(color, CGColorGetAlpha(color) * floodOpacity()); + CIColor* inputColor = [CIColor colorWithCGColor:withAlpha]; + CGColorRelease(color); + CGColorRelease(withAlpha); + [filter setValue:inputColor forKey:@"inputColor"]; + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEGaussianBlurCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEGaussianBlurCg.mm new file mode 100644 index 0000000..13140b6 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEGaussianBlurCg.mm @@ -0,0 +1,49 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEGaussianBlur.h" +#include "SVGFEHelpersCg.h" + +namespace WebCore { + +CIFilter* SVGFEGaussianBlur::getCIFilter(const FloatRect& bbox) const +{ + SVGResourceFilter* svgFilter = filter(); + FE_QUARTZ_SETUP_INPUT(@"CIGaussianPyramid"); + + float inputRadius = stdDeviationX(); + if (inputRadius != stdDeviationY()) { + float inputAspectRatio = stdDeviationX()/stdDeviationY(); + // FIXME: inputAspectRatio only support the range .5 to 2.0! + [filter setValue:[NSNumber numberWithFloat:inputAspectRatio] forKey:@"inputAspectRatio"]; + } + [filter setValue:[NSNumber numberWithFloat:inputRadius] forKey:@"inputRadius"]; + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEHelpersCg.h b/WebCore/svg/graphics/filters/cg/SVGFEHelpersCg.h new file mode 100644 index 0000000..176abb5 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEHelpersCg.h @@ -0,0 +1,88 @@ +/* + Copyright (C) 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#include "BlockExceptions.h" +#include "SVGFEDisplacementMap.h" +#include "SVGResourceFilter.h" +#include "SVGResourceFilterPlatformDataMac.h" +#include <QuartzCore/CoreImage.h> +#include <wtf/MathExtras.h> + +class Color; +class SVGLightSource; + +namespace WebCore { + +CIVector* getVectorForChannel(SVGChannelSelectorType channel); +CIColor* ciColor(const Color& c); + +// Lighting +CIFilter* getPointLightVectors(CIFilter* normals, CIVector* lightPosition, float surfaceScale); +CIFilter* getLightVectors(CIFilter* normals, const SVGLightSource* light, float surfaceScale); +CIFilter* getNormalMap(CIImage* bumpMap, float scale); + +}; + +// Macros used by the SVGFE*Cg classes +#define FE_QUARTZ_SETUP_INPUT(name) \ + SVGResourceFilterPlatformDataMac* filterPlatformData = static_cast<SVGResourceFilterPlatformDataMac*>(svgFilter->platformData()); \ + CIImage* inputImage = filterPlatformData->inputImage(this); \ + FE_QUARTZ_CHECK_INPUT(inputImage) \ + CIFilter* filter; \ + BEGIN_BLOCK_OBJC_EXCEPTIONS; \ + filter = [CIFilter filterWithName:name]; \ + [filter setDefaults]; \ + [filter setValue:inputImage forKey:@"inputImage"]; + +#define FE_QUARTZ_CHECK_INPUT(input) \ + if (!input) \ + return nil; + +#define FE_QUARTZ_OUTPUT_RETURN \ + filterPlatformData->setOutputImage(this, [filter valueForKey:@"outputImage"]); \ + return filter; \ + END_BLOCK_OBJC_EXCEPTIONS; \ + return nil; + +#define FE_QUARTZ_MAP_TO_SUBREGION_PREPARE(bbox) \ + FloatRect filterRect = svgFilter->filterBBoxForItemBBox(bbox); \ + FloatRect cropRect = primitiveBBoxForFilterBBox(filterRect, bbox); \ + cropRect.intersect(filterRect); \ + cropRect.move(-filterRect.x(), -filterRect.y()); + +#define FE_QUARTZ_MAP_TO_SUBREGION_APPLY(cropRect) \ + { \ + CIFilter* crop = [CIFilter filterWithName:@"CICrop"]; \ + [crop setDefaults]; \ + if (CIImage* currentFilterOutputImage = [filter valueForKey:@"outputImage"]) { \ + [crop setValue:currentFilterOutputImage forKey:@"inputImage"]; \ + [crop setValue:[CIVector vectorWithX:cropRect.x() Y:cropRect.y() Z:cropRect.width() W:cropRect.height()] forKey:@"inputRectangle"]; \ + filter = crop; \ + } \ + } + +#define FE_QUARTZ_MAP_TO_SUBREGION(bbox) \ + FE_QUARTZ_MAP_TO_SUBREGION_PREPARE(bbox); \ + FE_QUARTZ_MAP_TO_SUBREGION_APPLY(cropRect); + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEHelpersCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEHelpersCg.mm new file mode 100644 index 0000000..5c7fc31 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEHelpersCg.mm @@ -0,0 +1,162 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEHelpersCg.h" + +#include "Color.h" +#include "SVGDistantLightSource.h" +#include "SVGLightSource.h" +#include "SVGPointLightSource.h" +#include "SVGSpotLightSource.h" + +#import "WKDistantLightFilter.h" +#import "WKNormalMapFilter.h" +#import "WKPointLightFilter.h" +#import "WKSpotLightFilter.h" + +#include <wtf/MathExtras.h> + +namespace WebCore { + +CIVector* getVectorForChannel(SVGChannelSelectorType channel) +{ + switch (channel) { + case SVG_CHANNEL_UNKNOWN: + return nil; + case SVG_CHANNEL_R: + return [CIVector vectorWithX:1.0f Y:0.0f Z:0.0f W:0.0f]; + case SVG_CHANNEL_G: + return [CIVector vectorWithX:0.0f Y:1.0f Z:0.0f W:0.0f]; + case SVG_CHANNEL_B: + return [CIVector vectorWithX:0.0f Y:0.0f Z:1.0f W:0.0f]; + case SVG_CHANNEL_A: + return [CIVector vectorWithX:0.0f Y:0.0f Z:0.0f W:1.0f]; + default: + return [CIVector vectorWithX:0.0f Y:0.0f Z:0.0f W:0.0f]; + } +} + +CIColor* ciColor(const Color& c) +{ + CGColorRef colorCG = cgColor(c); + CIColor* colorCI = [CIColor colorWithCGColor:colorCG]; + CGColorRelease(colorCG); + return colorCI; +} + +// Lighting +CIFilter* getPointLightVectors(CIFilter* normals, CIVector* lightPosition, float surfaceScale) +{ + CIFilter* filter; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + filter = [CIFilter filterWithName:@"WKPointLight"]; + if (!filter) + return nil; + [filter setDefaults]; + [filter setValue:[normals valueForKey:@"outputImage"] forKey:@"inputNormalMap"]; + [filter setValue:lightPosition forKey:@"inputLightPosition"]; + [filter setValue:[NSNumber numberWithFloat:surfaceScale] forKey:@"inputSurfaceScale"]; + return filter; + END_BLOCK_OBJC_EXCEPTIONS; + return nil; +} + +CIFilter* getLightVectors(CIFilter* normals, const SVGLightSource* light, float surfaceScale) +{ + [WKDistantLightFilter class]; + [WKPointLightFilter class]; + [WKSpotLightFilter class]; + + CIFilter* filter = nil; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + + switch (light->type()) { + case LS_DISTANT: + { + const SVGDistantLightSource* dlight = static_cast<const SVGDistantLightSource*>(light); + + filter = [CIFilter filterWithName:@"WKDistantLight"]; + if (!filter) + return nil; + [filter setDefaults]; + + float azimuth = dlight->azimuth(); + float elevation = dlight->elevation(); + azimuth = deg2rad(azimuth); + elevation = deg2rad(elevation); + float Lx = cosf(azimuth)*cosf(elevation); + float Ly = sinf(azimuth)*cosf(elevation); + float Lz = sinf(elevation); + + [filter setValue:[normals valueForKey:@"outputImage"] forKey:@"inputNormalMap"]; + [filter setValue:[CIVector vectorWithX:Lx Y:Ly Z:Lz] forKey:@"inputLightDirection"]; + return filter; + } + case LS_POINT: + { + const SVGPointLightSource* plight = static_cast<const SVGPointLightSource*>(light); + return getPointLightVectors(normals, [CIVector vectorWithX:plight->position().x() Y:plight->position().y() Z:plight->position().z()], surfaceScale); + } + case LS_SPOT: + { + const SVGSpotLightSource* slight = static_cast<const SVGSpotLightSource*>(light); + filter = [CIFilter filterWithName:@"WKSpotLight"]; + if (!filter) + return nil; + + CIFilter* pointLightFilter = getPointLightVectors(normals, [CIVector vectorWithX:slight->position().x() Y:slight->position().y() Z:slight->position().z()], surfaceScale); + if (!pointLightFilter) + return nil; + [filter setDefaults]; + + [filter setValue:[pointLightFilter valueForKey:@"outputImage"] forKey:@"inputLightVectors"]; + [filter setValue:[CIVector vectorWithX:slight->direction().x() Y:slight->direction().y() Z:slight->direction().z()] forKey:@"inputLightDirection"]; + [filter setValue:[NSNumber numberWithFloat:slight->specularExponent()] forKey:@"inputSpecularExponent"]; + [filter setValue:[NSNumber numberWithFloat:deg2rad(slight->limitingConeAngle())] forKey:@"inputLimitingConeAngle"]; + return filter; + } + } + + END_BLOCK_OBJC_EXCEPTIONS; + return nil; +} + +CIFilter* getNormalMap(CIImage* bumpMap, float scale) +{ + [WKNormalMapFilter class]; + CIFilter* filter; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + filter = [CIFilter filterWithName:@"WKNormalMap"]; + [filter setDefaults]; + + [filter setValue:bumpMap forKey:@"inputImage"]; + [filter setValue:[NSNumber numberWithFloat:scale] forKey:@"inputSurfaceScale"]; + return filter; + END_BLOCK_OBJC_EXCEPTIONS; + return nil; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEImageCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEImageCg.mm new file mode 100644 index 0000000..2f12274 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEImageCg.mm @@ -0,0 +1,80 @@ +/* + Copyright (C) 2006, 2007 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEImage.h" + +#include "Image.h" +#include "SVGFEHelpersCg.h" +#include "CgSupport.h" + +namespace WebCore { + +CIFilter* SVGFEImage::getCIFilter(const FloatRect& bbox) const +{ + if (!cachedImage()) + return nil; + + SVGResourceFilter* svgFilter = filter(); + SVGResourceFilterPlatformDataMac* filterPlatformData = static_cast<SVGResourceFilterPlatformDataMac*>(svgFilter->platformData()); + + CIFilter* filter; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + CIImage* ciImage = [CIImage imageWithCGImage:cachedImage()->image()->getCGImageRef()]; + + filter = [CIFilter filterWithName:@"CIAffineTransform"]; + [filter setDefaults]; + [filter setValue:ciImage forKey:@"inputImage"]; + + FloatRect imageRect = cachedImage()->image()->rect(); + + // Flip image into right origin + CGAffineTransform cgTransform = CGAffineTransformMake(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, imageRect.bottom()); + NSAffineTransform* nsTransform = [NSAffineTransform transform]; + [nsTransform setTransformStruct:*((NSAffineTransformStruct *)&cgTransform)]; + [filter setValue:nsTransform forKey:@"inputTransform"]; + + // Calculate crop rect + FE_QUARTZ_MAP_TO_SUBREGION_PREPARE(bbox); + + // Map between the image rectangle and the crop rect + if (!cropRect.isEmpty()) { + CIFilter* scaleImage = [CIFilter filterWithName:@"CIAffineTransform"]; + [scaleImage setDefaults]; + [scaleImage setValue:[filter valueForKey:@"outputImage"] forKey:@"inputImage"]; + + cgTransform = CGAffineTransformMakeMapBetweenRects(CGRect(imageRect), CGRect(cropRect)); + [nsTransform setTransformStruct:*((NSAffineTransformStruct *)&cgTransform)]; + [scaleImage setValue:nsTransform forKey:@"inputTransform"]; + + filter = scaleImage; + } + + // Actually apply cropping + FE_QUARTZ_MAP_TO_SUBREGION_APPLY(cropRect); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEMergeCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEMergeCg.mm new file mode 100644 index 0000000..30a981a --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEMergeCg.mm @@ -0,0 +1,57 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEMerge.h" +#include "SVGFEHelpersCg.h" + +namespace WebCore { + +CIFilter* SVGFEMerge::getCIFilter(const FloatRect& bbox) const +{ + SVGResourceFilter* svgFilter = filter(); + SVGResourceFilterPlatformDataMac* filterPlatformData = static_cast<SVGResourceFilterPlatformDataMac*>(svgFilter->platformData()); + + CIFilter* filter = nil; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + const Vector<String>& inputs = mergeInputs(); + + CIImage* previousOutput = filterPlatformData->inputImage(this); + for (unsigned x = 0; x < inputs.size(); x++) { + CIImage* inputImage = filterPlatformData->imageForName(inputs[x]); + FE_QUARTZ_CHECK_INPUT(inputImage); + FE_QUARTZ_CHECK_INPUT(previousOutput); + filter = [CIFilter filterWithName:@"CISourceOverCompositing"]; + [filter setDefaults]; + [filter setValue:inputImage forKey:@"inputImage"]; + [filter setValue:previousOutput forKey:@"inputBackgroundImage"]; + previousOutput = [filter valueForKey:@"outputImage"]; + } + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFEOffsetCg.mm b/WebCore/svg/graphics/filters/cg/SVGFEOffsetCg.mm new file mode 100644 index 0000000..46fb045 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFEOffsetCg.mm @@ -0,0 +1,44 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFEOffset.h" +#include "SVGFEHelpersCg.h" + +namespace WebCore { + +CIFilter* SVGFEOffset::getCIFilter(const FloatRect& bbox) const +{ + SVGResourceFilter* svgFilter = filter(); + FE_QUARTZ_SETUP_INPUT(@"CIAffineTransform"); + NSAffineTransform* offsetTransform = [NSAffineTransform transform]; + [offsetTransform translateXBy:dx() yBy:dy()]; + [filter setValue:offsetTransform forKey:@"inputTransform"]; + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFESpecularLightingCg.mm b/WebCore/svg/graphics/filters/cg/SVGFESpecularLightingCg.mm new file mode 100644 index 0000000..e872c6a --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFESpecularLightingCg.mm @@ -0,0 +1,69 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFESpecularLighting.h" +#include "SVGFEHelpersCg.h" + +#import "WKSpecularLightingFilter.h" + +namespace WebCore { + +CIFilter* SVGFESpecularLighting::getCIFilter(const FloatRect& bbox) const +{ + const SVGLightSource* light = lightSource(); + if (!light) + return nil; + + [WKSpecularLightingFilter class]; + + SVGResourceFilter* svgFilter = filter(); + SVGResourceFilterPlatformDataMac* filterPlatformData = static_cast<SVGResourceFilterPlatformDataMac*>(svgFilter->platformData()); + CIFilter* filter; + BEGIN_BLOCK_OBJC_EXCEPTIONS; + filter = [CIFilter filterWithName:@"WKSpecularLighting"]; + [filter setDefaults]; + CIImage* inputImage = filterPlatformData->inputImage(this); + FE_QUARTZ_CHECK_INPUT(inputImage); + CIFilter* normals = getNormalMap(inputImage, surfaceScale()); + if (!normals) + return nil; + CIFilter* lightVectors = getLightVectors(normals, light, surfaceScale()); + if (!lightVectors) + return nil; + [filter setValue:[normals valueForKey:@"outputImage"] forKey:@"inputNormalMap"]; + [filter setValue:[lightVectors valueForKey:@"outputImage"] forKey:@"inputLightVectors"]; + [filter setValue:ciColor(lightingColor()) forKey:@"inputLightingColor"]; + [filter setValue:[NSNumber numberWithFloat:surfaceScale()] forKey:@"inputSurfaceScale"]; + [filter setValue:[NSNumber numberWithFloat:specularConstant()] forKey:@"inputSpecularConstant"]; + [filter setValue:[NSNumber numberWithFloat:specularExponent()] forKey:@"inputSpecularExponent"]; + [filter setValue:[NSNumber numberWithFloat:kernelUnitLengthX()] forKey:@"inputKernelUnitLengthX"]; + [filter setValue:[NSNumber numberWithFloat:kernelUnitLengthY()] forKey:@"inputKernelUnitLengthY"]; + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFETileCg.mm b/WebCore/svg/graphics/filters/cg/SVGFETileCg.mm new file mode 100644 index 0000000..dea9854 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFETileCg.mm @@ -0,0 +1,41 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) +#include "SVGFETile.h" +#include "SVGFEHelpersCg.h" + +namespace WebCore { + +CIFilter* SVGFETile::getCIFilter(const FloatRect& bbox) const +{ + SVGResourceFilter* svgFilter = filter(); + FE_QUARTZ_SETUP_INPUT(@"CIAffineTile"); + + FE_QUARTZ_MAP_TO_SUBREGION(bbox); + FE_QUARTZ_OUTPUT_RETURN; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/SVGFilterEffectCg.mm b/WebCore/svg/graphics/filters/cg/SVGFilterEffectCg.mm new file mode 100644 index 0000000..4b0a233 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/SVGFilterEffectCg.mm @@ -0,0 +1,37 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#include "SVGFilterEffect.h" + +namespace WebCore { + +CIFilter* SVGFilterEffect::getCIFilter(const FloatRect& bbox) const +{ + return nil; +} + +} + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKArithmeticFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKArithmeticFilter.cikernel new file mode 100644 index 0000000..3c32c3a --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKArithmeticFilter.cikernel @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +kernel vec4 arithmeticComposite(sampler in1, sampler in2, float k1, float k2, float k3, float k4) +{ + vec4 vin1 = sample(in1, samplerCoord(in1)); + vec4 vin2 = sample(in2, samplerCoord(in2)); + vec4 res = k1*vin1*vin2 + k2*vin1 + k3*vin2 + vec4(k4); + return res; +} diff --git a/WebCore/svg/graphics/filters/cg/WKArithmeticFilter.h b/WebCore/svg/graphics/filters/cg/WKArithmeticFilter.h new file mode 100644 index 0000000..4693853 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKArithmeticFilter.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKArithmeticFilter : CIFilter { + CIImage *inputImage; + CIImage *inputBackgroundImage; + NSNumber *inputK1; + NSNumber *inputK2; + NSNumber *inputK3; + NSNumber *inputK4; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKArithmeticFilter.m b/WebCore/svg/graphics/filters/cg/WKArithmeticFilter.m new file mode 100644 index 0000000..389f25d --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKArithmeticFilter.m @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import "config.h" +#import "WKArithmeticFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *arithmeticFilter = nil; + +@implementation WKArithmeticFilter ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKArithmeticFilter" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Arithmetic Filter", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:0.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputK1", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:0.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputK2", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:0.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputK3", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:0.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputK4", + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!arithmeticFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKArithmeticFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + arithmeticFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + return [self apply:arithmeticFilter, inputImage, inputBackgroundImage, inputK1, inputK2, inputK3, + inputK4, nil]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKComponentMergeFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKComponentMergeFilter.cikernel new file mode 100644 index 0000000..f33f20c --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKComponentMergeFilter.cikernel @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +kernel vec4 mergeComponents(sampler funcR, sampler funcG, sampler funcB, sampler funcA) +{ + float r = sample(funcR, samplerCoord(funcR)).r; + float g = sample(funcG, samplerCoord(funcG)).g; + float b = sample(funcB, samplerCoord(funcB)).b; + float a = sample(funcA, samplerCoord(funcA)).a; + return vec4(r, g, b, a); +} diff --git a/WebCore/svg/graphics/filters/cg/WKComponentMergeFilter.h b/WebCore/svg/graphics/filters/cg/WKComponentMergeFilter.h new file mode 100644 index 0000000..778e326 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKComponentMergeFilter.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKComponentMergeFilter : CIFilter { + CIImage *inputFuncR; + CIImage *inputFuncG; + CIImage *inputFuncB; + CIImage *inputFuncA; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKComponentMergeFilter.m b/WebCore/svg/graphics/filters/cg/WKComponentMergeFilter.m new file mode 100644 index 0000000..4f2045a --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKComponentMergeFilter.m @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import "config.h" +#import "WKComponentMergeFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *componentMergeFilter = nil; + +@implementation WKComponentMergeFilter ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKComponentMerge" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Component Merge", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!componentMergeFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKComponentMergeFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + componentMergeFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + return [self apply:componentMergeFilter, [CISampler samplerWithImage: inputFuncR], + [CISampler samplerWithImage: inputFuncG], [CISampler samplerWithImage: inputFuncB], [CISampler samplerWithImage: inputFuncA], @"definition", [inputFuncR definition], nil]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKDiffuseLightingFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKDiffuseLightingFilter.cikernel new file mode 100644 index 0000000..870956a --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDiffuseLightingFilter.cikernel @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +kernel vec4 diffuseLighting(sampler normalVectors, sampler lightVectors, __color lightingColor, + float surfaceScale, float diffuseConstant, float kernelLengthX, float kernelLengthY) +{ + vec2 pos = samplerCoord(lightVectors); + vec2 posn = samplerCoord(normalVectors); + vec4 l4 = sample(lightVectors, pos); + vec3 l = l4.xyz; + l = normalize(l); + vec3 n = sample(normalVectors, posn).xyz; + float nl = dot(l, n) * diffuseConstant; + vec4 res = vec4(lightingColor.r * nl, lightingColor.g * nl, lightingColor.b * nl, 1.0); + res.xyz *= l4.w; + return res; +} diff --git a/WebCore/svg/graphics/filters/cg/WKDiffuseLightingFilter.h b/WebCore/svg/graphics/filters/cg/WKDiffuseLightingFilter.h new file mode 100644 index 0000000..2731986 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDiffuseLightingFilter.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKDiffuseLightingFilter : CIFilter { + CISampler *inputNormalMap; + CISampler *inputLightVectors; + CIColor *inputLightingColor; + NSNumber *inputSurfaceScale; + NSNumber *inputDiffuseConstant; + NSNumber *inputKernelUnitLengthX; + NSNumber *inputKernelUnitLengthY; +} +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKDiffuseLightingFilter.m b/WebCore/svg/graphics/filters/cg/WKDiffuseLightingFilter.m new file mode 100644 index 0000000..3675af8 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDiffuseLightingFilter.m @@ -0,0 +1,97 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import "config.h" +#import "WKDiffuseLightingFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *diffuseLightingFilter = nil; +@implementation WKDiffuseLightingFilter + ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKDiffuseLighting" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Diffuse Lighting", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + [NSDictionary dictionaryWithObjectsAndKeys: + [CIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f], + kCIAttributeDefault, nil], @"inputLightingColor", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputSurfaceScale", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputDiffuseConstant", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputKernelUnitLengthX", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputKernelUnitLengthY", + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!diffuseLightingFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKDiffuseLightingFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + diffuseLightingFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + return [self apply:diffuseLightingFilter, inputNormalMap, inputLightVectors, inputLightingColor, inputSurfaceScale, inputDiffuseConstant, + inputKernelUnitLengthX, inputKernelUnitLengthY, nil]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKDiscreteTransferFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKDiscreteTransferFilter.cikernel new file mode 100644 index 0000000..db3cefd --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDiscreteTransferFilter.cikernel @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +kernel vec4 discreteTransfer(sampler image, sampler table, vec4 rgbaSelector, float maxIndex) +{ + vec4 C = sample(image, samplerCoord(image)); + float k = floor(dot(rgbaSelector, C) * maxIndex); + vec4 res = sample(table, vec2(k+0.0, 0.0)); + return res; +} diff --git a/WebCore/svg/graphics/filters/cg/WKDiscreteTransferFilter.h b/WebCore/svg/graphics/filters/cg/WKDiscreteTransferFilter.h new file mode 100644 index 0000000..d444c75 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDiscreteTransferFilter.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKDiscreteTransferFilter : CIFilter { + CIImage *inputImage; + CIImage *inputTable; + CIVector *inputSelector; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKDiscreteTransferFilter.m b/WebCore/svg/graphics/filters/cg/WKDiscreteTransferFilter.m new file mode 100644 index 0000000..dc6ca76 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDiscreteTransferFilter.m @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import "config.h" +#import "WKDiscreteTransferFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *discreteTransferFilter = nil; + +@implementation WKDiscreteTransferFilter ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKDiscreteTransfer" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Discrete Transfer", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!discreteTransferFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKDiscreteTransferFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + discreteTransferFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + CISampler *inputSampler = [CISampler samplerWithImage: inputImage]; + CISampler *tableSampler = [CISampler samplerWithImage: inputTable keysAndValues:kCISamplerFilterMode, kCISamplerFilterNearest, kCISamplerWrapMode, kCISamplerWrapClamp, nil]; + NSArray *args = [NSArray arrayWithObjects:inputSampler, tableSampler, inputSelector, + [NSNumber numberWithDouble:[inputTable extent].size.width - 1.0f], @"definition", [inputSampler definition], nil]; + return [self apply:discreteTransferFilter arguments:args options:nil]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKDisplacementMapFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKDisplacementMapFilter.cikernel new file mode 100644 index 0000000..95b19c6 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDisplacementMapFilter.cikernel @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +/* + * Performs the transformation: + * P'(x,y) <- P( x + scale * (XC(x,y) - .5), y + scale * (YC(x,y) - .5)) + * + * x/ychannel arguments are used to select the appropriate channel for x and + * y displacement. Hence each vector should have only one non-zero element, + * which should have the value 1.0. + * + */ + +kernel vec4 displacementMap(sampler image, sampler map, vec4 xchannel, vec4 ychannel, float scale) +{ + vec2 samplePos = samplerCoord(image); + vec4 XCYC = sample(map, samplerCoord(map)); + float xc = dot(XCYC, xchannel); + float yc = dot(XCYC, ychannel); + samplePos.x += scale*(xc-0.5); + samplePos.y += scale*(yc-0.5); + return sample(image, samplePos); +} diff --git a/WebCore/svg/graphics/filters/cg/WKDisplacementMapFilter.h b/WebCore/svg/graphics/filters/cg/WKDisplacementMapFilter.h new file mode 100644 index 0000000..e594495 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDisplacementMapFilter.h @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKDisplacementMapFilter : CIFilter { + CIImage *inputImage; + CIImage *inputDisplacementMap; + CIVector *inputXChannelSelector; + CIVector *inputYChannelSelector; + NSNumber *inputScale; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKDisplacementMapFilter.m b/WebCore/svg/graphics/filters/cg/WKDisplacementMapFilter.m new file mode 100644 index 0000000..8ccd52c --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDisplacementMapFilter.m @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import "config.h" +#import "WKDisplacementMapFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *displacementMapFilter = nil; + +@implementation WKDisplacementMapFilter + ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKDisplacementMapFilter" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Displacement Map Filter", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + [NSDictionary dictionaryWithObjectsAndKeys: + [CIVector vectorWithX:1.0f Y:0.0f Z:0.0f W:0.0f], + kCIAttributeDefault, nil], @"inputXChannelSelector", + [NSDictionary dictionaryWithObjectsAndKeys: + [CIVector vectorWithX:0.0f Y:1.0f Z:0.0f W:0.0f], + kCIAttributeDefault, nil], @"inputYChannelSelector", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeDefault, + [NSNumber numberWithDouble:0.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputScale", + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!displacementMapFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKDisplacementMapFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + displacementMapFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + return [self apply:displacementMapFilter, inputImage, inputDisplacementMap, inputXChannelSelector, inputYChannelSelector, inputScale, nil]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKDistantLightFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKDistantLightFilter.cikernel new file mode 100644 index 0000000..c14677c --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDistantLightFilter.cikernel @@ -0,0 +1,29 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +kernel vec4 distantLightGenerator(sampler image, vec3 direction) +{ + return vec4(direction.x, direction.y, direction.z, 1.0); +} diff --git a/WebCore/svg/graphics/filters/cg/WKDistantLightFilter.h b/WebCore/svg/graphics/filters/cg/WKDistantLightFilter.h new file mode 100644 index 0000000..e5fe15a --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDistantLightFilter.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKDistantLightFilter : CIFilter { + CIImage * inputNormalMap; + CIVector * inputLightDirection; +} +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKDistantLightFilter.m b/WebCore/svg/graphics/filters/cg/WKDistantLightFilter.m new file mode 100644 index 0000000..29e3caf --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKDistantLightFilter.m @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import "config.h" +#import "WKDistantLightFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *distantLightFilter = nil; + +@implementation WKDistantLightFilter + ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKDistantLight" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Distant Light", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + [NSDictionary dictionaryWithObjectsAndKeys: + kCIAttributeTypePosition3, kCIAttributeType, + nil], @"inputLightDirection", + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!distantLightFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKDistantLightFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + distantLightFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + return [self apply:distantLightFilter, [CISampler samplerWithImage:inputNormalMap], inputLightDirection, nil]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKGammaTransferFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKGammaTransferFilter.cikernel new file mode 100644 index 0000000..810edb6 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKGammaTransferFilter.cikernel @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +kernel vec4 gammaTransfer(sampler image, float amplitude, float exponent, float offset) +{ + vec4 C = sample(image, samplerCoord(image)); + return amplitude * pow(C, vec4(exponent)) + offset; +} diff --git a/WebCore/svg/graphics/filters/cg/WKGammaTransferFilter.h b/WebCore/svg/graphics/filters/cg/WKGammaTransferFilter.h new file mode 100644 index 0000000..7e0c1e4 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKGammaTransferFilter.h @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKGammaTransferFilter : CIFilter { + CIImage *inputImage; + NSNumber *inputAmplitude; + NSNumber *inputExponent; + NSNumber *inputOffset; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKGammaTransferFilter.m b/WebCore/svg/graphics/filters/cg/WKGammaTransferFilter.m new file mode 100644 index 0000000..8642931 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKGammaTransferFilter.m @@ -0,0 +1,85 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import "config.h" +#import "WKGammaTransferFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *gammaTransferFilter = nil; + +@implementation WKGammaTransferFilter ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKGammaTransfer" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Gamma Transfer", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputAmplitude", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputExponent", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeDefault, + [NSNumber numberWithDouble:0.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputOffset", + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!gammaTransferFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKGammaTransferFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + gammaTransferFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + CISampler *inputSampler = [CISampler samplerWithImage: inputImage]; + return [self apply:gammaTransferFilter, inputSampler, inputAmplitude, inputExponent, inputOffset, @"definition", [inputSampler definition], nil]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKIdentityTransferFilter.h b/WebCore/svg/graphics/filters/cg/WKIdentityTransferFilter.h new file mode 100644 index 0000000..0c36daa --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKIdentityTransferFilter.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKIdentityTransferFilter : CIFilter { + CIImage *inputImage; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKIdentityTransferFilter.m b/WebCore/svg/graphics/filters/cg/WKIdentityTransferFilter.m new file mode 100644 index 0000000..935c305 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKIdentityTransferFilter.m @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import "config.h" +#import "WKIdentityTransferFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@implementation WKIdentityTransferFilter ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKIdentityTransfer" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Identity Transfer", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + return [super init]; +} + +- (CIImage *)outputImage +{ + return inputImage; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKLinearTransferFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKLinearTransferFilter.cikernel new file mode 100644 index 0000000..17d57e4 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKLinearTransferFilter.cikernel @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +kernel vec4 linearTransfer(sampler image, float slope, float intercept) +{ + vec4 C = sample(image, samplerCoord(image)); + return slope * C + intercept; +} diff --git a/WebCore/svg/graphics/filters/cg/WKLinearTransferFilter.h b/WebCore/svg/graphics/filters/cg/WKLinearTransferFilter.h new file mode 100644 index 0000000..91a99f5 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKLinearTransferFilter.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKLinearTransferFilter : CIFilter { + CIImage *inputImage; + NSNumber *inputSlope; + NSNumber *inputIntercept; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKLinearTransferFilter.m b/WebCore/svg/graphics/filters/cg/WKLinearTransferFilter.m new file mode 100644 index 0000000..ecfed53 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKLinearTransferFilter.m @@ -0,0 +1,80 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import "config.h" +#import "WKLinearTransferFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *linearTransferFilter = nil; + +@implementation WKLinearTransferFilter ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKLinearTransfer" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Linear Transfer", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputSlope", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeDefault, + [NSNumber numberWithDouble:0.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputIntersection", + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!linearTransferFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKLinearTransferFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + linearTransferFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + CISampler *inputSampler = [CISampler samplerWithImage: inputImage]; + return [self apply:linearTransferFilter, inputSampler, inputSlope, inputIntercept, @"definition", [inputSampler definition], nil]; +} + +@end + +#endif ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKNormalMapFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKNormalMapFilter.cikernel new file mode 100644 index 0000000..589f475 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKNormalMapFilter.cikernel @@ -0,0 +1,49 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +//TODO: We currently ignore the input kernel lengths +kernel vec4 convolve3x3(sampler image, float divisor, float bias, + vec3 m0, vec3 m1, vec3 m2) +{ + vec4 colour = vec4(0.0, 0.0, 0.0, 0.0); + vec2 pos= samplerCoord(image); + colour = sample(image, pos + vec2(-1.0, -1.0)) *m0.x; + colour += sample(image, pos + vec2(-1.0, 0.0)) *m0.y; + colour += sample(image, pos + vec2(-1.0, 1.0)) *m0.z; + colour += sample(image, pos + vec2( 0.0, -1.0)) *m1.x; + colour += sample(image, pos) * m1.y; + colour += sample(image, pos + vec2( 0.0, 1.0))*m1.z; + colour += sample(image, pos + vec2( 1.0, -1.0))*m2.x; + colour += sample(image, pos + vec2( 1.0, 0.0))*m2.y; + colour += sample(image, pos + vec2( 1.0, 1.0))*m2.z; + return colour / divisor + bias; +} + +kernel vec4 mergeNormals(sampler Nx, sampler Ny, sampler src, float surfaceScale) +{ + vec3 N = vec3(surfaceScale * sample(Nx, samplerCoord(Nx)).a, -surfaceScale * sample(Ny, samplerCoord(Ny)).a, 1.0); + N = normalize(N); + return vec4(N.x, N.y, N.z, sample(src, samplerCoord(src)).a); +} diff --git a/WebCore/svg/graphics/filters/cg/WKNormalMapFilter.h b/WebCore/svg/graphics/filters/cg/WKNormalMapFilter.h new file mode 100644 index 0000000..fb27447 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKNormalMapFilter.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKNormalMapFilter : CIFilter { + CIImage *inputImage; + NSNumber *inputSurfaceScale; +} +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKNormalMapFilter.m b/WebCore/svg/graphics/filters/cg/WKNormalMapFilter.m new file mode 100644 index 0000000..b462008 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKNormalMapFilter.m @@ -0,0 +1,109 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import "config.h" +#import "WKNormalMapFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *convolveKernel = nil; +static CIKernel *normalMapKernel = nil; + +@implementation WKNormalMapFilter + ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKNormalMap" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Normal Map", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects: kCICategoryBlur, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels, nil], kCIAttributeFilterCategories, + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputSurfaceScale", + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!normalMapKernel) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKNormalMapFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + convolveKernel = [[kernels objectAtIndex:0] retain]; + normalMapKernel = [[kernels objectAtIndex:1] retain]; + } + return [super init]; +} + +- (NSArray *)xConvolveArgsWithBumpMap:(CISampler *)bumpMap { + return [NSArray arrayWithObjects: + bumpMap, + [NSNumber numberWithFloat:4], + [NSNumber numberWithFloat:0], + [CIVector vectorWithX:1 Y:2 Z:1], + [CIVector vectorWithX:0 Y:0 Z:0], + [CIVector vectorWithX:-1 Y:-2 Z:-1], + nil]; +} + +- (NSArray *)yConvolveArgsWithBumpMap:(CISampler *)bumpMap { + return [NSArray arrayWithObjects: + bumpMap, + [NSNumber numberWithFloat:4], + [NSNumber numberWithFloat:0], + [CIVector vectorWithX:1 Y:0 Z:-1], + [CIVector vectorWithX:2 Y:0 Z:-2], + [CIVector vectorWithX:1 Y:0 Z:-1], + nil]; +} + +- (CIImage *)outputImage +{ + CISampler *image = [CISampler samplerWithImage:inputImage]; + NSDictionary *applyOptions = [NSDictionary dictionaryWithObjectsAndKeys:[image definition], kCIApplyOptionDefinition, nil]; + + CIImage *convolveX = [self apply:convolveKernel arguments:[self xConvolveArgsWithBumpMap:image] options:applyOptions]; + CIImage *convolveY = [self apply:convolveKernel arguments:[self yConvolveArgsWithBumpMap:image] options:applyOptions]; + CISampler *samplerX = [CISampler samplerWithImage:convolveX]; + CISampler *samplerY = [CISampler samplerWithImage:convolveY]; + + NSArray *normalMapArgs = [NSArray arrayWithObjects:samplerX, samplerY, image, inputSurfaceScale, nil]; + return [self apply:normalMapKernel arguments:normalMapArgs options:applyOptions]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKPointLightFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKPointLightFilter.cikernel new file mode 100644 index 0000000..fd0a851 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKPointLightFilter.cikernel @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +kernel vec4 genPointLight(sampler normalMap, vec3 lightPos, float surfaceScale) +{ + vec2 pos = samplerCoord(normalMap); + vec3 P = vec3(pos.x, pos.y, surfaceScale * sample(normalMap, pos).a); + vec3 L = lightPos - P; + L = normalize(L); + return vec4(L.x, L.y, L.z, 1.0); +} diff --git a/WebCore/svg/graphics/filters/cg/WKPointLightFilter.h b/WebCore/svg/graphics/filters/cg/WKPointLightFilter.h new file mode 100644 index 0000000..58ec689 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKPointLightFilter.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKPointLightFilter : CIFilter { + CIImage *inputNormalMap; + CIVector *inputLightPosition; + NSNumber *inputSurfaceScale; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKPointLightFilter.m b/WebCore/svg/graphics/filters/cg/WKPointLightFilter.m new file mode 100644 index 0000000..331207e --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKPointLightFilter.m @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import "config.h" +#import "WKPointLightFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *pointLightFilter = nil; + +@implementation WKPointLightFilter + ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKPointLight" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Point Light", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + [NSDictionary dictionaryWithObjectsAndKeys: + kCIAttributeTypePosition3, kCIAttributeType, + nil], @"inputLightPosition", + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!pointLightFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKPointLightFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + pointLightFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + return [self apply:pointLightFilter, inputNormalMap, inputLightPosition, inputSurfaceScale, nil]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKSpecularLightingFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKSpecularLightingFilter.cikernel new file mode 100644 index 0000000..64228f0 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKSpecularLightingFilter.cikernel @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +kernel vec4 basic(sampler inputNormalVectors, sampler inputLightVectors, __color inputLightingColor, float inputSurfaceScale, float inputSpecularConstant, + float inputSpecularExponent, float inputKernelUnitLengthX, float inputKernelUnitLengthY) +{ + vec2 pos = samplerCoord(inputLightVectors); + vec2 posn = samplerCoord(inputNormalVectors); + vec3 l = sample(inputLightVectors, pos).xyz; + vec3 n = sample(inputNormalVectors, posn).xyz; + vec3 h = l+vec3(0.0, 0.0, 1.0); + h = normalize(h); + float nh = inputSpecularConstant*pow((dot(n, h)), inputSpecularExponent); + vec4 res = inputLightingColor * nh; + res.a = max(res.r, res.g); + res.a = max(res.a, res.b); + return res; +} diff --git a/WebCore/svg/graphics/filters/cg/WKSpecularLightingFilter.h b/WebCore/svg/graphics/filters/cg/WKSpecularLightingFilter.h new file mode 100644 index 0000000..1b76f2b --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKSpecularLightingFilter.h @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKSpecularLightingFilter : CIFilter { + CISampler *inputNormalMap; + CISampler *inputLightVectors; + CIColor *inputLightingColor; + NSNumber *inputSurfaceScale; + NSNumber *inputSpecularConstant; + NSNumber *inputSpecularExponent; + NSNumber *inputKernelUnitLengthX; + NSNumber *inputKernelUnitLengthY; +} +@end + +#endif ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKSpecularLightingFilter.m b/WebCore/svg/graphics/filters/cg/WKSpecularLightingFilter.m new file mode 100644 index 0000000..22495ae --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKSpecularLightingFilter.m @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import "config.h" +#import "WKSpecularLightingFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *specularLightingFilter = nil; + +@implementation WKSpecularLightingFilter + ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKSpecularLighting" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Specular Lighting", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + [NSDictionary dictionaryWithObjectsAndKeys: + [CIColor colorWithRed:1.0f green:1.0f blue:1.0f alpha:1.0f], + kCIAttributeDefault, nil], @"inputLightingColor", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputSurfaceScale", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputSpecularConstant", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:0.0], kCIAttributeMin, + [NSNumber numberWithDouble:128.0], kCIAttributeMin, + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputSpecularExponent", + [NSDictionary dictionaryWithObjectsAndKeys: + kCIAttributeTypeOffset, kCIAttributeType, + nil], @"inputKernelUnitLength", + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!specularLightingFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKSpecularLightingFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + specularLightingFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + return [self apply:specularLightingFilter, inputNormalMap, inputLightVectors, inputLightingColor, inputSurfaceScale, inputSpecularConstant, + inputSpecularExponent, inputKernelUnitLengthX, inputKernelUnitLengthY, nil]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKSpotLightFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKSpotLightFilter.cikernel new file mode 100644 index 0000000..0fa83a8 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKSpotLightFilter.cikernel @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2005 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +kernel vec4 spotLightFilter(sampler lightVectors, vec3 lightDirection, float specularExponent, float cosCutoffAngle) +{ + vec2 pos = samplerCoord(lightVectors); + vec3 l = sample(lightVectors, pos).xyz; + float sl = -dot(lightDirection, l); + sl = max(sl, 0.0); + sl = pow(sl, specularExponent) * sign(sl - cosCutoffAngle); + return vec4(l.x, l.y, l.z, sl); +} diff --git a/WebCore/svg/graphics/filters/cg/WKSpotLightFilter.h b/WebCore/svg/graphics/filters/cg/WKSpotLightFilter.h new file mode 100644 index 0000000..d87beca --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKSpotLightFilter.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKSpotLightFilter : CIFilter { + CIImage *inputLightVectors; + CIVector *inputLightDirection; + NSNumber *inputSpecularExponent; + NSNumber *inputLimitingConeAngle; +} +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKSpotLightFilter.m b/WebCore/svg/graphics/filters/cg/WKSpotLightFilter.m new file mode 100644 index 0000000..62973ef --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKSpotLightFilter.m @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2005 Apple Computer, Inc. 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. + */ + +#import "config.h" +#import "WKSpotLightFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *spotLightFilter = nil; + +@implementation WKSpotLightFilter + ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKSpotLight" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Spot Light", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + [NSDictionary dictionaryWithObjectsAndKeys: + kCIAttributeTypePosition3, kCIAttributeType, + nil], @"inputLightDirection", + [NSDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithDouble:1.0], kCIAttributeDefault, + [NSNumber numberWithDouble:1.0], kCIAttributeIdentity, + kCIAttributeTypeScalar, kCIAttributeType, + nil], @"inputSpecularExponent", + [NSDictionary dictionaryWithObjectsAndKeys: + kCIAttributeTypeAngle, kCIAttributeType, + nil], @"inputLimitingConeAngle", + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!spotLightFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKSpotLightFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + spotLightFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + float coscutoff = cosf([inputLimitingConeAngle floatValue]); + if (coscutoff < 0) + coscutoff = -coscutoff; + return [self apply:spotLightFilter, inputLightVectors, inputLightDirection, inputSpecularExponent, [NSNumber numberWithFloat:coscutoff], nil]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/filters/cg/WKTableTransferFilter.cikernel b/WebCore/svg/graphics/filters/cg/WKTableTransferFilter.cikernel new file mode 100644 index 0000000..19dfcdf --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKTableTransferFilter.cikernel @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +/* For some reason CI is ignoring the request to interpolate the colour returned + * when we sample the lookup table. Therefore it is necessary to implement the + * blend operation ourselves. + */ +kernel vec4 tableTransfer(sampler image, sampler table, vec4 rgbaSelector, float maxIndex) +{ + vec4 C = sample(image, samplerCoord(image)); + float k = dot(rgbaSelector, C) * maxIndex; + float t = fract(k); + k = floor(k); + vec4 res = sample(table, vec2(k, 0.0))*(1.0-t)+sample(table, vec2(k+1.0, 0.0))*(t); + return res; +} diff --git a/WebCore/svg/graphics/filters/cg/WKTableTransferFilter.h b/WebCore/svg/graphics/filters/cg/WKTableTransferFilter.h new file mode 100644 index 0000000..34adf00 --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKTableTransferFilter.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import <QuartzCore/CoreImage.h> + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +@interface WKTableTransferFilter : CIFilter { + CIImage *inputImage; + CIImage *inputTable; + CIVector *inputSelector; +} + +@end + +#endif diff --git a/WebCore/svg/graphics/filters/cg/WKTableTransferFilter.m b/WebCore/svg/graphics/filters/cg/WKTableTransferFilter.m new file mode 100644 index 0000000..55d7c9d --- /dev/null +++ b/WebCore/svg/graphics/filters/cg/WKTableTransferFilter.m @@ -0,0 +1,76 @@ +/* + * Copyright (C) 2006 Oliver Hunt <ojh16@student.canterbury.ac.nz>. 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 THE AUTHOR ``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 THE AUTHOR 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. + */ + +#import "config.h" +#import "WKTableTransferFilter.h" + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +static CIKernel *tableTransferFilter = nil; + +@implementation WKTableTransferFilter ++ (void)initialize +{ + [CIFilter registerFilterName:@"WKTableTransfer" + constructor:self + classAttributes:[NSDictionary dictionaryWithObjectsAndKeys: + @"WebKit Table Transfer", kCIAttributeFilterDisplayName, + [NSArray arrayWithObjects:kCICategoryStylize, kCICategoryVideo, + kCICategoryStillImage, kCICategoryNonSquarePixels,nil], kCIAttributeFilterCategories, + [NSDictionary dictionaryWithObjectsAndKeys: + kCIAttributeTypeGradient, kCIAttributeType, + nil], @"inputTable", + nil]]; +} + ++ (CIFilter *)filterWithName:(NSString *)name +{ + return [[[self alloc] init] autorelease]; +} + +- (id)init +{ + if (!tableTransferFilter) { + NSBundle *bundle = [NSBundle bundleForClass:[self class]]; + NSString *kernelFile = [bundle pathForResource:@"WKTableTransferFilter" ofType:@"cikernel"]; + NSString *code = [NSString stringWithContentsOfFile:kernelFile encoding:NSUTF8StringEncoding error:0]; + NSArray *kernels = [CIKernel kernelsWithString:code]; + tableTransferFilter = [[kernels objectAtIndex:0] retain]; + } + return [super init]; +} + +- (CIImage *)outputImage +{ + CISampler *inputSampler = [CISampler samplerWithImage: inputImage]; + CISampler *tableSampler = [CISampler samplerWithImage: inputTable keysAndValues:kCISamplerFilterMode, kCISamplerFilterLinear, kCISamplerWrapMode, kCISamplerWrapClamp, nil]; + NSArray *args = [NSArray arrayWithObjects:inputSampler, tableSampler, inputSelector, + [NSNumber numberWithDouble:[inputTable extent].size.width - 1.0f], @"definition", [inputSampler definition], nil]; + return [self apply:tableTransferFilter arguments:args options:nil]; +} + +@end + +#endif // ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/mac/SVGResourceFilterPlatformDataMac.h b/WebCore/svg/graphics/mac/SVGResourceFilterPlatformDataMac.h new file mode 100644 index 0000000..3236ee5 --- /dev/null +++ b/WebCore/svg/graphics/mac/SVGResourceFilterPlatformDataMac.h @@ -0,0 +1,65 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * 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 SVGResourceFilterPlatformDataMac_h +#define SVGResourceFilterPlatformDataMac_h + +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#include "SVGResourceFilter.h" + +#include <ApplicationServices/ApplicationServices.h> +#include <wtf/RetainPtr.h> + +@class CIImage; +@class CIFilter; +@class CIContext; +@class NSArray; +@class NSMutableDictionary; + +namespace WebCore { + class SVGResourceFilterPlatformDataMac : public SVGResourceFilterPlatformData { + public: + SVGResourceFilterPlatformDataMac(SVGResourceFilter*); + virtual ~SVGResourceFilterPlatformDataMac(); + + CIImage* imageForName(const String&) const; + void setImageForName(CIImage*, const String&); + + void setOutputImage(const SVGFilterEffect*, CIImage*); + CIImage* inputImage(const SVGFilterEffect*); + + NSArray* getCIFilterStack(CIImage* inputImage, const FloatRect& bbox); + + CIContext* m_filterCIContext; + CGLayerRef m_filterCGLayer; + RetainPtr<NSMutableDictionary> m_imagesByName; + SVGResourceFilter* m_filter; + }; +} + +#endif // #if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#endif // SVGResourceFilterPlatformDataMac_h diff --git a/WebCore/svg/graphics/mac/SVGResourceFilterPlatformDataMac.mm b/WebCore/svg/graphics/mac/SVGResourceFilterPlatformDataMac.mm new file mode 100644 index 0000000..c031bbc --- /dev/null +++ b/WebCore/svg/graphics/mac/SVGResourceFilterPlatformDataMac.mm @@ -0,0 +1,129 @@ +/* + * Copyright (C) 2007 Eric Seidel <eric@webkit.org> + * + * 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" +#if ENABLE(SVG) && ENABLE(SVG_FILTERS) + +#include "SVGResourceFilterPlatformDataMac.h" +#include <QuartzCore/CoreImage.h> + +namespace WebCore { + +static const char* const SVGPreviousFilterOutputName = "__previousOutput__"; + +SVGResourceFilterPlatformDataMac::SVGResourceFilterPlatformDataMac(SVGResourceFilter* filter) + : m_filterCIContext(0) + , m_filterCGLayer(0) + , m_imagesByName(AdoptNS, [[NSMutableDictionary alloc] init]) + , m_filter(filter) +{ +} + +SVGResourceFilterPlatformDataMac::~SVGResourceFilterPlatformDataMac() +{ + ASSERT(!m_filterCGLayer); + ASSERT(!m_filterCIContext); +} + + +NSArray* SVGResourceFilterPlatformDataMac::getCIFilterStack(CIImage* inputImage, const FloatRect& bbox) +{ + NSMutableArray* filterEffects = [NSMutableArray array]; + + setImageForName(inputImage, "SourceGraphic"); // input + + for (unsigned int i = 0; i < m_filter->effects().size(); i++) { + CIFilter* filter = m_filter->effects()[i]->getCIFilter(bbox); + if (filter) + [filterEffects addObject:filter]; + } + + [m_imagesByName.get() removeAllObjects]; // clean up before next time. + + return filterEffects; +} + +static inline CIImage* alphaImageForImage(CIImage* image) +{ + CIFilter* onlyAlpha = [CIFilter filterWithName:@"CIColorMatrix"]; + CGFloat zero[4] = {0, 0, 0, 0}; + [onlyAlpha setDefaults]; + [onlyAlpha setValue:image forKey:@"inputImage"]; + [onlyAlpha setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputRVector"]; + [onlyAlpha setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputGVector"]; + [onlyAlpha setValue:[CIVector vectorWithValues:zero count:4] forKey:@"inputBVector"]; + return [onlyAlpha valueForKey:@"outputImage"]; +} + +CIImage* SVGResourceFilterPlatformDataMac::imageForName(const String& name) const +{ + return [m_imagesByName.get() objectForKey:name]; +} + +void SVGResourceFilterPlatformDataMac::setImageForName(CIImage* image, const String& name) +{ + [m_imagesByName.get() setValue:image forKey:name]; +} + +void SVGResourceFilterPlatformDataMac::setOutputImage(const SVGFilterEffect* filterEffect, CIImage* output) +{ + if (!filterEffect->result().isEmpty()) + setImageForName(output, filterEffect->result()); + + setImageForName(output, SVGPreviousFilterOutputName); +} + +CIImage* SVGResourceFilterPlatformDataMac::inputImage(const SVGFilterEffect* filterEffect) +{ + if (filterEffect->in().isEmpty()) { + CIImage* inImage = imageForName(SVGPreviousFilterOutputName); + + if (!inImage) + inImage = imageForName("SourceGraphic"); + + return inImage; + } else if (filterEffect->in() == "SourceAlpha") { + CIImage* sourceAlpha = imageForName(filterEffect->in()); + + if (!sourceAlpha) { + CIImage* sourceGraphic = imageForName("SourceGraphic"); + + if (!sourceGraphic) + return nil; + + sourceAlpha = alphaImageForImage(sourceGraphic); + setImageForName(sourceAlpha, "SourceAlpha"); + } + + return sourceAlpha; + } + + return imageForName(filterEffect->in()); +} + + +} + +#endif // #if ENABLE(SVG) && ENABLE(SVG_FILTERS) diff --git a/WebCore/svg/graphics/qt/RenderPathQt.cpp b/WebCore/svg/graphics/qt/RenderPathQt.cpp new file mode 100644 index 0000000..8bee8b8 --- /dev/null +++ b/WebCore/svg/graphics/qt/RenderPathQt.cpp @@ -0,0 +1,89 @@ +/* + Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org> + 2004, 2005, 2006 Rob Buis <buis@kde.org> + 2005 Eric Seidel <eric.seidel@kdemail.net> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" +#include "RenderPath.h" +#include "SVGRenderStyle.h" +#include "SVGPaintServer.h" + +#include <QDebug> +#include <QPainterPathStroker> + +namespace WebCore { + +bool RenderPath::strokeContains(const FloatPoint& point, bool requiresStroke) const +{ + if (path().isEmpty()) + return false; + + if (requiresStroke && !SVGPaintServer::strokePaintServer(style(), this)) + return false; + + return false; +} + +static QPainterPath getPathStroke(const QPainterPath &path, const RenderObject* object, const RenderStyle* style) +{ + QPainterPathStroker s; + s.setWidth(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0)); + + if (style->svgStyle()->capStyle() == ButtCap) + s.setCapStyle(Qt::FlatCap); + else if (style->svgStyle()->capStyle() == RoundCap) + s.setCapStyle(Qt::RoundCap); + + if (style->svgStyle()->joinStyle() == MiterJoin) { + s.setJoinStyle(Qt::MiterJoin); + s.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit()); + } else if(style->svgStyle()->joinStyle() == RoundJoin) + s.setJoinStyle(Qt::RoundJoin); + + const DashArray& dashes = WebCore::dashArrayFromRenderingStyle(style); + double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0); + + unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0; + if(dashLength) { + QVector<qreal> pattern; + unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2; + + for(unsigned int i = 0; i < count; i++) + pattern.append(dashes[i % dashLength] / (float)s.width()); + + s.setDashPattern(pattern); + + Q_UNUSED(dashOffset); + // TODO: dash-offset, does/will qt4 API allow it? (Rob) + } + + return s.createStroke(path); +} + +FloatRect RenderPath::strokeBBox() const +{ + QPainterPath outline = getPathStroke(*(path().platformPath()), this, style()); + return outline.boundingRect(); +} + +} + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/qt/SVGPaintServerGradientQt.cpp b/WebCore/svg/graphics/qt/SVGPaintServerGradientQt.cpp new file mode 100644 index 0000000..7240c49 --- /dev/null +++ b/WebCore/svg/graphics/qt/SVGPaintServerGradientQt.cpp @@ -0,0 +1,110 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServerGradient.h" + +#include "GraphicsContext.h" +#include "RenderObject.h" +#include "RenderStyle.h" +#include "SVGGradientElement.h" + +#include <QPainter> +#include <QPainterPath> +#include <QColor> +#include <QGradient> + +namespace WebCore { + +// Helper function used by linear & radial gradient +void SVGPaintServerGradient::fillColorArray(QGradient& gradient, const Vector<SVGGradientStop>& stops, + float opacity) const +{ + for (unsigned i = 0; i < stops.size(); ++i) { + float offset = stops[i].first; + Color color = stops[i].second; + + QColor c(color.red(), color.green(), color.blue()); + c.setAlpha(int(color.alpha() * opacity)); + + gradient.setColorAt(offset, c); + } +} + +bool SVGPaintServerGradient::setup(GraphicsContext*& context, const RenderObject* object, + SVGPaintTargetType type, bool isPaintingText) const +{ + m_ownerElement->buildGradient(); + + QPainter* painter(context ? context->platformContext() : 0); + Q_ASSERT(painter); + + QPainterPath* path(context ? context->currentPath() : 0); + Q_ASSERT(path); + + RenderStyle* renderStyle = object->style(); + + QGradient gradient = setupGradient(context, object); + + painter->setPen(Qt::NoPen); + painter->setBrush(Qt::NoBrush); + + if (spreadMethod() == SPREADMETHOD_REPEAT) + gradient.setSpread(QGradient::RepeatSpread); + else if (spreadMethod() == SPREADMETHOD_REFLECT) + gradient.setSpread(QGradient::ReflectSpread); + else + gradient.setSpread(QGradient::PadSpread); + double opacity = 1.0; + + if ((type & ApplyToFillTargetType) && renderStyle->svgStyle()->hasFill()) { + fillColorArray(gradient, gradientStops(), opacity); + + QBrush brush(gradient); + brush.setMatrix(gradientTransform()); + + painter->setBrush(brush); + context->setFillRule(renderStyle->svgStyle()->fillRule()); + } + + if ((type & ApplyToStrokeTargetType) && renderStyle->svgStyle()->hasStroke()) { + fillColorArray(gradient, gradientStops(), opacity); + + QPen pen; + QBrush brush(gradient); + brush.setMatrix(gradientTransform()); + + setPenProperties(object, renderStyle, pen); + pen.setBrush(brush); + + painter->setPen(pen); + } + + return true; +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/qt/SVGPaintServerLinearGradientQt.cpp b/WebCore/svg/graphics/qt/SVGPaintServerLinearGradientQt.cpp new file mode 100644 index 0000000..69934ab --- /dev/null +++ b/WebCore/svg/graphics/qt/SVGPaintServerLinearGradientQt.cpp @@ -0,0 +1,65 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServerLinearGradient.h" +#include "SVGGradientElement.h" + +#include "GraphicsContext.h" +#include "RenderPath.h" + +#include <QLinearGradient> +#include <QPainter> +#include <QPainterPath> + +namespace WebCore { + +QGradient SVGPaintServerLinearGradient::setupGradient(GraphicsContext*& context, const RenderObject* object) const +{ + QPainterPath* path(context ? context->currentPath() : 0); + Q_ASSERT(path); + + double x1, x2, y1, y2; + if (boundingBoxMode()) { + QRectF bbox = path->boundingRect(); + x1 = bbox.x(); + y1 = bbox.y(); + x2 = bbox.x() + bbox.width(); + y2 = bbox.y() + bbox.height(); + } else { + x1 = gradientStart().x(); + y1 = gradientStart().y(); + x2 = gradientEnd().x(); + y2 = gradientEnd().y(); + } + + QLinearGradient gradient(QPointF(x1, y1), QPointF(x2, y2)); + + return gradient; +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/qt/SVGPaintServerPatternQt.cpp b/WebCore/svg/graphics/qt/SVGPaintServerPatternQt.cpp new file mode 100644 index 0000000..119e0b0 --- /dev/null +++ b/WebCore/svg/graphics/qt/SVGPaintServerPatternQt.cpp @@ -0,0 +1,79 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServerPattern.h" + +namespace WebCore { + +bool SVGPaintServerPattern::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const +{ + // FIXME: Reactivate old pattern code + +/* + QPainter* painter(context ? context->platformContext() : 0); + Q_ASSERT(painter); + + QPainterPath* _path = static_cast<QPainterPath*>(qtContext->path()); + Q_ASSERT(_path != 0); + + RenderStyle* renderStyle = object->style(); + + painter->setPen(Qt::NoPen); + painter->setBrush(Qt::NoBrush); + QImage* patternimage = new QImage(tile()->bits(), tile()->width(), tile()->height(), QImage::Format_ARGB32_Premultiplied); + patternimage->setAlphaBuffer(true); + if (type & APPLY_TO_FILL) { + //QColor c = color(); + //c.setAlphaF(style->fillPainter()->opacity() * style->opacity() * opacity()); + KRenderingFillPainter fillPainter = KSVGPainterFactory::fillPainter(renderStyle, object); + QBrush brush(QPixmap::fromImage(*patternimage)); + _path->setFillRule(fillPainter.fillRule() == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill); + painter->setBrush(brush); + } + if (type & APPLY_TO_STROKE) { + //QColor c = color(); + //c.setAlphaF(style->strokePainter()->opacity() * style->opacity() * opacity()); + KRenderingStrokePainter strokePainter = KSVGPainterFactory::strokePainter(renderStyle, object); + + QPen pen; + QBrush brush(QPixmap::fromImage(*patternimage)); + + setPenProperties(strokePainter, pen); + pen.setBrush(brush); + painter->setPen(pen); + } + + painter->drawPath(*_path); + + delete patternimage; +*/ + + return true; +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/qt/SVGPaintServerQt.cpp b/WebCore/svg/graphics/qt/SVGPaintServerQt.cpp new file mode 100644 index 0000000..db20347 --- /dev/null +++ b/WebCore/svg/graphics/qt/SVGPaintServerQt.cpp @@ -0,0 +1,104 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServer.h" + +#include "GraphicsContext.h" +#include "SVGRenderStyle.h" +#include "RenderObject.h" + +#include <QPainter> +#include <QVector> + +namespace WebCore { + +void SVGPaintServer::setPenProperties(const RenderObject* object, const RenderStyle* style, QPen& pen) const +{ + pen.setWidthF(SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeWidth(), 1.0)); + + if (style->svgStyle()->capStyle() == ButtCap) + pen.setCapStyle(Qt::FlatCap); + else if (style->svgStyle()->capStyle() == RoundCap) + pen.setCapStyle(Qt::RoundCap); + + if (style->svgStyle()->joinStyle() == MiterJoin) { + pen.setJoinStyle(Qt::MiterJoin); + pen.setMiterLimit((qreal) style->svgStyle()->strokeMiterLimit()); + } else if(style->svgStyle()->joinStyle() == RoundJoin) + pen.setJoinStyle(Qt::RoundJoin); + + const DashArray& dashes = WebCore::dashArrayFromRenderingStyle(style); + double dashOffset = SVGRenderStyle::cssPrimitiveToLength(object, style->svgStyle()->strokeDashOffset(), 0.0); + + unsigned int dashLength = !dashes.isEmpty() ? dashes.size() : 0; + if(dashLength) { + QVector<qreal> pattern; + unsigned int count = (dashLength % 2) == 0 ? dashLength : dashLength * 2; + + for(unsigned int i = 0; i < count; i++) + pattern.append(dashes[i % dashLength] / (float)pen.widthF()); + + pen.setDashPattern(pattern); + + Q_UNUSED(dashOffset); + // TODO: dash-offset, does/will qt4 API allow it? (Rob) + } +} + +void SVGPaintServer::draw(GraphicsContext*& context, const RenderObject* path, SVGPaintTargetType type) const +{ + if (!setup(context, path, type)) + return; + + renderPath(context, path, type); + teardown(context, path, type); +} + +void SVGPaintServer::teardown(GraphicsContext*&, const RenderObject*, SVGPaintTargetType, bool isPaintingText) const +{ + // no-op +} + +void SVGPaintServer::renderPath(GraphicsContext*& context, const RenderObject* path, SVGPaintTargetType type) const +{ + RenderStyle* renderStyle = path->style(); + + QPainter* painter(context ? context->platformContext() : 0); + Q_ASSERT(painter); + + QPainterPath* painterPath(context ? context->currentPath() : 0); + Q_ASSERT(painterPath); + + if ((type & ApplyToFillTargetType) && renderStyle->svgStyle()->hasFill()) + painter->fillPath(*painterPath, painter->brush()); + + if ((type & ApplyToStrokeTargetType) && renderStyle->svgStyle()->hasStroke()) + painter->strokePath(*painterPath, painter->pen()); +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/qt/SVGPaintServerRadialGradientQt.cpp b/WebCore/svg/graphics/qt/SVGPaintServerRadialGradientQt.cpp new file mode 100644 index 0000000..95d71a3 --- /dev/null +++ b/WebCore/svg/graphics/qt/SVGPaintServerRadialGradientQt.cpp @@ -0,0 +1,98 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServerRadialGradient.h" + +#include "GraphicsContext.h" +#include "RenderPath.h" + +#include <math.h> +#include <QPainter> +#include <QPainterPath> +#include <QRadialGradient> + +namespace WebCore { + +QGradient SVGPaintServerRadialGradient::setupGradient(GraphicsContext*& context, const RenderObject* object) const +{ + QPainter* painter(context ? context->platformContext() : 0); + Q_ASSERT(painter); + + QPainterPath* path(context ? context->currentPath() : 0); + Q_ASSERT(path); + + RenderStyle* renderStyle = object->style(); + + QMatrix mat = painter->matrix(); + + double cx, fx, cy, fy, r; + if (boundingBoxMode()) { + QRectF bbox = path->boundingRect(); + cx = double(bbox.left()) + (double(gradientCenter().x() / 100.0) * double(bbox.width())); + cy = double(bbox.top()) + (double(gradientCenter().y() / 100.0) * double(bbox.height())); + fx = double(bbox.left()) + (double(gradientFocal().x() / 100.0) * double(bbox.width())) - cx; + fy = double(bbox.top()) + (double(gradientFocal().y() / 100.0) * double(bbox.height())) - cy; + r = double(gradientRadius() / 100.0) * (sqrt(pow(bbox.width(), 2) + pow(bbox.height(), 2))); + + float width = bbox.width(); + float height = bbox.height(); + + int diff = int(width - height); // allow slight tolerance + if (!(diff > -2 && diff < 2)) { + // make elliptical or circular depending on bbox aspect ratio + float ratioX = (width / height); + float ratioY = (height / width); + mat.scale((width > height) ? 1 : ratioX, (width > height) ? ratioY : 1); + } + } else { + cx = gradientCenter().x(); + cy = gradientCenter().y(); + + fx = gradientFocal().x(); + fy = gradientFocal().y(); + + fx -= cx; + fy -= cy; + + r = gradientRadius(); + } + + if (sqrt(fx * fx + fy * fy) > r) { + // Spec: If (fx, fy) lies outside the circle defined by (cx, cy) and r, set (fx, fy) + // to the point of intersection of the line through (fx, fy) and the circle. + double angle = atan2(fy, fx); + fx = int(cos(angle) * r) - 1; + fy = int(sin(angle) * r) - 1; + } + + QRadialGradient gradient(QPointF(cx, cy), gradientRadius(), QPointF(fx + cx, fy + cy)); + + return gradient; +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/qt/SVGPaintServerSolidQt.cpp b/WebCore/svg/graphics/qt/SVGPaintServerSolidQt.cpp new file mode 100644 index 0000000..7b06a03 --- /dev/null +++ b/WebCore/svg/graphics/qt/SVGPaintServerSolidQt.cpp @@ -0,0 +1,71 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGPaintServerSolid.h" + +#include "GraphicsContext.h" +#include "RenderPath.h" + +#include <QPainter> + +namespace WebCore { + +bool SVGPaintServerSolid::setup(GraphicsContext*& context, const RenderObject* object, SVGPaintTargetType type, bool isPaintingText) const +{ + QPainter* painter(context ? context->platformContext() : 0); + Q_ASSERT(painter); + + RenderStyle* renderStyle = object->style(); + // TODO? painter->setOpacity(renderStyle->opacity()); + + QColor c = color(); + + if ((type & ApplyToFillTargetType) && renderStyle->svgStyle()->hasFill()) { + c.setAlphaF(renderStyle->svgStyle()->fillOpacity()); + + QBrush brush(c); + painter->setBrush(brush); + context->setFillRule(renderStyle->svgStyle()->fillRule()); + + /* if(isPaintingText()) ... */ + } + + if ((type & ApplyToStrokeTargetType) && renderStyle->svgStyle()->hasStroke()) { + c.setAlphaF(renderStyle->svgStyle()->strokeOpacity()); + + QPen pen(c); + setPenProperties(object, renderStyle, pen); + painter->setPen(pen); + + /* if(isPaintingText()) ... */ + } + + return true; +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/qt/SVGResourceClipperQt.cpp b/WebCore/svg/graphics/qt/SVGResourceClipperQt.cpp new file mode 100644 index 0000000..42d3855 --- /dev/null +++ b/WebCore/svg/graphics/qt/SVGResourceClipperQt.cpp @@ -0,0 +1,127 @@ +/* + Copyright (C) 2004, 2005, 2006 Nikolas Zimmermann <wildfox@kde.org> + 2004, 2005, 2006 Rob Buis <buis@kde.org> + 2005 Apple Computer, Inc. + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGResourceClipper.h" + +#include "GraphicsContext.h" + +#include <QPainter> +#include <QPainterPath> + +namespace WebCore { + +void SVGResourceClipper::applyClip(GraphicsContext* context, const FloatRect& boundingBox) const +{ + if (m_clipData.clipData().size() < 1) + return; + + context->beginPath(); + + QPainterPath newPath; + + bool heterogenousClipRules = false; + WindRule clipRule = m_clipData.clipData()[0].windRule; + + unsigned int clipDataCount = m_clipData.clipData().size(); + for (unsigned int x = 0; x < clipDataCount; x++) { + ClipData clipData = m_clipData.clipData()[x]; + if (clipData.windRule != clipRule) + heterogenousClipRules = true; + + QPainterPath path = *(clipData.path.platformPath()); + if (path.isEmpty()) + continue; + + if (!newPath.isEmpty()) + newPath.closeSubpath(); + + // Respect clipping units... + QMatrix transform; + + if (clipData.bboxUnits) { + transform.translate(boundingBox.x(), boundingBox.y()); + transform.scale(boundingBox.width(), boundingBox.height()); + } + + // TODO: support heterogenous clip rules! + //clipRule = (clipData.windRule() == RULE_EVENODD ? Qt::OddEvenFill : Qt::WindingFill); + + for (int i = 0; i < path.elementCount(); ++i) { + const QPainterPath::Element &cur = path.elementAt(i); + + switch (cur.type) { + case QPainterPath::MoveToElement: + newPath.moveTo(QPointF(cur.x, cur.y) * transform); + break; + case QPainterPath::LineToElement: + newPath.lineTo(QPointF(cur.x, cur.y) * transform); + break; + case QPainterPath::CurveToElement: + { + const QPainterPath::Element &c1 = path.elementAt(i + 1); + const QPainterPath::Element &c2 = path.elementAt(i + 2); + + Q_ASSERT(c1.type == QPainterPath::CurveToDataElement); + Q_ASSERT(c2.type == QPainterPath::CurveToDataElement); + + newPath.cubicTo(QPointF(cur.x, cur.y) * transform, + QPointF(c1.x, c1.y) * transform, + QPointF(c2.x, c2.y) * transform); + + i += 2; + break; + } + case QPainterPath::CurveToDataElement: + Q_ASSERT(false); + break; + } + } + } + + if (m_clipData.clipData().size()) { + // FIXME! + // We don't currently allow for heterogenous clip rules. + // we would have to detect such, draw to a mask, and then clip + // to that mask + // if (!CGContextIsPathEmpty(cgContext)) { + if (clipRule == RULE_EVENODD) + newPath.setFillRule(Qt::OddEvenFill); + else + newPath.setFillRule(Qt::WindingFill); + // } + } + + QPainter* painter(context ? context->platformContext() : 0); + Q_ASSERT(painter); + + painter->setClipPath(newPath); +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/qt/SVGResourceFilterQt.cpp b/WebCore/svg/graphics/qt/SVGResourceFilterQt.cpp new file mode 100644 index 0000000..557f3dd --- /dev/null +++ b/WebCore/svg/graphics/qt/SVGResourceFilterQt.cpp @@ -0,0 +1,48 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) && ENABLE(SVG_EXPERIMENTAL_FEATURES) +#include "SVGResourceFilter.h" + +namespace WebCore { + +SVGResourceFilterPlatformData* SVGResourceFilter::createPlatformData() +{ + return 0; +} + +void SVGResourceFilter::prepareFilter(GraphicsContext*&, const FloatRect&) +{ + // FIXME: implement me :-) +} + +void SVGResourceFilter::applyFilter(GraphicsContext*&, const FloatRect&) +{ + // FIXME: implement me :-) +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet diff --git a/WebCore/svg/graphics/qt/SVGResourceMaskerQt.cpp b/WebCore/svg/graphics/qt/SVGResourceMaskerQt.cpp new file mode 100644 index 0000000..2b89bac --- /dev/null +++ b/WebCore/svg/graphics/qt/SVGResourceMaskerQt.cpp @@ -0,0 +1,38 @@ +/* + Copyright (C) 2006 Nikolas Zimmermann <wildfox@kde.org> + + This file is part of the KDE project + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + aint with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "config.h" + +#if ENABLE(SVG) +#include "SVGResourceMasker.h" + +namespace WebCore { + +void SVGResourceMasker::applyMask(GraphicsContext*, const FloatRect&) +{ + // FIXME: implement me :-) +} + +} // namespace WebCore + +#endif + +// vim:ts=4:noet |