Skip to content

Commit

Permalink
Update print branch
Browse files Browse the repository at this point in the history
  • Loading branch information
inukshuk committed Jun 3, 2019
1 parent c9f5573 commit 48b0055
Show file tree
Hide file tree
Showing 20 changed files with 341 additions and 23 deletions.
41 changes: 28 additions & 13 deletions res/menu/app.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ en:
label: 'Open…'
accelerator: 'CmdOrCtrl+O'
command: 'app:open-dialog'
- &open-new-window
- &open-new
label: 'Open In New Window…'
accelerator: 'Shift+CmdOrCtrl+O'
command: 'app:open-new-dialog'
Expand All @@ -50,10 +50,16 @@ en:
command: 'app:consolidate-photo-library'
condition: 'project'
- type: 'separator'
- label: 'Close'
accelerator: 'CmdOrCtrl+W'
role: 'close'
condition: 'window'
- &print
label: 'Print'
command: 'app:print'
accelerator: 'CmdOrCtrl+P'
condition: 'project'
- type: 'separator'
- &close
label: 'Close Project'
command: 'app:close-project'
condition: 'project'
- type: 'separator'
- label: 'Quit'
accelerator: 'CmdOrCtrl+Q'
Expand Down Expand Up @@ -119,12 +125,17 @@ en:
label: 'Window'
submenu:
- label: 'Minimize'
accelerator: 'CmdOrCtrl+M'
accelerator: 'Ctrl+M'
role: 'minimize'
condition: 'window'
- label: 'Move to Center'
command: 'app:center-window'
condition: 'window'
- type: 'separator'
- label: 'Close'
accelerator: 'Ctrl+W'
role: 'close'
condition: 'window'
- &dev
label: 'Developer'
id: 'dev'
Expand All @@ -148,8 +159,6 @@ en:
- type: 'separator'
- label: 'Rebase Project'
command: 'app:rebase-project'
- label: 'Close Project'
command: 'app:close-project'
- type: 'separator'
- label: 'Theme'
id: 'theme'
Expand Down Expand Up @@ -237,10 +246,15 @@ en:
- *new
- type: 'separator'
- *open
- *open-new
- *recent
- type: 'separator'
- *import
- *consolidate
- type: 'separator'
- *print
- type: 'separator'
- *close
- label: 'Edit'
submenu:
- *undo
Expand All @@ -259,19 +273,20 @@ en:
role: 'window'
submenu:
- label: 'Minimize'
accelerator: 'CmdOrCtrl+M'
accelerator: 'Cmd+M'
role: 'minimize'
condition: 'window'
- label: 'Move to Center'
command: 'app:center-window'
condition: 'window'
- label: 'Close'
accelerator: 'CmdOrCtrl+W'
role: 'close'
condition: 'window'
- type: 'separator'
- label: 'Bring All to Front'
role: 'front'
- type: 'separator'
- label: 'Close'
accelerator: 'Cmd+W'
role: 'close'
condition: 'window'
- *dev
- label: 'Help'
role: 'help'
Expand Down
3 changes: 2 additions & 1 deletion scripts/log-viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const symbol = log =>
const SYMBOL = {
about: 'α',
main: 'β',
prefs: 'π',
prefs: 'σ',
print: 'π',
project: 'ρ',
wizard: 'φ'
}
Expand Down
19 changes: 19 additions & 0 deletions src/browser/tropy.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const {
} = require('electron')

const { fatal, info, logger } = require('../common/log')
const { once } = require('../common/util')
const { existsSync: exists } = require('fs')
const { into, compose, remove, take } = require('transducers.js')

Expand Down Expand Up @@ -620,6 +621,10 @@ class Tropy extends EventEmitter {
this.showOpenDialog(null)
})

this.on('app:print', () => {
this.dispatch(act.item.print(), this.wm.current())
})

this.on('app:zoom-in', () => {
this.state.zoom = this.wm.zoom(this.state.zoom + 0.25)
})
Expand Down Expand Up @@ -674,6 +679,20 @@ class Tropy extends EventEmitter {
this.emit(cmd, BrowserWindow.fromWebContents(event.sender), ...args)
})

ipc.on('print', async (_, items) => {
let win = await this.wm.open('print', this.hash)
await once(win, 'react:ready')
win.show()
win.send('print', items)
await once(win, 'print:ready')

info('printing...')
win.webContents.print({}, (success) => {
info(`print callback: ${success}`)
//win.close()
})
})

