Giter VIP home page Giter VIP logo

drawkit's Introduction

DrawKit Build Status Carthage compatible podspec Version podspec Platform

DrawKit is an illustration and vector artwork framework for macOS. See http://drawkit.github.io for full documentation and a getting started guide.

Quick Start

Using Terminal.app on macOS, clone the DrawKit project and open the first example in Xcode:

git clone https://github.com/DrawKit/DrawKit DrawKit
open DrawKit/Examples/0-no-code/drawkit-no-code.xcodeproj

Try pasting in text or dragging an image onto the canvas of the no code example application.

DrawKit Demos

For a full demonstration of DrawKit, try the DrawDemo application. Complete with source code this application highlights what is possible with DrawKit.

DKMiniDemo and source code are great for learning about DrawKit.

How We Work Together / Contributing

This project is maintained thanks to the contributors who send pull requests. @grahammiln typically deals with administrative tasks and contributors do the rest.

We will merge any pull request that adds something useful and does not break existing code, and will often grant commit access to the repository.

If you're an active user and want to be a maintainer, please get in touch.

DrawKit needs your help! There are numerous warnings to address and minor updates needed. Pick something easy and make a difference. Please help maintain and support this incredible framework.

Package Managers

Carthage and CocoaPods are dependency managers. They aim to help automate and simplify the use of 3rd-party libraries like DrawKit in your Xcode projects.

Carthage

For Carthage, append the following to your project's Cartfile:

github "DrawKit/DrawKit" 

CocoaPods

For CocoaPods, append the following to your project's Podfile:

platform :osx, '10.7'
pod "DrawKit"

Overview

DrawKit is a software framework that enables the macOS Cocoa developer to rapidly implement vector drawing and illustration features in a custom application. It is comprehensive, powerful and complete, but it is also highly modular so you can make use of only those parts that you need, or go the whole hog and drop it in as a complete vector drawing solution.

DrawKit sample capabilities

Taking its cue from Cocoa's powerful text handling model, DrawKit provides a general purpose and complete drawing model that can be deployed with very little (or in the most general case, no) code at all. The defaults for most classes and created objects have been selected to give a working system out of the box with minimal set up. As you might expect, the more your requirements deviate from the defaults, the more customising you will need to do, but DrawKit has been designed to make this as straightforward as possible without compromising on the graphical power available. Many classes can be operated in a variety of modes for the most obvious of customisations, and can of course be subclassed when necessary to provide more divergent behaviour.

Where possible, familiar Cocoa idioms and conventions are used to ensure that the Cocoa developer will be able to start using DrawKit as if it were a natural extension of the standard Cocoa frameworks (which in a way, of course, it is).

