import { asNumber , asPDFName , asPDFNumber } from 'src/api/objects' ; import { degreesToRadians } from 'src/api/rotations' ; import { PDFHexString , PDFName , PDFNumber , PDFOperator , PDFOperatorNames as Ops , } from 'src/core' ; export const clip = ( ) => PDFOperator . of ( Ops . ClipNonZero ) ; export const clipEvenOdd = ( ) => PDFOperator . of ( Ops . ClipEvenOdd ) ; const { cos , sin , tan } = Math ; export const concatTransformationMatrix = ( a , b , c , d , e , f ) => PDFOperator . of ( Ops . ConcatTransformationMatrix , [ asPDFNumber ( a ) , asPDFNumber ( b ) , asPDFNumber ( c ) , asPDFNumber ( d ) , asPDFNumber ( e ) , asPDFNumber ( f ) , ] ) ; export const translate = ( xPos , yPos ) => concatTransformationMatrix ( 1 , 0 , 0 , 1 , xPos , yPos ) ; export const scale = ( xPos , yPos ) => concatTransformationMatrix ( xPos , 0 , 0 , yPos , 0 , 0 ) ; export const rotateRadians = ( angle ) => concatTransformationMatrix ( cos ( asNumber ( angle ) ) , sin ( asNumber ( angle ) ) , - sin ( asNumber ( angle ) ) , cos ( asNumber ( angle ) ) , 0 , 0 ) ; export const rotateDegrees = ( angle ) => rotateRadians ( degreesToRadians ( asNumber ( angle ) ) ) ; export const skewRadians = ( xSkewAngle , ySkewAngle ) => concatTransformationMatrix ( 1 , tan ( asNumber ( xSkewAngle ) ) , tan ( asNumber ( ySkewAngle ) ) , 1 , 0 , 0 ) ; export const skewDegrees = ( xSkewAngle , ySkewAngle ) => skewRadians ( degreesToRadians ( asNumber ( xSkewAngle ) ) , degreesToRadians ( asNumber ( ySkewAngle ) ) ) ; export const setDashPattern = ( dashArray , dashPhase ) => PDFOperator . of ( Ops . SetLineDashPattern , [ `[${ dashArray . map ( asPDFNumber ) . join ( ' ' ) }]` , asPDFNumber ( dashPhase ) , ] ) ; export const restoreDashPattern = ( ) => setDashPattern ( [ ] , 0 ) ; export enum LineCapStyle { Butt = 0 , Round = 1 , Projecting = 2 } export const setLineCap = ( style ) => PDFOperator . of ( Ops . SetLineCapStyle , [ asPDFNumber ( style ) ] ) ; export enum LineJoinStyle { Miter = 0 , Round = 1 , Bevel = 2 } export const setLineJoin = ( style ) => PDFOperator . of ( Ops . SetLineJoinStyle , [ asPDFNumber ( style ) ] ) ; export const setGraphicsState = ( state ) => PDFOperator . of ( Ops . SetGraphicsStateParams , [ asPDFName ( state ) ] ) ; export const pushGraphicsState = ( ) => PDFOperator . of ( Ops . PushGraphicsState ) ; export const popGraphicsState = ( ) => PDFOperator . of ( Ops . PopGraphicsState ) ; export const setLineWidth = ( width ) => PDFOperator . of ( Ops . SetLineWidth , [ asPDFNumber ( width ) ] ) ; export const appendBezierCurve = ( x1 , y1 , x2 , y2 , x3 , y3 ) => PDFOperator . of ( Ops . AppendBezierCurve , [ asPDFNumber ( x1 ) , asPDFNumber ( y1 ) , asPDFNumber ( x2 ) , asPDFNumber ( y2 ) , asPDFNumber ( x3 ) , asPDFNumber ( y3 ) , ] ) ; export const appendQuadraticCurve = ( x1 , y1 , x2 , y2 ) => PDFOperator . of ( Ops . CurveToReplicateInitialPoint , [ asPDFNumber ( x1 ) , asPDFNumber ( y1 ) , asPDFNumber ( x2 ) , asPDFNumber ( y2 ) , ] ) ; export const closePath = ( ) => PDFOperator . of ( Ops . ClosePath ) ; export const moveTo = ( xPos , yPos ) => PDFOperator . of ( Ops . MoveTo , [ asPDFNumber ( xPos ) , asPDFNumber ( yPos ) ] ) ; export const lineTo = ( xPos , yPos ) => PDFOperator . of ( Ops . LineTo , [ asPDFNumber ( xPos ) , asPDFNumber ( yPos ) ] ) ; param xPos param yPos param width param height export const rectangle = ( xPos , yPos , width , height ) => PDFOperator . of ( Ops . AppendRectangle , [ asPDFNumber ( xPos ) , asPDFNumber ( yPos ) , asPDFNumber ( width ) , asPDFNumber ( height ) , ] ) ; param xPos param yPos param size export const square = ( xPos , yPos , size ) => rectangle ( xPos , yPos , size , size ) ; export const stroke = ( ) => PDFOperator . of ( Ops . StrokePath ) ; export const fill = ( ) => PDFOperator . of ( Ops . FillNonZero ) ; export const fillAndStroke = ( ) => PDFOperator . of ( Ops . FillNonZeroAndStroke ) ; export const endPath = ( ) => PDFOperator . of ( Ops . EndPath ) ; export const nextLine = ( ) => PDFOperator . of ( Ops . NextLine ) ; export const moveText = ( x , y ) => PDFOperator . of ( Ops . MoveText , [ asPDFNumber ( x ) , asPDFNumber ( y ) ] ) ; export const showText = ( text ) => PDFOperator . of ( Ops . ShowText , [ text ] ) ; export const beginText = ( ) => PDFOperator . of ( Ops . BeginText ) ; export const endText = ( ) => PDFOperator . of ( Ops . EndText ) ; export const setFontAndSize = ( name , size ) => PDFOperator . of ( Ops . SetFontAndSize , [ asPDFName ( name ) , asPDFNumber ( size ) ] ) ; export const setCharacterSpacing = ( spacing ) => PDFOperator . of ( Ops . SetCharacterSpacing , [ asPDFNumber ( spacing ) ] ) ; export const setWordSpacing = ( spacing ) => PDFOperator . of ( Ops . SetWordSpacing , [ asPDFNumber ( spacing ) ] ) ; param squeeze export const setCharacterSqueeze = ( squeeze ) => PDFOperator . of ( Ops . SetTextHorizontalScaling , [ asPDFNumber ( squeeze ) ] ) ; export const setLineHeight = ( lineHeight ) => PDFOperator . of ( Ops . SetTextLineHeight , [ asPDFNumber ( lineHeight ) ] ) ; export const setTextRise = ( rise ) => PDFOperator . of ( Ops . SetTextRise , [ asPDFNumber ( rise ) ] ) ; export enum TextRenderingMode { Fill = 0 , Outline = 1 , FillAndOutline = 2 , Invisible = 3 , FillAndClip = 4 , OutlineAndClip = 5 , FillAndOutlineAndClip = 6 , Clip = 7 } export const setTextRenderingMode = ( mode ) => PDFOperator . of ( Ops . SetTextRenderingMode , [ asPDFNumber ( mode ) ] ) ; export const setTextMatrix = ( a , b , c , d , e , f ) => PDFOperator . of ( Ops . SetTextMatrix , [ asPDFNumber ( a ) , asPDFNumber ( b ) , asPDFNumber ( c ) , asPDFNumber ( d ) , asPDFNumber ( e ) , asPDFNumber ( f ) , ] ) ; export const rotateAndSkewTextRadiansAndTranslate = ( rotationAngle , xSkewAngle , ySkewAngle , x , y ) => setTextMatrix ( cos ( asNumber ( rotationAngle ) ) , sin ( asNumber ( rotationAngle ) ) + tan ( asNumber ( xSkewAngle ) ) , - sin ( asNumber ( rotationAngle ) ) + tan ( asNumber ( ySkewAngle ) ) , cos ( asNumber ( rotationAngle ) ) , x , y ) ; export const rotateAndSkewTextDegreesAndTranslate = ( rotationAngle , xSkewAngle , ySkewAngle , x , y ) => rotateAndSkewTextRadiansAndTranslate ( degreesToRadians ( asNumber ( rotationAngle ) ) , degreesToRadians ( asNumber ( xSkewAngle ) ) , degreesToRadians ( asNumber ( ySkewAngle ) ) , x , y ) ; export const drawObject = ( name ) => PDFOperator . of ( Ops . DrawObject , [ asPDFName ( name ) ] ) ; export const setFillingGrayscaleColor = ( gray ) => PDFOperator . of ( Ops . NonStrokingColorGray , [ asPDFNumber ( gray ) ] ) ; export const setStrokingGrayscaleColor = ( gray ) => PDFOperator . of ( Ops . StrokingColorGray , [ asPDFNumber ( gray ) ] ) ; export const setFillingRgbColor = ( red , green , blue ) => PDFOperator . of ( Ops . NonStrokingColorRgb , [ asPDFNumber ( red ) , asPDFNumber ( green ) , asPDFNumber ( blue ) , ] ) ; export const setStrokingRgbColor = ( red , green , blue ) => PDFOperator . of ( Ops . StrokingColorRgb , [ asPDFNumber ( red ) , asPDFNumber ( green ) , asPDFNumber ( blue ) , ] ) ; export const setFillingCmykColor = ( cyan , magenta , yellow , key ) => PDFOperator . of ( Ops . NonStrokingColorCmyk , [ asPDFNumber ( cyan ) , asPDFNumber ( magenta ) , asPDFNumber ( yellow ) , asPDFNumber ( key ) , ] ) ; export const setStrokingCmykColor = ( cyan , magenta , yellow , key ) => PDFOperator . of ( Ops . StrokingColorCmyk , [ asPDFNumber ( cyan ) , asPDFNumber ( magenta ) , asPDFNumber ( yellow ) , asPDFNumber ( key ) , ] ) ; export const beginMarkedContent = ( tag ) => PDFOperator . of ( Ops . BeginMarkedContent , [ asPDFName ( tag ) ] ) ; export const endMarkedContent = ( ) => PDFOperator . of ( Ops . EndMarkedContent ) ;