ipc.on('error', (event, error) => {
this.handleUncaughtException(
error,
Expand Down
4 changes: 4 additions & 0 deletions src/browser/wm.js
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,10 @@ class WindowManager extends EventEmitter {
minimizable: false,
resizable: false
},
print: {
width: 600,
height: 300
},
project: {
width: 1280,
height: 720,
Expand Down
6 changes: 5 additions & 1 deletion src/common/iiif.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const { URL } = require('url')
const { rotate } = require('./math')
const { rotate, isHorizontal } = require('./math')


class Rotation {
Expand Down Expand Up @@ -44,6 +44,10 @@ class Rotation {
return `${this.mirror ? symbol : ''}${this.angle}`
}

get isHorizontal() {
return isHorizontal(this.angle)
}

get orientation() {
switch (this.angle) {
case 0:
Expand Down
4 changes: 4 additions & 0 deletions src/components/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const IntlProvider = connect(state => {

// eslint-disable-next-line react/prefer-stateless-function
class Main extends React.Component {
componentDidMount() {
this.props.window.send('react:ready')
}

render() {
return (
<WindowContext.Provider value={this.props.window}>
Expand Down
45 changes: 45 additions & 0 deletions src/components/print/container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict'

const React = require('react')
const { Item } = require('./item')
const { WindowContext } = require('../main')

class PrintContainer extends React.Component {
state = {
items: []
}

componentDidMount() {
this.context.on('print', this.onPrint)
}

componentWillUnmount() {
this.context.removeListener('print', this.onPrint)
}

componentDidUpdate(_, state) {
if (this.state.items !== state.items) {
this.context.send('print:ready')
}
}

onPrint = (items) => {
this.setState({ items })
}

render() {
return (
this.state.items.map(item =>
<Item
key={item.id}
data={item.data}
photos={item.photos}/>)
)
}

static contextType = WindowContext
}

module.exports = {
PrintContainer
}
7 changes: 7 additions & 0 deletions src/components/print/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
'use strict'

module.exports = {
...require('./container'),
...require('./item'),
...require('./photo')
}
18 changes: 18 additions & 0 deletions src/components/print/item.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict'

const React = require('react')
const { Photo } = require('./photo')
const { arrayOf, object } = require('prop-types')

const Item = ({ photos }) => (
photos.map(photo =>
<Photo {...photo} key={photo.id}/>)
)

Item.propTypes = {
photos: arrayOf(object).isRequired
}

module.exports = {
Item
}
41 changes: 41 additions & 0 deletions src/components/print/photo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
'use strict'

const React = require('react')
const cx = require('classnames')
const { Rotation } = require('../../common/iiif')
const { bool, number, string } = require('prop-types')

const Photo = ({ angle, height, mirror, orientation, path, width }) => {
let rotation = Rotation
.fromExifOrientation(orientation)
.add({ angle, mirror })

return (
<div className={classes(width < height, rotation.isHorizontal)}>
<img
className={`iiif rot-${rotation.format('x')}`}
src={path}/>
</div>
)
}

Photo.propTypes = {
angle: number.isRequired,
height: number.isRequired,
mirror: bool.isRequired,
orientation: number.isRequired,
path: string.isRequired,
width: number.isRequired
}

const classes = (isPortrait, isHorizontal) => cx(
'photo',
'page',
isPortrait ?
(isHorizontal ? 'portrait' : 'landscape') :
(isHorizontal ? 'landscape' : 'portrait')
)

module.exports = {
Photo
}
32 changes: 32 additions & 0 deletions src/stores/print.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict'

const {
applyMiddleware,
createStore,
combineReducers,
compose
} = require('redux')

const { default: thunk } = require('redux-thunk')
const { intl } = require('../reducers/intl')

const devtools = (ARGS.dev || ARGS.debug) &&
window.__REDUX_DEVTOOLS_EXTENSION__

module.exports = {
create(init = {}) {
let reducer = combineReducers({
intl
})

let middleware = applyMiddleware(
thunk
)

if (typeof devtools === 'function') {
middleware = compose(middleware, devtools())
}

return createStore(reducer, init, middleware)
}
}
28 changes: 28 additions & 0 deletions src/stylesheets/components/_print.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//
// Print
// --------------------------------------------------

html,
body,
main,
.page {
height: 100%;
}

body {
margin: 0;
}

.page {
display: flex;
justify-content: center;
align-items: center;
page-break-after: always;
}

img {
flex: 0 1 auto;
max-width: 100%;
max-height: 100%;
object-fit: contain;
}
12 changes: 12 additions & 0 deletions src/stylesheets/darwin/print-dark.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
/* stylelint-disable max-empty-lines */

//
// Print window
// --------------------------------------------------

$platform: "darwin";
$theme: "dark";


// Components
// --------------------------------------------------

@import "../components/print";
12 changes: 12 additions & 0 deletions src/stylesheets/darwin/print-light.scss
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
/* stylelint-disable max-empty-lines */

//
// Print window
// --------------------------------------------------

$platform: "darwin";
$theme: "light";


// Components
// --------------------------------------------------

@import "../components/print";

0 comments on commit 48b0055

Please sign in to comment.