Generally speaking, DrawKit provides the following:

  • A general-purpose "drawing" data model consisting of unlimited layers organised hierarchically.
  • Separation into model, view and controller classes gives genuine architectural flexibility
  • Built-in classes for shapes and path objects, and various derivations of them to cover most typical needs.
  • Standard grid and guide layers supporting object snapping and any "real world" measurement system you need.
  • Built-in selection of objects and targeting of the selection for commands and user events.
  • Separation of an object's geometry from its appearance gives incredible flexibility for creating exciting graphics.
  • Attachment of unlimited arbitrary user data to all objects.
  • Style objects can be optionally shared by multiple objects, and contain an entire tree of rasterizers for drawing. This goes way beyond the classic "one stroke and one fill per object" that many drawing applications adopt (though if this is what you want it's easy to implement).
  • Built-in gradients, vector pattern fills and hatches.
  • Interactively edit any bezier path.
  • Image objects support all the formats that Cocoa itself supports.
  • Text objects.
  • Group objects to any degree of nesting. Groups can be rotated, scaled and moved like any shape.
  • Many path operations including boolean (set) operations (requires the inclusion of additional code).
  • Tool-based drawing, editing and selection operations.
  • Export to PDF or any raster image format, as well as its own keyed archive format.
  • Built-in Undo.
  • Supports multiple views and multiple view classes.
  • Various caching and quality modulating techniques to improve performance when interacting directly.

DrawKit is a moderately large framework but its architecture is straightforward. While you won't be able to learn it in half an hour, it is designed to be easy to deploy and get working with minimal configuration or fuss.

DrawKit does NOT provide a user interface except that of direct manipulation of objects, which is highly customisable. It is intended to form the core of an application or perhaps find a subsidiary role - it is not in and of itself a drawing application. Some classes are provided to help get started with building a GUI for DrawKit, such as a basic document class and a base class for an inspector type of controller.

As its name suggests, DrawKit is a kit - some assembly is required. However getting a "bare bones" system up and running should be very easy, which is intended to give the programmer confidence in the default operation of the framework, providing an excellent starting point for customising and extending DrawKit to suit your own applications' needs.

License

DrawKit is MPL2 licensed. This licence means DrawKit can be used within open source and commercial software, including products distributed on the Mac App Store.

History

Originally based on, and forked from, DrawKit 1.0b7 (2010/05/01) source code by Graham Cox.

Maintainers

See CONTRIBUTORS for a list of code level contributors.

drawkit's People

Contributors

calebmitcler avatar grahammiln avatar maddthesane avatar spiderr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

drawkit's Issues

Documentation?

I'd like to contribute to the overall usage documentation. @grahammiln I'd like start documenting things over in the github wiki -- you ok with that? I was thinking use that as a draft/adhoc place before moving it into the "official" documentation (under DrawKit/Documentation). It's also easier to contribute to the wiki with a lower barrier to entry overall.

Bezier Pen is not closing

When you draw a shape with Bezier Pen, the path is open at the end. It would be better to close the path when you bring the mouse to the starting point, because all vector illustration software has this feature. Bezier pen is supposed to work like this. Is there any way to add this feature?

Load styles from file

Hello

I want to load styles from .styles file when button is clicked, but the result is nothing. Here is my code, can you help me to find my errors please?

NSString *path = @"/Users/Mediajon/Documents/colors.styles";    
[[DKStyleRegistry sharedStyleRegistry] readFromFile:path mergeOptions:kDKReplaceExistingStyles     mergeDelegate:self];

Thanks

How to set an NSAttributedString?

Question: Is there a better way to set an NSAttributedString on a DKTextShape?

Background & Code:

I was trying to implement strikethrough via the following:

    let strokeEffect: [NSAttributedStringKey : Any] = [
      NSAttributedStringKey.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue,
      NSAttributedStringKey.strikethroughColor: NSColor.black,
    ]

    if let textShape = selectedObject as? DKTextShape {
      let text = textShape.string
      let newStrokeString = NSAttributedString(string: text, attributes: strokeEffect)
      selectedObject?.setOriginalText(newStrokeString)
    }

via debugging, it's definitely getting into selectedObject?.setOriginalText(newStrokeString) and is getting into [self setMetadataItem:[DKMetadataItem metadataItemWithAttributedString:text] forKey:kDKPrivateShapeOriginalText]; (see below for reference)

however it doesn't seem like the attribute string is getting applied.

- (void)setOriginalText:(NSAttributedString*)text
{
#if USE_107_OR_LATER_SCHEMA
	[self setMetadataItem:[DKMetadataItem metadataItemWithAttributedString:text]
				   forKey:kDKPrivateShapeOriginalText];
#else
	[self setMetadataObject:text
					 forKey:kDKPrivateShapeOriginalText];
#endif
}

Xcode 10 / Mojave / Swift 4.2 issue?

I'm getting a black rendering for my view on something that was previously working after upgrading to:

  • Xcode 10 (app store version)
  • Mojave
  • Swift 4.2

I'm downloading Xcode 9.4.1 to see if that's the issue and am going to step through it.

Anyone else seeing this?

Question - notification for when object clicked (not double clicked)?

I'm trying to figure out which notification fires for when the selected object changes? It doesn't seem to be kDKDrawableSubselectionChangedNotification.

Example:

  1. Draw 2 rectangles A & B
  2. select A
    Expect to receive a notification that a selection was made. I've got kDKDrawableDoubleClickNotification working correctly but essentially I'm looking for "kDKDrawableClickNotification"

How to add Shift Key to tool shortcuts?

Hello

How can we add shift key to the tool shortcuts? For example we want to make Rectangle Tool with Shift+R keys, what key code should be changed?

Thanks

SVG

Hello

What is the best way to add sag support to this framework?

Thanks

scrollWheel jerky zoom behavior fix: event delta of 0 means 'stop gesture'

In GCZoomView.m

  • (void)scrollWheel:(NSEvent*)theEvent

    CGFloat deltaX = [theEvent deltaX], deltaY = [theEvent deltaY], deltaZ = [theEvent deltaZ];

    double totalDelta = deltaX + deltaY + deltaZ;
    //printf( "deltaX %f deltaY %f deltaZ %f totalDelta %f", deltaX, deltaY, deltaZ, totalDelta );
    //NSLog( @"%@", [event description] );
    if ( totalDelta == 0 )
    return; // this is the indication that a trackpad gesture has 'finished'... on the iphone, i think it means 'stop animate scroll now'

diff --git a/framework/Code/GCZoomView.m b/framework/Code/GCZoomView.m
index e78be1c..ef81021 100644
--- a/framework/Code/GCZoomView.m
+++ b/framework/Code/GCZoomView.m
@@ -421,12 +421,20 @@ NSString* kDKDrawingScrollwheelSensePrefsKey = @"kDKDrawingcrollwheelSense"; //
// to what you might think. It's more intuitive if the centre point remains constant

            NSPoint p = [self centredPointInDocView];

- CGFloat delta = [theEvent deltaY];

  •           //CGFloat delta = [theEvent deltaY];
    
  •  CGFloat deltaX = [theEvent deltaX], deltaY = [theEvent deltaY], deltaZ = [theEvent deltaZ];
    
  •  double totalDelta = deltaX + deltaY + deltaZ;
    
  •  //printf( "deltaX %f deltaY %f deltaZ %f totalDelta %f", deltaX, deltaY, deltaZ, totalDelta );
    
  •  //NSLog( @"%@", [event description] );
    
  •  if ( totalDelta == 0 )
    
  •     return; // i think this is the indication that a trackpad gesture has 'finished'... on the iphone, i think it means 'stop animate scroll now'
    
  •  // [GCZoomView setScrollwheelInverted:YES];
            if ([[self class] scrollwheelInverted])
    
  •                   delta = -delta;
    
  •                   totalDelta = -totalDelta;
    
  •           [self zoomWithScrollWheelDelta:delta
    
  •           [self zoomWithScrollWheelDelta:totalDelta
                                             toCentrePoint:p];
    } else
            [super scrollWheel:theEvent];
    

Status check - ARC upgrade

I'm wondering what the status of the project is. I have forked it and am working on upgrading it to be ARC compliant.

Anyone else interested?

Swift Support

I tried using the library in a swift project and converting the example project DK Mini Demo to swift. I'm running into a few errors. The first is Value of type 'DKDrawingView' has no member 'selectDrawingTool'. Looks like the way the obj-c code is written, those methods appear private. Attached is the project.
DrawingView.zip

DKTextShape does not increase the size when text is too big.

Using a text shape and increasing the size of the font after the shape to a high value is hiding a part of the text.
Using GCDrawDemo, I have added two text shapes on the image below, first has font size 48, second has the default one:

untitled gcdrawdemo today at 10 48

Is there a way we can have the text shape resized automatically on font change?

Intent to move to new licence (MPLv2)

I am aware of concerns regarding the LGPL licence and its use within the Mac App Store. In particular the concerns about using LGPL where DRM protections are used.

Given these concerns, I intend to switch DrawKit's licence to a more permissive licence. My main objective is to ensure the continued protection for those contributing to the project and to ensure the project remains open.

I am considering moving to Mozilla Public License v2:

Black Rectangle when placed in Containing View

Hi -

This is an integration issue with Cocoa, not an issue within DrawKit (afaict).

If I do the following - it works 👍🏽

  1. create a new app Cocoa app (Xcode 9.3), add DKDrawKit + DrawSwift files
  2. drag a customview over into the ViewController, set the class on the customview to DKDrawingView
  3. run

Result = a window with the grid displayed from DKDrawingView (good!)

If I do the following, it displays a black screen 👎

Repeat steps 1 & 2
3. Drag out a TabViewController and rewire the Window to display the TabViewController
4. Place the default ViewController (with the DKDrawingView in it) into the TabViewController

Result = the tab view displays a render area of the right size, but it's rendering a black box.

I'm assuming this issue has to do with layer setup and the fact that it's now in a containing view?

DKImageShape - Drag and Drop - CGContextSetCTM: invalid context 0x0

Machine: mac 10.15.3
Xcode: 11.3.1

Summary: Anyone else seeing issues with DnD for images in DrawKit, post catalina/xcode11?

I started seeing this bug crop up recently with drag-n-drop operations, specifically once I a place an image on a DKDrawingView and start dragging it around.

Using default DrawKit primitives (box, line, etc.) does not produce this issue.

I have to set the environment variable "CG_CONTEXT_SHOW_BACKTRACE" to produce the stack trace below. Afaict, everything still seems to work properly.

It happens regardless if it's in a DKShapeGroup.

Image is loaded as a literal from an asset catalog, as a universal PDF.

Stacktrace:

2020-02-17 09:56:15.559928-0700 MyApp[49217:5498717] [com.myapp.myapp] CGContextSetCTM: invalid context 0x0. Backtrace:
<-[NSImageRep drawInRect:]+505>
 <-[NSImageRep CGImageForProposedRect:context:hints:]+325>
  <__74-[NSImageRep drawInRect:fromRect:operation:fraction:respectFlipped:hints:]_block_invoke+910>
   <-[NSImageRep drawInRect:fromRect:operation:fraction:respectFlipped:hints:]+946>
    <__71-[NSImage drawInRect:fromRect:operation:fraction:respectFlipped:hints:]_block_invoke.1343+693>
     <-[NSImage _usingBestRepresentationForRect:context:hints:body:]+145>
      <-[NSImage drawInRect:fromRect:operation:fraction:respectFlipped:hints:]+1343>
       <-[DKImageShape drawImage]+579>
        <-[DKImageShape drawContent]+192>
         <-[DKDrawableObject drawContentWithSelectedState:]+189>
          <-[DKShapeGroup drawGroupContent]+400>
           <-[DKShapeGroup drawContent]+118>
            <-[DKDrawableObject drawContentInRect:fromRect:withStyle:]+657>
             <-[DKDrawableObject rectHitsPath:]+636>
              <-[DKDrawableObject pointHitsPath:]+156>
               <-[DKDrawableShape hitSelectedPart:forSnapDetection:]+555>
                <-[DKObjectOwnerLayer snapPoint:toAnyObjectExcept:snapTolerance:]+344>
                 <-[DKObjectOwnerLayer snappedMousePoint:forObject:withControlFlag:]+148>
                  <-[DKDrawableObject snappedMousePoint:withControlFlag:]+155>
                   <-[DKDrawablePath lineCreateLoop:]+818>
                    <-[DKDrawablePath mouseDownAtPoint:inPart:event:]+380>
                     <-[DKObjectCreationTool mouseDownAtPoint:targetObject:layer:event:delegate:]+690>
                      <-[DKToolController mouseDown:]+633>
                       <-[DKDrawingView mouseDown:]+112>
                        <$s13MyApp17CanvasDrawingViewC9mouseDown4withySo7NSEventC_tF+64>
                         <$s13MyApp17CanvasDrawingViewC9mouseDown4withySo7NSEventC_tFTo+47>
                          <-[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:]+4907>
                           <-[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:]+2612>
                            <-[NSWindow(NSEventRouting) sendEvent:]+349>
                             <-[NSApplication(NSEvent) sendEvent:]+352>
                              <-[NSApplication run]+707>
                               <NSApplicationMain+777>

Problems creating `NSScrollView` embedded `DKDrawingView` from NIB

Instigating an NSScrollView embedded DKDrawingView from a NIB results in an empty window.

Problem

With Interface Builder:

  1. Create a new NSWindow containing a NSScrollView.
  2. Set the scrollview's document view to a DKDrawingView.
  3. Run the application.

The window should contain a scrollview with a default DrawKit showing a grid.

Remove the NSScrollView and the DKDrawingView works as expected.

Work Around

  1. Create a new NSWindow containing a NSScrollView.
  2. Within the NSWindowController class, instigate the DKDrawingView programmatically and insert into the scrollview:
- (void)awakeFromNib
{
    self.drawingView = [[DKDrawingView alloc] initWithFrame:NSZeroRect];
    [self.scrollView setDocumentView:self.drawingView];

    self.drawing = [DKDrawing defaultDrawingWithSize:[DKDrawing isoA3PaperSize:NO]];
    self.drawingController = [[DKToolController alloc] initWithView:self.drawingView];
    [self.drawing addController:self.drawingController];

    [super awakeFromNib];
}

Notes

This behaviour suggests the DrawKit code handles NIB created views differently from programmatically created views.

Use of GPL licensed code

DrawKit contains GPL licensed code within the framework/ThirdParty folder.

This code appeared in the original DrawKit archive. The code is optionally compiled into DrawKit using compile time preprocessor macros.

As the code is not essential to DrawKit, any GPL code should be migrated to other repositories or removed. This will simplify licensing.

How to access image that was dragged into DKDrawingView[Help Needed]

How can i access and resize an image that was dragged into DKDrawingView. I need to resize the image to fit the view. The functionality i'm looking for can be found in the GCDrawDemo, the object inspector window

//get the layer the current image is at
let obj = canvasDrawing.objectInLayers(at: 1)
//bitmaprepresentation of that image
let bitmaprep = obj.bitmapRepresentation(withDPI: 350)
 let nsImg =  NSImage.init(cgImage:  (bitmaprep.cgImage)!, size: NSSize.init(width: 3000.0, height: 1200))

right now this produces an image thats cropped to fit the DKDrawingView canvas

Carthage support for DrawKit?

I really like Carthage over Cocoapods. Any chance you could add support for Carthage? I like that it leaves my project files alone.

Convert to Shape Group bug

Hi

When converting text into Shape Group, line which is below is going top and top line is going to bottom as attached image.

Thanks
textgroup

Need a simple demo.

The DrawKit is very good framework.

I think it will be awesome if there are a simple demo. :)

Performance issues on retina display

Zooming and panning a DKDrawingView on a non retina display is very smooth. When on retina display the zoom/pan is very choppy and unresponsive. An objectDrawingLayer with no DkDrawableObjects does not behave this way, so the issues seems to be pointing at DKDrawabaleShapes or maybe DKRasterizer? I try setting NSGraphicsContext imageInterpolation to low in DKImageAdornment but still receive same behavior

Question - SVG support?

Is SVG supported now (2018)? I saw a note from 2014 that said that PDF is supported and go that route or make your own converter. I'm assuming that's still the case but wanted to clarify.

Looking for contributors and pull requests

I am looking for help maintaining DrawKit.

  • If you have modifications or changes you want merged in...
  • You use DrawKit for your projects and want to help safe-guard this framework…
  • You want to help with DrawKit…

…please get in touch by leaving a comment here.

Edit Text is not working

Hello Everyone

Double clicking text shape or Edit Text functions are not working. Does anyone have a solution for this issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.