idx
int64
0
41.2k
question
stringlengths
73
5.81k
target
stringlengths
5
918
4,100
public static int cuTexRefSetFormat ( CUtexref hTexRef , int fmt , int NumPackedComponents ) { return checkResult ( cuTexRefSetFormatNative ( hTexRef , fmt , NumPackedComponents ) ) ; }
Sets the format for a texture reference .
4,101
public static int cuTexRefSetAddress2D ( CUtexref hTexRef , CUDA_ARRAY_DESCRIPTOR desc , CUdeviceptr dptr , long PitchInBytes ) { return checkResult ( cuTexRefSetAddress2DNative ( hTexRef , desc , dptr , PitchInBytes ) ) ; }
Binds an address as a 2D texture reference .
4,102
public static int cuTexRefSetAddressMode ( CUtexref hTexRef , int dim , int am ) { return checkResult ( cuTexRefSetAddressModeNative ( hTexRef , dim , am ) ) ; }
Sets the addressing mode for a texture reference .
4,103
public static int cuTexRefGetAddressMode ( int pam [ ] , CUtexref hTexRef , int dim ) { return checkResult ( cuTexRefGetAddressModeNative ( pam , hTexRef , dim ) ) ; }
Gets the addressing mode used by a texture reference .
4,104
public static int cuTexRefGetFormat ( int pFormat [ ] , int pNumChannels [ ] , CUtexref hTexRef ) { return checkResult ( cuTexRefGetFormatNative ( pFormat , pNumChannels , hTexRef ) ) ; }
Gets the format used by a texture reference .
4,105
public static int cuSurfRefSetArray ( CUsurfref hSurfRef , CUarray hArray , int Flags ) { return checkResult ( cuSurfRefSetArrayNative ( hSurfRef , hArray , Flags ) ) ; }
Sets the CUDA array for a surface reference .
4,106
public static int cuDeviceCanAccessPeer ( int canAccessPeer [ ] , CUdevice dev , CUdevice peerDev ) { return checkResult ( cuDeviceCanAccessPeerNative ( canAccessPeer , dev , peerDev ) ) ; }
Queries if a device may directly access a peer device s memory .
4,107
public static int cuParamSeti ( CUfunction hfunc , int offset , int value ) { return checkResult ( cuParamSetiNative ( hfunc , offset , value ) ) ; }
Adds an integer parameter to the function s argument list .
4,108
public static int cuParamSetf ( CUfunction hfunc , int offset , float value ) { return checkResult ( cuParamSetfNative ( hfunc , offset , value ) ) ; }
Adds a floating - point parameter to the function s argument list .
4,109
public static int cuParamSetv ( CUfunction hfunc , int offset , Pointer ptr , int numbytes ) { return checkResult ( cuParamSetvNative ( hfunc , offset , ptr , numbytes ) ) ; }
Adds arbitrary data to the function s argument list .
4,110
public static int cuParamSetTexRef ( CUfunction hfunc , int texunit , CUtexref hTexRef ) { return checkResult ( cuParamSetTexRefNative ( hfunc , texunit , hTexRef ) ) ; }
Adds a texture - reference to the function s argument list .
4,111
public static int cuEventElapsedTime ( float pMilliseconds [ ] , CUevent hStart , CUevent hEnd ) { return checkResult ( cuEventElapsedTimeNative ( pMilliseconds , hStart , hEnd ) ) ; }
Computes the elapsed time between two events .
4,112
public static int cuPointerGetAttribute ( Pointer data , int attribute , CUdeviceptr ptr ) { return checkResult ( cuPointerGetAttributeNative ( data , attribute , ptr ) ) ; }
Returns information about a pointer .
4,113
public static int cuStreamCreateWithPriority ( CUstream phStream , int flags , int priority ) { return checkResult ( cuStreamCreateWithPriorityNative ( phStream , flags , priority ) ) ; }
Create a stream with the given priority
4,114
public static int cuStreamAttachMemAsync ( CUstream hStream , CUdeviceptr dptr , long length , int flags ) { return checkResult ( cuStreamAttachMemAsyncNative ( hStream , dptr , length , flags ) ) ; }
Attach memory to a stream asynchronously .
4,115
public static int cuGLCtxCreate ( CUcontext pCtx , int Flags , CUdevice device ) { return checkResult ( cuGLCtxCreateNative ( pCtx , Flags , device ) ) ; }
Create a CUDA context for interoperability with OpenGL .
4,116
public static int cuGraphicsResourceGetMappedPointer ( CUdeviceptr pDevPtr , long pSize [ ] , CUgraphicsResource resource ) { return checkResult ( cuGraphicsResourceGetMappedPointerNative ( pDevPtr , pSize , resource ) ) ; }
Get a device pointer through which to access a mapped graphics resource .
4,117
public static int cuLaunchCooperativeKernel ( CUfunction f , int gridDimX , int gridDimY , int gridDimZ , int blockDimX , int blockDimY , int blockDimZ , int sharedMemBytes , CUstream hStream , Pointer kernelParams ) { return checkResult ( cuLaunchCooperativeKernelNative ( f , gridDimX , gridDimY , gridDimZ , blockDimX , blockDimY , blockDimZ , sharedMemBytes , hStream , kernelParams ) ) ; }
Launches a CUDA function where thread blocks can cooperate and synchronize as they execute .
4,118
public static int cuLaunchCooperativeKernelMultiDevice ( CUDA_LAUNCH_PARAMS launchParamsList [ ] , int numDevices , int flags ) { return checkResult ( cuLaunchCooperativeKernelMultiDeviceNative ( launchParamsList , numDevices , flags ) ) ; }
Launches CUDA functions on multiple devices where thread blocks can cooperate and synchronize as they execute .
4,119
public static int cuLaunchHostFunc ( CUstream hStream , CUhostFn fn , Object userData ) { return checkResult ( cuLaunchHostFuncNative ( hStream , fn , userData ) ) ; }
Enqueues a host function call in a stream .
4,120
public static int cuProfilerInitialize ( String configFile , String outputFile , int outputMode ) { return checkResult ( cuProfilerInitializeNative ( configFile , outputFile , outputMode ) ) ; }
Initialize the profiling .
4,121
private Dimension getLayoutDimension ( ) { Dimension dim ; if ( layoutDimension != null ) { dim = new Dimension ( layoutDimension ) ; if ( dim . width <= 0 ) dim . width = 10 ; if ( dim . height <= 0 ) dim . height = 10 ; } else dim = new Dimension ( 10 , 10 ) ; return dim ; }
Obtains the dimension that should be used for the layout .
4,122
private void checkLayout ( ) { Dimension dim = getLayoutDimension ( ) ; if ( currentDimension == null || ! currentDimension . equals ( dim ) ) { createLayout ( dim ) ; viewport . setContainingBlockBox ( owner ) ; if ( owner instanceof BlockBox ) viewport . clipByBlock ( ( BlockBox ) owner ) ; owner . removeAllSubBoxes ( ) ; owner . addSubBox ( viewport ) ; currentDimension = new Dimension ( dim ) ; } }
Checks whether the layout is computed and recomputes it when necessary .
4,123
private void organizeContent ( ) { table = new TableBox ( el , g , ctx ) ; table . adoptParent ( this ) ; table . setStyle ( style ) ; for ( Iterator < Box > it = nested . iterator ( ) ; it . hasNext ( ) ; ) { Box box = it . next ( ) ; if ( box instanceof TableCaptionBox ) { caption = ( TableCaptionBox ) box ; } else if ( box instanceof BlockBox && ( ( BlockBox ) box ) . isPositioned ( ) ) { } else { table . addSubBox ( box ) ; box . setContainingBlockBox ( table ) ; box . setParent ( table ) ; it . remove ( ) ; endChild -- ; } } addSubBox ( table ) ; }
Goes through the list of child boxes and organizes them into captions header footer etc .
4,124
private void initComponents ( URL baseurl ) { documentScroll = new javax . swing . JScrollPane ( ) ; browserCanvas = new BrowserCanvas ( docroot , decoder , new java . awt . Dimension ( 1000 , 600 ) , baseurl ) ; browserCanvas . addMouseListener ( new MouseListener ( ) { public void mouseClicked ( MouseEvent e ) { System . out . println ( "Click: " + e . getX ( ) + ":" + e . getY ( ) ) ; } public void mousePressed ( MouseEvent e ) { } public void mouseReleased ( MouseEvent e ) { } public void mouseEntered ( MouseEvent e ) { } public void mouseExited ( MouseEvent e ) { } } ) ; getContentPane ( ) . setLayout ( new java . awt . GridLayout ( 1 , 0 ) ) ; setTitle ( "CSSBox Browser" ) ; addWindowListener ( new java . awt . event . WindowAdapter ( ) { public void windowClosing ( java . awt . event . WindowEvent evt ) { exitForm ( evt ) ; } } ) ; documentScroll . setViewportView ( browserCanvas ) ; getContentPane ( ) . add ( documentScroll ) ; pack ( ) ; }
Creates and initializes the GUI components
4,125
protected void loadAttributes ( ) { try { if ( ! HTMLNorm . getAttribute ( el , "colspan" ) . equals ( "" ) ) colspan = Integer . parseInt ( HTMLNorm . getAttribute ( el , "colspan" ) ) ; else colspan = 1 ; if ( ! HTMLNorm . getAttribute ( el , "rowspan" ) . equals ( "" ) ) rowspan = Integer . parseInt ( HTMLNorm . getAttribute ( el , "rowspan" ) ) ; else rowspan = 1 ; } catch ( NumberFormatException e ) { log . warn ( "Invalid width value: " + e . getMessage ( ) ) ; } }
Loads the important values from the element attributes .
4,126
public void copyValues ( ElementBox src ) { super . copyValues ( src ) ; nested . addAll ( src . nested ) ; textonly = src . textonly ; pseudoElements = new HashMap < > ( src . pseudoElements ) ; style = src . style ; pseudoStyle = new HashMap < > ( src . pseudoStyle ) ; startChild = src . startChild ; endChild = src . endChild ; isblock = src . isblock ; style = src . style ; display = src . display ; lineHeight = src . lineHeight ; whitespace = src . whitespace ; bgcolor = ( src . bgcolor == null ) ? null : new Color ( src . bgcolor . getRed ( ) , src . bgcolor . getGreen ( ) , src . bgcolor . getBlue ( ) , src . bgcolor . getAlpha ( ) ) ; bgimages = ( src . bgimages == null ) ? null : new Vector < BackgroundImage > ( src . bgimages ) ; transform = src . transform ; position = src . position ; topset = src . topset ; leftset = src . leftset ; bottomset = src . bottomset ; rightset = src . rightset ; if ( src . coords != null ) coords = new LengthSet ( src . coords ) ; if ( src . margin != null ) margin = new LengthSet ( src . margin ) ; if ( src . emargin != null ) emargin = new LengthSet ( src . emargin ) ; if ( src . border != null ) border = new LengthSet ( src . border ) ; if ( src . padding != null ) padding = new LengthSet ( src . padding ) ; if ( src . content != null ) content = new Dimension ( src . content ) ; }
Copy the values from another element box .
4,127
protected void loadBorders ( CSSDecoder dec , int contw ) { border = new LengthSet ( ) ; if ( borderVisible ( "top" ) ) border . top = getBorderWidth ( dec , "border-top-width" ) ; else border . top = 0 ; if ( borderVisible ( "right" ) ) border . right = getBorderWidth ( dec , "border-right-width" ) ; else border . right = 0 ; if ( borderVisible ( "bottom" ) ) border . bottom = getBorderWidth ( dec , "border-bottom-width" ) ; else border . bottom = 0 ; if ( borderVisible ( "left" ) ) border . left = getBorderWidth ( dec , "border-left-width" ) ; else border . left = 0 ; }
Loads the border sizes from the style .
4,128
protected void loadBackground ( ) { CSSProperty . BackgroundColor bg = style . getProperty ( "background-color" ) ; if ( bg == CSSProperty . BackgroundColor . color ) { TermColor bgc = style . getSpecifiedValue ( TermColor . class , "background-color" ) ; if ( bgc . isTransparent ( ) ) bgcolor = null ; else bgcolor = CSSUnits . convertColor ( bgc . getValue ( ) ) ; } else bgcolor = null ; bgimages = loadBackgroundImages ( style ) ; }
Loads the background information from the style
4,129
protected void loadPosition ( ) { CSSDecoder dec = new CSSDecoder ( ctx ) ; int contw = getContainingBlock ( ) . width ; int conth = getContainingBlock ( ) . height ; CSSProperty . Top ptop = style . getProperty ( "top" ) ; CSSProperty . Right pright = style . getProperty ( "right" ) ; CSSProperty . Bottom pbottom = style . getProperty ( "bottom" ) ; CSSProperty . Left pleft = style . getProperty ( "left" ) ; topset = ! ( ptop == null || ptop == CSSProperty . Top . AUTO ) ; rightset = ! ( pright == null || pright == CSSProperty . Right . AUTO ) ; bottomset = ! ( pbottom == null || pbottom == CSSProperty . Bottom . AUTO ) ; leftset = ! ( pleft == null || pleft == CSSProperty . Left . AUTO ) ; coords = new LengthSet ( ) ; if ( topset ) coords . top = dec . getLength ( getLengthValue ( "top" ) , ( ptop == CSSProperty . Top . AUTO ) , 0 , 0 , conth ) ; if ( rightset ) coords . right = dec . getLength ( getLengthValue ( "right" ) , ( pright == CSSProperty . Right . AUTO ) , 0 , 0 , contw ) ; if ( bottomset ) coords . bottom = dec . getLength ( getLengthValue ( "bottom" ) , ( pbottom == CSSProperty . Bottom . AUTO ) , 0 , 0 , conth ) ; if ( leftset ) coords . left = dec . getLength ( getLengthValue ( "left" ) , ( pleft == CSSProperty . Left . AUTO ) , 0 , 0 , contw ) ; }
Loads the top left bottom and right coordinates from the style
4,130
public TableColumn copyBox ( ) { TableColumn ret = new TableColumn ( el , g , ctx ) ; ret . copyValues ( this ) ; return ret ; }
Creates a copy of the column
4,131
public void setSpecifiedWidth ( String width ) { colwidth = width ; try { content = new Dimension ( 0 , 0 ) ; content . width = Integer . parseInt ( width ) ; bounds . width = content . width ; abswidth = content . width ; wset = true ; } catch ( NumberFormatException e ) { if ( ! width . equals ( "" ) ) log . warn ( "Invalid width value: " + width ) ; } }
Set the width of the column form an attribute or CSS
4,132
public void setColumnWidth ( int width ) { content = new Dimension ( 0 , 0 ) ; content . width = width ; bounds . width = content . width ; }
Set the width of the column
4,133
public void addCell ( TableCellBox cell ) { if ( cells == null ) organizeContent ( ) ; cells . add ( cell ) ; cell . setOwnerRow ( this ) ; }
Add a new cell to the table row .
4,134
public int getMinimalColumnWidth ( int col ) { int ret = 0 ; int r = 0 ; while ( r < getRowCount ( ) ) { TableCellBox cell = cells [ col ] [ r ] ; if ( cell != null ) { int min = cell . getMinimalWidth ( ) / cell . getColspan ( ) ; if ( min > ret ) ret = min ; r += cell . getRowspan ( ) ; } else r ++ ; } return ret ; }
Determine the minimal width of the column
4,135
public int getMaximalColumnWidth ( int col ) { int ret = 0 ; int r = 0 ; while ( r < getRowCount ( ) ) { TableCellBox cell = cells [ col ] [ r ] ; if ( cell != null ) { int max = cell . getMaximalWidth ( ) / cell . getColspan ( ) ; if ( max > ret ) ret = max ; r += cell . getRowspan ( ) ; } else r ++ ; } return ret ; }
Determine the maximal width of the column
4,136
public void updateColumn ( int c , TableColumn col ) { int r = 0 ; while ( r < getRowCount ( ) ) { TableCellBox cell = cells [ c ] [ r ] ; if ( cell != null ) { cell . setOwnerColumn ( col ) ; int min = cell . getMinimalWidth ( ) / cell . getColspan ( ) ; if ( min > col . getMinimalWidth ( ) ) col . setMinimalWidth ( min ) ; int max = cell . getMaximalWidth ( ) / cell . getColspan ( ) ; if ( max > col . getMaximalWidth ( ) ) col . setMaximalWidth ( max ) ; if ( cell . wset ) { col . wset = true ; if ( cell . isRelative ( ) ) { col . setRelative ( true ) ; if ( col . percent < cell . percent ) col . percent = cell . percent ; } else { if ( cell . getContentWidth ( ) > col . abswidth ) col . abswidth = cell . getContentWidth ( ) ; } } if ( col . getWidth ( ) < col . getMinimalWidth ( ) ) col . setColumnWidth ( col . getMinimalWidth ( ) ) ; r += cell . getRowspan ( ) ; } else r ++ ; } }
Checks the maximal and minimal width of the column if the column has fixed width and if it is relative . Updates the appropriate information in the TableColumn structure .
4,137
public ElementBox createBox ( ElementBox parent , Element e , Viewport viewport , NodeData style ) { String name = e . getNodeName ( ) . toLowerCase ( ) ; if ( name . equals ( "object" ) ) return createSubtreeObject ( parent , e , viewport , style ) ; else if ( name . equals ( "img" ) ) return createSubtreeImg ( parent , e , viewport , style ) ; else if ( name . equals ( "a" ) && e . hasAttribute ( "name" ) && ( e . getTextContent ( ) == null || e . getTextContent ( ) . trim ( ) . length ( ) == 0 ) ) { ElementBox eb = factory . createElementInstance ( parent , e , style ) ; eb . setSticky ( true ) ; return eb ; } else return null ; }
Creates the box according to the HTML element .
4,138
public void add ( BlockBox box ) { box . setOwnerFloatList ( this ) ; floats . add ( box ) ; if ( box . getBounds ( ) . y + box . getBounds ( ) . height > getMaxY ( ) ) bottomBox = box ; if ( box . getBounds ( ) . y > getLastY ( ) ) lastBox = box ; }
Adds a new floating box to the list
4,139
public int getWidth ( int y ) { int maxx = 0 ; for ( int i = 0 ; i < size ( ) ; i ++ ) { Box box = getBox ( i ) ; if ( box . getBounds ( ) . y <= y && box . getBounds ( ) . y + box . getBounds ( ) . height > y ) { int wx = box . getBounds ( ) . x + box . getBounds ( ) . width ; if ( wx > maxx ) maxx = wx ; } } return maxx ; }
Gets the total width of the floating boxes in some point .
4,140
public int getMaxYForOwner ( BlockBox owner , boolean requireVisible ) { int maxy = 0 ; for ( int i = 0 ; i < size ( ) ; i ++ ) { Box box = getBox ( i ) ; if ( ( ! requireVisible || box . isDeclaredVisible ( ) ) && box . getContainingBlockBox ( ) == owner ) { int ny = box . bounds . y + box . bounds . height ; if ( ny > maxy ) maxy = ny ; } } return maxy ; }
Goes through all the boxes and computes the Y coordinate of the bottom edge of the lowest box . Only the boxes with the owner containing block are taken into account .
4,141
public static int getNextY ( FloatList fleft , FloatList fright , int y ) { int fy = y ; int nexty1 = fleft . getNextY ( fy ) ; int nexty2 = fright . getNextY ( fy ) ; if ( nexty1 != - 1 && nexty2 != - 1 ) fy = Math . min ( nexty1 , nexty2 ) ; else if ( nexty2 != - 1 ) fy = nexty2 ; else if ( nexty1 != - 1 ) fy = nexty1 ; else fy = - 1 ; return fy ; }
Finds the nearest higher Y coordinate in two float lists where the float widths are different from the given starting coordinate .
4,142
public void copyValues ( Box src ) { rootelem = src . rootelem ; isblock = src . isblock ; order = src . order ; isempty = src . isempty ; sticky = src . sticky ; availwidth = src . availwidth ; viewport = src . viewport ; parent = src . parent ; cbox = src . cbox ; clipblock = src . clipblock ; bounds = new Rectangle ( src . bounds ) ; absbounds = new Rectangle ( src . absbounds ) ; displayed = src . displayed ; visible = src . visible ; splitted = src . splitted ; rest = src . rest ; }
Copy all the values from another box
4,143
public void adoptParent ( ElementBox parent ) { if ( parent instanceof BlockBox ) setContainingBlockBox ( parent ) ; else setContainingBlockBox ( parent . getContainingBlockBox ( ) ) ; setParent ( parent ) ; setViewport ( parent . getViewport ( ) ) ; setClipBlock ( parent . getClipBlock ( ) ) ; }
Initializes a box in order to be a proper child box of the specified parent . Copies all the necessary information from the parent .
4,144
public void clipAbsoluteBounds ( Rectangle clip ) { Rectangle inter = absbounds . intersection ( clip ) ; if ( inter . width == 0 && inter . height == 0 ) displayed = false ; else absbounds = inter ; }
Adjusts the absolute bounds width and height in order to fit into the clip . If the box doesn t fit at all it is marked as invisible .
4,145
public Rectangle getContainingBlock ( ) { if ( cbox instanceof Viewport ) { Rectangle visible = ( ( Viewport ) cbox ) . getVisibleRect ( ) ; return new Rectangle ( 0 , 0 , visible . width , visible . height ) ; } else return cbox . getContentBounds ( ) ; }
Obtains the containing block bounds .
4,146
public Rectangle getAbsoluteContainingBlock ( ) { if ( cbox instanceof Viewport ) { Rectangle ab = cbox . getAbsoluteBounds ( ) ; Rectangle visible = ( ( Viewport ) cbox ) . getVisibleRect ( ) ; return new Rectangle ( ab . x , ab . y , visible . width , visible . height ) ; } else return cbox . getAbsoluteContentBounds ( ) ; }
Obtains the containing block absolute bounds .
4,147
protected Rectangle applyClip ( Shape current , Rectangle newclip ) { if ( current == null ) return newclip ; else { if ( current instanceof Rectangle ) return ( ( Rectangle ) current ) . intersection ( newclip ) ; else return current . getBounds ( ) . intersection ( newclip ) ; } }
Computes a new clipping region from the current one and the eventual clipping box
4,148
protected void initDefaultFonts ( ) { defaultFonts = new HashMap < String , String > ( 3 ) ; defaultFonts . put ( Font . SERIF , Font . SERIF ) ; defaultFonts . put ( Font . SANS_SERIF , Font . SANS_SERIF ) ; defaultFonts . put ( Font . MONOSPACED , Font . MONOSPACED ) ; }
Initializes the default fonts . Current implementation just defines the same physical names for basic AWT logical fonts .
4,149
public void redrawBoxes ( ) { Graphics2D ig = img . createGraphics ( ) ; clearCanvas ( ) ; viewport . draw ( new GraphicsRenderer ( ig ) ) ; revalidate ( ) ; }
Redraws all the rendered boxes .
4,150
public Viewport createViewportTree ( Element root , Graphics2D g , VisualContext ctx , int width , int height ) { Element vp = createAnonymousElement ( root . getOwnerDocument ( ) , "Xdiv" , "block" ) ; viewport = new Viewport ( vp , g , ctx , this , root , width , height ) ; viewport . setConfig ( config ) ; overflowPropagated = false ; BoxTreeCreationStatus stat = new BoxTreeCreationStatus ( viewport ) ; createSubtree ( root , stat ) ; log . debug ( "Root box is: " + viewport . getRootBox ( ) ) ; return viewport ; }
Create the viewport and the underlying box tree from a DOM tree .
4,151
public void createBoxTree ( BoxTreeCreationStatus stat ) { boolean generated = false ; do { if ( stat . parent . isDisplayed ( ) ) { if ( stat . parent . preadd != null ) { addToTree ( stat . parent . preadd , stat ) ; stat . parent . preadd = null ; } if ( stat . parent . previousTwin == null ) { Node n = createPseudoElement ( stat . parent , PseudoElementType . BEFORE ) ; if ( n != null && ( n . getNodeType ( ) == Node . ELEMENT_NODE || n . getNodeType ( ) == Node . TEXT_NODE ) ) { stat . curchild = - 1 ; createSubtree ( n , stat ) ; } } NodeList children = stat . parent . getElement ( ) . getChildNodes ( ) ; for ( int child = stat . parent . firstDOMChild ; child < stat . parent . lastDOMChild ; child ++ ) { Node n = children . item ( child ) ; if ( n . getNodeType ( ) == Node . ELEMENT_NODE || n . getNodeType ( ) == Node . TEXT_NODE ) { stat . curchild = child ; createSubtree ( n , stat ) ; } } if ( stat . parent . nextTwin == null ) { Node n = createPseudoElement ( stat . parent , PseudoElementType . AFTER ) ; if ( n != null && ( n . getNodeType ( ) == Node . ELEMENT_NODE || n . getNodeType ( ) == Node . TEXT_NODE ) ) { stat . curchild = children . getLength ( ) ; createSubtree ( n , stat ) ; } } normalizeBox ( stat . parent ) ; } if ( stat . parent . nextTwin != null ) { stat . parent = stat . parent . nextTwin ; generated = true ; } else generated = false ; } while ( generated ) ; }
Creates the box subtrees for all the child nodes of the DOM node corresponding to the box creatin status . Recursively creates the child boxes from the child nodes .
4,152
private void createSubtree ( Node n , BoxTreeCreationStatus stat ) { stat . parent . curstat = new BoxTreeCreationStatus ( stat ) ; Box newbox ; boolean istext = false ; if ( n . getNodeType ( ) == Node . TEXT_NODE ) { newbox = createTextBox ( ( Text ) n , stat ) ; istext = true ; } else newbox = createElementBox ( ( Element ) n , stat ) ; if ( ! istext ) { BoxTreeCreationStatus newstat = new BoxTreeCreationStatus ( stat ) ; newstat . parent = ( ElementBox ) newbox ; if ( ( ( ElementBox ) newbox ) . mayContainBlocks ( ) ) { BlockBox block = ( BlockBox ) newbox ; if ( ! overflowPropagated ) overflowPropagated = viewport . checkPropagateOverflow ( block ) ; if ( block . position == BlockBox . POS_ABSOLUTE || block . position == BlockBox . POS_RELATIVE || block . position == BlockBox . POS_FIXED ) { newstat . absbox = block ; ElementBox cblock = block . getContainingBlockBox ( ) ; if ( cblock instanceof BlockBox && ( cblock . getClipBlock ( ) == null || ( ( BlockBox ) cblock ) . getOverflowX ( ) != Overflow . VISIBLE ) ) block . setClipBlock ( ( BlockBox ) cblock ) ; else block . setClipBlock ( cblock . getClipBlock ( ) ) ; if ( block . overflowX != BlockBox . OVERFLOW_VISIBLE || block . clipRegion != null ) newstat . clipbox = block ; else newstat . clipbox = block . getClipBlock ( ) ; } else { if ( block . overflowX != BlockBox . OVERFLOW_VISIBLE ) newstat . clipbox = block ; } newstat . contbox = block ; newstat . lastinflow = null ; createBoxTree ( newstat ) ; removeTrailingWhitespaces ( block ) ; } else createBoxTree ( newstat ) ; } addToTree ( newbox , stat ) ; }
Creates a subtree of a parent box that corresponds to a single child DOM node of this box and adds the subtree to the complete tree .
4,153
private void addToTree ( Box newbox , BoxTreeCreationStatus stat ) { if ( newbox . isBlock ( ) ) { if ( ! ( ( BlockBox ) newbox ) . isPositioned ( ) ) { if ( stat . parent . mayContainBlocks ( ) ) { stat . parent . addSubBox ( newbox ) ; stat . lastinflow = newbox ; } else { ElementBox iparent = null ; ElementBox grandpa = stat . parent ; ElementBox prev = null ; do { iparent = grandpa ; grandpa = iparent . getParent ( ) ; int lastchild = iparent . lastDOMChild ; iparent . lastDOMChild = iparent . curstat . curchild ; if ( iparent . curstat . curchild + 1 < lastchild || prev != null ) { ElementBox newparent = iparent . copyBox ( ) ; newparent . removeAllSubBoxes ( ) ; newparent . firstDOMChild = iparent . curstat . curchild + 1 ; iparent . nextTwin = newparent ; newparent . previousTwin = iparent ; if ( prev != null ) newparent . preadd = prev ; prev = newparent ; } } while ( grandpa != null && ! grandpa . mayContainBlocks ( ) ) ; if ( grandpa != null ) { iparent . postadd = new Vector < Box > ( 2 ) ; iparent . postadd . add ( newbox ) ; if ( iparent . nextTwin != null ) iparent . postadd . add ( iparent . nextTwin ) ; stat . lastinflow = null ; } else log . error ( "(internal error) grandpa is missing for %s" , newbox ) ; } } else { ( ( BlockBox ) newbox ) . domParent = newbox . getParent ( ) ; ( ( BlockBox ) newbox ) . absReference = stat . lastinflow ; newbox . getContainingBlockBox ( ) . addSubBox ( newbox ) ; } } else { boolean lastwhite = ( stat . lastinflow == null ) || stat . lastinflow . isBlock ( ) || ( stat . lastinflow . endsWithWhitespace ( ) && stat . lastinflow . collapsesSpaces ( ) ) ; boolean collapse = lastwhite && newbox . isWhitespace ( ) && newbox . collapsesSpaces ( ) && ! newbox . isSticky ( ) && ! ( newbox instanceof InlineBlockBox ) ; if ( ! collapse ) { stat . parent . addSubBox ( newbox ) ; stat . lastinflow = newbox ; } else newbox . setContainingBlockBox ( null ) ; } if ( newbox instanceof ElementBox && ( ( ElementBox ) newbox ) . postadd != null ) { for ( Box box : ( ( ElementBox ) newbox ) . postadd ) addToTree ( box , stat ) ; ( ( ElementBox ) newbox ) . postadd = null ; } }
Adds a bew box to the tree according to its type and the tree creation status .
4,154
private ElementBox normalizeBox ( ElementBox root ) { if ( root . mayContainBlocks ( ) && ( ( BlockBox ) root ) . containsBlocks ( ) ) createAnonymousBlocks ( ( BlockBox ) root ) ; else if ( root . containsMixedContent ( ) ) createAnonymousInline ( root ) ; if ( root . getDisplay ( ) == ElementBox . DISPLAY_TABLE || root . getDisplay ( ) == ElementBox . DISPLAY_INLINE_TABLE ) createAnonymousWrappers ( root , "tr" , "table-row" , properTableChild ) ; else if ( root . getDisplay ( ) == ElementBox . DISPLAY_TABLE_ROW_GROUP ) createAnonymousWrappers ( root , "tr" , "table-row" , properTableRowGroupChild ) ; else if ( root . getDisplay ( ) == ElementBox . DISPLAY_TABLE_ROW ) createAnonymousWrappers ( root , "td" , "table-cell" , properTableRowChild ) ; createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_CELL , ElementBox . DISPLAY_TABLE_ROW , ElementBox . DISPLAY_ANY , ElementBox . DISPLAY_ANY , "tr" , "table-row" ) ; createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_ROW , ElementBox . DISPLAY_TABLE_ROW_GROUP , ElementBox . DISPLAY_TABLE_HEADER_GROUP , ElementBox . DISPLAY_TABLE_FOOTER_GROUP , "tbody" , "table-row-group" ) ; createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_COLUMN , ElementBox . DISPLAY_TABLE , ElementBox . DISPLAY_INLINE_TABLE , ElementBox . DISPLAY_TABLE_COLUMN_GROUP , "table" , "table" ) ; createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_ROW_GROUP , ElementBox . DISPLAY_TABLE , ElementBox . DISPLAY_INLINE_TABLE , ElementBox . DISPLAY_ANY , "table" , "table" ) ; createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_HEADER_GROUP , ElementBox . DISPLAY_TABLE , ElementBox . DISPLAY_INLINE_TABLE , ElementBox . DISPLAY_ANY , "table" , "table" ) ; createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_FOOTER_GROUP , ElementBox . DISPLAY_TABLE , ElementBox . DISPLAY_INLINE_TABLE , ElementBox . DISPLAY_ANY , "table" , "table" ) ; createAnonymousBoxes ( root , ElementBox . DISPLAY_TABLE_CAPTION , ElementBox . DISPLAY_TABLE , ElementBox . DISPLAY_INLINE_TABLE , ElementBox . DISPLAY_ANY , "table" , "table" ) ; return root ; }
Checks the newly created box and creates anonymous block boxes above the children if necessary .
4,155
private void createAnonymousBoxes ( ElementBox root , CSSProperty . Display type , CSSProperty . Display reqtype1 , CSSProperty . Display reqtype2 , CSSProperty . Display reqtype3 , String name , String display ) { if ( root . getDisplay ( ) != reqtype1 && root . getDisplay ( ) != reqtype2 && root . getDisplay ( ) != reqtype3 ) { Vector < Box > nest = new Vector < Box > ( ) ; ElementBox adiv = null ; for ( int i = 0 ; i < root . getSubBoxNumber ( ) ; i ++ ) { Box sub = root . getSubBox ( i ) ; if ( sub instanceof BlockBox && ( ( BlockBox ) sub ) . isPositioned ( ) ) { nest . add ( sub ) ; } else if ( sub instanceof ElementBox ) { ElementBox subel = ( ElementBox ) sub ; if ( subel . getDisplay ( ) != type ) { adiv = null ; nest . add ( sub ) ; } else { if ( adiv == null ) { Element elem = createAnonymousElement ( root . getElement ( ) . getOwnerDocument ( ) , name , display ) ; adiv = createBox ( root , elem , display ) ; adiv . isblock = true ; adiv . isempty = true ; adiv . setContainingBlockBox ( sub . getContainingBlockBox ( ) ) ; adiv . setClipBlock ( sub . getClipBlock ( ) ) ; nest . add ( adiv ) ; } if ( sub . isDisplayed ( ) && ! sub . isEmpty ( ) ) { adiv . isempty = false ; adiv . displayed = true ; } sub . setParent ( adiv ) ; sub . setContainingBlockBox ( adiv ) ; adiv . addSubBox ( sub ) ; } } else return ; } root . nested = nest ; root . endChild = nest . size ( ) ; } }
Checks the child boxes of the specified root box wheter they require creating an anonymous parent box .
4,156
protected ElementBox createAnonymousBox ( ElementBox parent , Box child , boolean block ) { ElementBox anbox ; if ( block ) { Element anelem = createAnonymousElement ( child . getNode ( ) . getOwnerDocument ( ) , "Xdiv" , "block" ) ; anbox = new BlockBox ( anelem , ( Graphics2D ) child . getGraphics ( ) . create ( ) , child . getVisualContext ( ) . create ( ) ) ; anbox . setViewport ( viewport ) ; anbox . setStyle ( createAnonymousStyle ( "block" ) ) ; ( ( BlockBox ) anbox ) . contblock = false ; anbox . isblock = true ; } else { Element anelem = createAnonymousElement ( child . getNode ( ) . getOwnerDocument ( ) , "Xspan" , "inline" ) ; anbox = new InlineBox ( anelem , ( Graphics2D ) child . getGraphics ( ) . create ( ) , child . getVisualContext ( ) . create ( ) ) ; anbox . setViewport ( viewport ) ; anbox . setStyle ( createAnonymousStyle ( "inline" ) ) ; anbox . isblock = false ; } if ( parent != null ) { computeInheritedStyle ( anbox , parent ) ; anbox . setParent ( parent ) ; } anbox . setOrder ( next_order ++ ) ; anbox . isempty = true ; anbox . setBase ( child . getBase ( ) ) ; anbox . setContainingBlockBox ( child . getContainingBlockBox ( ) ) ; anbox . setClipBlock ( child . getClipBlock ( ) ) ; return anbox ; }
Creates an empty anonymous block or inline box that can be placed between an optional parent and its child . The corresponding properties of the box are taken from the child . The child is inserted NOT as the child box of the new box . The new box is NOT inserted as a subbox of the parent .
4,157
public ElementBox createBox ( ElementBox parent , Element n , String display ) { ElementBox root = null ; NodeData style = decoder . getElementStyleInherited ( n ) ; if ( style == null ) style = createAnonymousStyle ( display ) ; if ( config . getUseHTML ( ) && html . isTagSupported ( n ) ) { root = html . createBox ( parent , n , viewport , style ) ; } if ( root == null ) { root = createElementInstance ( parent , n , style ) ; } root . setBase ( baseurl ) ; root . setViewport ( viewport ) ; root . setParent ( parent ) ; root . setOrder ( next_order ++ ) ; return root ; }
Creates a single new box from an element .
4,158
private Node createPseudoElement ( ElementBox box , PseudoElementType pseudo ) { Element n = box . getElement ( ) ; NodeData style = decoder . getElementStyleInherited ( n , pseudo ) ; if ( style != null ) { TermList cont = style . getValue ( TermList . class , "content" ) ; if ( cont != null && cont . size ( ) > 0 ) { Element pelem = createAnonymousElement ( n . getOwnerDocument ( ) , "XPspan" , "inline" ) ; for ( Term < ? > c : cont ) { if ( c instanceof TermIdent ) { } else if ( c instanceof TermString ) { Text txt = n . getOwnerDocument ( ) . createTextNode ( ( ( TermString ) c ) . getValue ( ) ) ; pelem . appendChild ( txt ) ; } else if ( c instanceof TermURI ) { } else if ( c instanceof TermFunction . Attr ) { TermFunction . Attr f = ( TermFunction . Attr ) c ; String val = HTMLNorm . getAttribute ( n , f . getName ( ) ) ; Text txt = n . getOwnerDocument ( ) . createTextNode ( val ) ; pelem . appendChild ( txt ) ; } } decoder . useStyle ( pelem , null , style ) ; return pelem ; } else return null ; } else return null ; }
Creates a new box for a pseudo - element .
4,159
public Element createAnonymousElement ( Document doc , String name , String display ) { Element div = doc . createElement ( name ) ; div . setAttribute ( "class" , "Xanonymous" ) ; div . setAttribute ( "style" , "display:" + display ) ; return div ; }
Creates a new DOM element that represents an anonymous box in a document .
4,160
private void computeInheritedStyle ( ElementBox dest , ElementBox parent ) { NodeData newstyle = dest . getStyle ( ) . inheritFrom ( parent . getStyle ( ) ) ; dest . setStyle ( newstyle ) ; }
Computes the style of a node based on its parent using the CSS inheritance .
4,161
public void considerBox ( Inline box ) { if ( ( ( Box ) box ) . isDisplayed ( ) && ! box . collapsedCompletely ( ) ) { int a = box . getBaselineOffset ( ) ; int b = box . getBelowBaseline ( ) ; if ( box instanceof InlineElement ) { VerticalAlign va = ( ( InlineElement ) box ) . getVerticalAlign ( ) ; if ( va != VerticalAlign . TOP && va != VerticalAlign . BOTTOM ) { int dif = computeBaselineDifference ( ( InlineElement ) box ) ; a -= dif ; b += dif ; above = Math . max ( above , a ) ; below = Math . max ( below , b ) ; maxAlignedHeight = Math . max ( maxAlignedHeight , box . getMaxLineHeight ( ) ) ; } else if ( va == VerticalAlign . BOTTOM ) heightFromBottom = Math . max ( heightFromBottom , box . getMaxLineHeight ( ) ) ; } else { above = Math . max ( above , a ) ; below = Math . max ( below , b ) ; maxAlignedHeight = Math . max ( maxAlignedHeight , box . getMaxLineHeight ( ) ) ; } maxBoxHeight = Math . max ( maxBoxHeight , box . getMaxLineHeight ( ) ) ; } }
Updates the line box sizes according to a new inline box .
4,162
public void considerBoxProperties ( ElementBox box ) { VisualContext ctx = box . getVisualContext ( ) ; int a = ctx . getBaselineOffset ( ) ; int b = ctx . getFontHeight ( ) - ctx . getBaselineOffset ( ) ; above = Math . max ( above , a ) ; below = Math . max ( below , b ) ; maxAlignedHeight = Math . max ( maxAlignedHeight , box . getLineHeight ( ) ) ; }
Initializes the above and below offsets based on the font properties of the given box .
4,163
public int alignBox ( Inline box ) { if ( box instanceof InlineElement ) { VerticalAlign va = ( ( InlineElement ) box ) . getVerticalAlign ( ) ; if ( va == VerticalAlign . TOP || va == VerticalAlign . BOTTOM ) { return 0 ; } else { return above + computeBaselineDifference ( ( InlineElement ) box ) - box . getBaselineOffset ( ) + ( ( InlineElement ) box ) . getLineboxOffset ( ) ; } } else return above - box . getBaselineOffset ( ) ; }
Aligns a new box and updates the line metrics .
4,164
private int computeBaselineDifference ( InlineElement box ) { int a = box . getBaselineOffset ( ) ; int b = box . getBelowBaseline ( ) ; CSSProperty . VerticalAlign va = box . getVerticalAlign ( ) ; int dif = 0 ; if ( va == CSSProperty . VerticalAlign . BASELINE ) dif = 0 ; else if ( va == CSSProperty . VerticalAlign . MIDDLE ) { int midbox = box . getLineHeight ( ) / 2 ; int halfex = ( int ) Math . round ( parent . getVisualContext ( ) . getEx ( ) / 2 ) ; dif = midbox - halfex ; } else if ( va == CSSProperty . VerticalAlign . SUB ) dif = ( int ) Math . round ( 0.3 * parent . getLineHeight ( ) ) ; else if ( va == CSSProperty . VerticalAlign . SUPER ) dif = - ( int ) Math . round ( 0.3 * parent . getLineHeight ( ) ) ; else if ( va == CSSProperty . VerticalAlign . TEXT_TOP ) { int na = parent . getVisualContext ( ) . getBaselineOffset ( ) ; dif = a - na ; } else if ( va == CSSProperty . VerticalAlign . TEXT_BOTTOM ) { int nb = parent . getVisualContext ( ) . getFontHeight ( ) - parent . getVisualContext ( ) . getBaselineOffset ( ) ; dif = nb - b ; } else if ( va == CSSProperty . VerticalAlign . length || va == CSSProperty . VerticalAlign . percentage ) { CSSDecoder dec = new CSSDecoder ( ( ( ElementBox ) box ) . getVisualContext ( ) ) ; int len = dec . getLength ( ( ( ElementBox ) box ) . getLengthValue ( "vertical-align" ) , false , 0 , 0 , box . getLineHeight ( ) ) ; dif = - len ; } return dif ; }
Computes the difference between the box baseline and our baseline according to the vertical alignment of the box .
4,165
public int getLength ( TermLengthOrPercent value , boolean auto , int defval , int autoval , int whole ) { if ( auto ) return autoval ; else if ( value == null ) return defval ; else return ( int ) context . pxLength ( value , whole ) ; }
Returns the length in pixels from a CSS definition
4,166
public void copy ( LengthSet src ) { top = src . top ; right = src . right ; bottom = src . bottom ; left = src . left ; }
Copies all the values from an existing set .
4,167
protected void writeSVG ( Viewport vp , Writer out ) throws IOException { int w = vp . getClippedContentBounds ( ) . width ; int h = vp . getClippedContentBounds ( ) . height ; SVGRenderer render = new SVGRenderer ( w , h , out ) ; vp . draw ( render ) ; render . close ( ) ; }
Renders the viewport using an SVGRenderer to the given output writer .
4,168
public int match ( FontSpec font ) { if ( this . family . equalsIgnoreCase ( font . family ) ) { int ret = 100 ; if ( this . weight == null ) ret ++ ; else if ( representsBold ( this . weight ) == representsBold ( font . weight ) ) ret += 10 ; if ( this . style == null ) ret ++ ; else if ( this . style == font . style ) ret += 10 ; return ret ; } else return 0 ; }
Check whether the specified font corresponds to this font specification .
4,169
public boolean affectsDisplay ( ) { boolean ret = containsFlow ( ) ; if ( border . top > 0 || border . bottom > 0 ) ret = true ; if ( padding . top > 0 || padding . bottom > 0 ) ret = true ; return ret ; }
Returns true if the element displays at least something
4,170
public void setContentWidth ( int width ) { int w = width ; if ( max_size . width != - 1 && w > max_size . width ) w = max_size . width ; if ( min_size . width != - 1 && w < min_size . width ) w = min_size . width ; content . width = w ; }
Sets the width of the content while considering the min - and max - width .
4,171
public void setContentHeight ( int height ) { int h = height ; if ( max_size . height != - 1 && h > max_size . height ) h = max_size . height ; if ( min_size . height != - 1 && h < min_size . height ) h = min_size . height ; content . height = h ; }
Sets the height of the content while considering the min - and max - height .
4,172
protected void moveFloatsDown ( int ofs ) { floatY += ofs ; for ( int i = startChild ; i < endChild ; i ++ ) { Box box = getSubBox ( i ) ; if ( box instanceof BlockBox ) { BlockBox block = ( BlockBox ) box ; if ( block . isInFlow ( ) ) block . moveFloatsDown ( ofs ) ; else if ( block . getFloating ( ) != BlockBox . FLOAT_NONE ) block . moveDown ( ofs ) ; } } }
Moves down all the floating boxes contained in this box and its children .
4,173
private void alignLineHorizontally ( LineBox line , boolean isLast ) { final int dif = content . width - line . getLimits ( ) - line . getWidth ( ) ; if ( dif > 0 ) { if ( align == ALIGN_JUSTIFY ) { if ( ! isLast ) extendInlineChildWidths ( dif , line . getStart ( ) , line . getEnd ( ) , true , true ) ; } else if ( align != ALIGN_LEFT ) { for ( int i = line . getStart ( ) ; i < line . getEnd ( ) ; i ++ ) { Box subbox = getSubBox ( i ) ; if ( subbox instanceof Inline ) { if ( align == ALIGN_RIGHT ) subbox . moveRight ( dif ) ; else if ( align == ALIGN_CENTER ) subbox . moveRight ( dif / 2 ) ; } } } } }
Aligns the subboxes in a line according to the selected alignment settings .
4,174
public void computeEfficientMargins ( ) { emargin . top = margin . top ; emargin . bottom = margin . bottom ; if ( containsBlocks ( ) && containsFlow ( ) ) { BlockBox firstseparated = null ; int mbottom = 0 ; for ( int i = 0 ; i < getSubBoxNumber ( ) ; i ++ ) { BlockBox subbox = ( BlockBox ) getSubBox ( i ) ; if ( subbox . isDisplayed ( ) && subbox . isInFlow ( ) ) { subbox . computeEfficientMargins ( ) ; boolean boxempty = subbox . marginsAdjoin ( ) ; if ( firstseparated == null && ! separatedFromTop ( this ) ) { if ( subbox . emargin . top > emargin . top ) emargin . top = subbox . emargin . top ; } if ( boxempty ) { int m = Math . max ( subbox . emargin . top , subbox . emargin . bottom ) ; if ( m > mbottom ) mbottom = m ; } else mbottom = subbox . emargin . bottom ; if ( ! boxempty && firstseparated == null ) firstseparated = subbox ; } } if ( mbottom > emargin . bottom && ! separatedFromBottom ( this ) ) emargin . bottom = mbottom ; } if ( marginsAdjoin ( ) ) { emargin . top = Math . max ( emargin . top , emargin . bottom ) ; emargin . bottom = 0 ; } }
Computes the efficient sizes of in - flow margins for collapsing
4,175
public boolean doLayout ( int availw , boolean force , boolean linestart ) { if ( ! displayed ) { content . setSize ( 0 , 0 ) ; bounds . setSize ( 0 , 0 ) ; return true ; } clearSplitted ( ) ; if ( ! hasFixedWidth ( ) ) { int min = Math . max ( getMinimalContentWidthLimit ( ) , getMinimalContentWidth ( ) ) ; int max = getMaximalContentWidth ( ) ; int availcont = availw - emargin . left - border . left - padding . left - emargin . right - border . right - padding . right ; int pref = Math . min ( Math . max ( min , availcont ) , max ) ; setContentWidth ( pref ) ; updateChildSizes ( ) ; } widthComputed = true ; setAvailableWidth ( totalWidth ( ) ) ; if ( ! contblock ) layoutInline ( ) ; else layoutBlocks ( ) ; return true ; }
Layout the sub - elements .
4,176
protected void layoutBlockFloating ( BlockBox subbox , int wlimit , BlockLayoutStatus stat ) { subbox . setFloats ( new FloatList ( subbox ) , new FloatList ( subbox ) , 0 , 0 , 0 ) ; subbox . doLayout ( wlimit , true , true ) ; FloatList f = ( subbox . getFloating ( ) == FLOAT_LEFT ) ? fleft : fright ; FloatList of = ( subbox . getFloating ( ) == FLOAT_LEFT ) ? fright : fleft ; int floatX = ( subbox . getFloating ( ) == FLOAT_LEFT ) ? floatXl : floatXr ; int oFloatX = ( subbox . getFloating ( ) == FLOAT_LEFT ) ? floatXr : floatXl ; int fy = stat . y + floatY ; if ( fy < f . getLastY ( ) ) fy = f . getLastY ( ) ; int fx = f . getWidth ( fy ) ; if ( fx < floatX ) fx = floatX ; if ( fx == 0 && floatX < 0 ) fx = floatX ; int ofx = of . getWidth ( fy ) ; if ( ofx < oFloatX ) ofx = oFloatX ; if ( ofx == 0 && oFloatX < 0 ) ofx = oFloatX ; while ( ( fx > floatX || ofx > oFloatX || stat . inlineWidth > 0 ) && ( stat . inlineWidth + fx - floatX + ofx - oFloatX + subbox . getWidth ( ) > wlimit ) ) { int nexty = FloatList . getNextY ( fleft , fright , fy ) ; if ( nexty == - 1 ) fy += Math . max ( stat . maxh , getLineHeight ( ) ) ; else fy = nexty ; fx = f . getWidth ( fy ) ; if ( fx < floatX ) fx = floatX ; if ( fx == 0 && floatX < 0 ) fx = floatX ; ofx = of . getWidth ( fy ) ; if ( ofx < oFloatX ) ofx = oFloatX ; if ( ofx == 0 && oFloatX < 0 ) ofx = oFloatX ; stat . inlineWidth = 0 ; } subbox . setPosition ( fx , fy ) ; f . add ( subbox ) ; int floatw = maxFloatWidth ( fy , fy + subbox . getHeight ( ) ) ; if ( floatw > stat . maxw ) stat . maxw = floatw ; if ( stat . maxw > wlimit ) stat . maxw = wlimit ; }
Calculates the position for a floating box in the given context .
4,177
public void initFirstLine ( ElementBox box ) { if ( firstLine == null ) firstLine = new LineBox ( this , 0 , 0 ) ; firstLine . considerBoxProperties ( box ) ; for ( int i = startChild ; i < endChild ; i ++ ) { Box child = getSubBox ( i ) ; if ( child . isInFlow ( ) ) { if ( child . isBlock ( ) ) ( ( BlockBox ) child ) . initFirstLine ( box ) ; break ; } } }
Initializes the first line box with the box properties . This may be used for considering special content such as list item markers .
4,178
public void setLineBox ( LineBox linebox ) { this . linebox = linebox ; for ( int i = startChild ; i < endChild ; i ++ ) { Box sub = getSubBox ( i ) ; if ( sub instanceof InlineElement ) ( ( InlineElement ) sub ) . setLineBox ( linebox ) ; } }
Assigns the line box assigned to this inline box and all the inline sub - boxes .
4,179
public void copyValues ( TextBox src ) { super . copyValues ( src ) ; text = new String ( src . text ) ; ignoreinitialws = false ; collapsews = src . collapsews ; splitws = src . splitws ; linews = src . linews ; firstLineLength = src . firstLineLength ; lastLineLength = src . lastLineLength ; longestLineLength = src . longestLineLength ; containsLineBreak = src . containsLineBreak ; transform = src . transform ; wordSpacing = src . wordSpacing ; }
Copy all the values from another text box .
4,180
public TextBox copyTextBox ( ) { TextBox ret = new TextBox ( textNode , g , ctx ) ; ret . copyValues ( this ) ; return ret ; }
Create a new box from the same DOM node in the same context
4,181
public void setWhiteSpace ( CSSProperty . WhiteSpace value ) { splitws = ( value == ElementBox . WHITESPACE_NORMAL || value == ElementBox . WHITESPACE_PRE_WRAP || value == ElementBox . WHITESPACE_PRE_LINE ) ; collapsews = ( value == ElementBox . WHITESPACE_NORMAL || value == ElementBox . WHITESPACE_NOWRAP || value == ElementBox . WHITESPACE_PRE_LINE ) ; linews = ( value == ElementBox . WHITESPACE_NORMAL || value == ElementBox . WHITESPACE_NOWRAP ) ; if ( ! splitted ) applyWhiteSpace ( ) ; computeLineLengths ( ) ; minwidth = computeMinimalWidth ( ) ; maxwidth = computeMaximalWidth ( ) ; }
Sets the whitespace processing for this box . The text content is then treated accordingly . The text start and text end indices are reset to their initial values .
4,182
private String collapseWhitespaces ( String src ) { StringBuffer ret = new StringBuffer ( ) ; boolean inws = false ; for ( int i = 0 ; i < src . length ( ) ; i ++ ) { char ch = src . charAt ( i ) ; if ( collapsews && isWhitespace ( ch ) ) { if ( ! inws ) { ret . append ( ' ' ) ; inws = true ; } } else if ( isLineBreak ( ch ) ) { ret . append ( '\r' ) ; if ( ch == '\r' && i + 1 < src . length ( ) && src . charAt ( i + 1 ) == '\n' ) i ++ ; } else { inws = false ; ret . append ( ch ) ; } } return new String ( ret ) ; }
Applies the whitespace removal rules used in HTML .
4,183
private String applyTransformations ( String src ) { switch ( transform ) { case LOWERCASE : return src . toLowerCase ( ) ; case UPPERCASE : return src . toUpperCase ( ) ; case CAPITALIZE : StringBuilder ret = new StringBuilder ( src . length ( ) ) ; boolean ws = true ; for ( int i = 0 ; i < src . length ( ) ; i ++ ) { char ch = src . charAt ( i ) ; if ( Character . isWhitespace ( ch ) ) ws = true ; else { if ( ws ) ch = Character . toUpperCase ( ch ) ; ws = false ; } ret . append ( ch ) ; } return ret . toString ( ) ; default : return src ; } }
Applies the text transformations to a string according to the current style .
4,184
public int getCharOffsetXElem ( int pos ) { if ( text != null ) { FontMetrics fm = g . getFontMetrics ( ) ; if ( pos <= textStart ) return 0 ; else if ( pos > textStart && pos < textEnd ) return stringWidth ( fm , text . substring ( textStart , pos ) ) ; else return stringWidth ( fm , text . substring ( textStart , textEnd ) ) ; } else return 0 ; }
Computes the X pixel offset of the given character of the box text . The character position is specified within the whole source text node .
4,185
protected void computeLineLengths ( ) { firstLineLength = - 1 ; lastLineLength = 0 ; longestLineLength = 0 ; String t = getText ( ) ; FontMetrics fm = g . getFontMetrics ( ) ; int s1 = 0 ; int s2 = t . indexOf ( '\r' ) ; int w = 0 ; do { if ( s2 == - 1 ) s2 = t . length ( ) ; else containsLineBreak = true ; w = stringWidth ( fm , t . substring ( s1 , s2 ) ) ; if ( firstLineLength == - 1 ) firstLineLength = w ; if ( w > longestLineLength ) longestLineLength = w ; s1 = s2 + 1 ; s2 = t . indexOf ( '\r' , s1 ) ; } while ( s1 < t . length ( ) && s2 < t . length ( ) ) ; lastLineLength = w ; }
Computes the lengths of the first last and longest lines .
4,186
private int stringWidth ( FontMetrics fm , String text ) { int w = fm . stringWidth ( text ) ; if ( wordSpacing != null ) { float add = 0.0f ; for ( int i = 0 ; i < text . length ( ) ; i ++ ) { if ( text . charAt ( i ) == ' ' ) add += wordSpacing ; } w = Math . round ( w + add ) ; } return w ; }
Computes the final width of a string while considering word - spacing
4,187
private void drawAttributedString ( Graphics2D g , int x , int y , String text ) { if ( ! ctx . getTextDecoration ( ) . isEmpty ( ) ) { AttributedString as = new AttributedString ( text ) ; as . addAttribute ( TextAttribute . FONT , ctx . getFont ( ) ) ; if ( ctx . getTextDecoration ( ) . contains ( CSSProperty . TextDecoration . UNDERLINE ) ) as . addAttribute ( TextAttribute . UNDERLINE , TextAttribute . UNDERLINE_ON ) ; if ( ctx . getTextDecoration ( ) . contains ( CSSProperty . TextDecoration . LINE_THROUGH ) ) as . addAttribute ( TextAttribute . STRIKETHROUGH , TextAttribute . STRIKETHROUGH_ON ) ; g . drawString ( as . getIterator ( ) , x , y + getBaselineOffset ( ) ) ; } else g . drawString ( text , x , y + getBaselineOffset ( ) ) ; }
Draws a single string with eventual attributes based on the current visual context .
4,188
private boolean isWhitespace ( char ch ) { if ( linews ) return Character . isWhitespace ( ch ) ; else return ch != '\n' && ch != '\r' && Character . isWhitespace ( ch ) ; }
Checks if a character can be interpreted as whitespace according to current settings .
4,189
public String getTextDecorationString ( ) { if ( textDecoration . isEmpty ( ) ) return "none" ; else { StringBuilder ret = new StringBuilder ( ) ; for ( CSSProperty . TextDecoration dec : textDecoration ) { if ( ret . length ( ) > 0 ) ret . append ( ' ' ) ; ret . append ( dec . toString ( ) ) ; } return ret . toString ( ) ; } }
Returns the text decoration used for the box .
4,190
public void updateGraphics ( Graphics2D g ) { g . setFont ( font ) ; g . setColor ( color ) ; g . setRenderingHint ( RenderingHints . KEY_ANTIALIASING , RenderingHints . VALUE_ANTIALIAS_OFF ) ; g . setRenderingHint ( RenderingHints . KEY_TEXT_ANTIALIASING , RenderingHints . VALUE_TEXT_ANTIALIAS_ON ) ; }
Updates a Graphics according to this context
4,191
public void updateForGraphics ( NodeData style , Graphics2D g ) { if ( style != null ) update ( style ) ; updateGraphics ( g ) ; fm = g . getFontMetrics ( ) ; FontRenderContext frc = new FontRenderContext ( null , false , false ) ; TextLayout layout = new TextLayout ( "x" , font , frc ) ; ex = layout . getBounds ( ) . getHeight ( ) ; ch = fm . charWidth ( '0' ) ; }
Updates this context according to the given style . Moreover given Graphics is updated to this style and used for taking the font metrics .
4,192
public double ptLength ( TermLengthOrPercent spec , double whole ) { float nval = spec . getValue ( ) ; if ( spec . isPercentage ( ) ) { return ( whole * nval ) / 100 ; } else if ( spec instanceof TermCalc ) { final CalcArgs args = ( ( TermCalc ) spec ) . getArgs ( ) ; return args . evaluate ( getPtEval ( ) . setWhole ( whole ) ) ; } else { final TermLength . Unit unit = spec . getUnit ( ) ; if ( unit == null ) return 0 ; switch ( unit ) { case pt : return nval ; case in : return nval * 72 ; case cm : return ( nval * 72 ) / 2.54 ; case mm : return ( nval * 72 ) / 25.4 ; case q : return ( nval * 72 ) / ( 2.54 * 40.0 ) ; case pc : return nval * 12 ; case px : return ( nval * 72 ) / dpi ; case em : return ( em * nval * 72 ) / dpi ; case rem : return ( rem * nval * 72 ) / dpi ; case ex : return ( ex * nval * 72 ) / dpi ; case ch : return ( ch * nval * 72 ) / dpi ; case vw : return ( viewport . getVisibleRect ( ) . getWidth ( ) * nval * 72 ) / ( 100.0 * dpi ) ; case vh : return ( viewport . getVisibleRect ( ) . getHeight ( ) * nval * 72 ) / ( 100.0 * dpi ) ; case vmin : return ( Math . min ( viewport . getVisibleRect ( ) . getWidth ( ) , viewport . getVisibleRect ( ) . getHeight ( ) ) * nval * 72 ) / ( 100.0 * dpi ) ; case vmax : return ( Math . max ( viewport . getVisibleRect ( ) . getWidth ( ) , viewport . getVisibleRect ( ) . getHeight ( ) ) * nval * 72 ) / ( 100.0 * dpi ) ; default : return 0 ; } } }
Converts a length from a CSS length or percentage to pt .
4,193
public double radAngle ( TermAngle spec ) { float nval = spec . getValue ( ) ; final TermLength . Unit unit = spec . getUnit ( ) ; if ( spec instanceof TermCalcAngleImpl ) { final CalcArgs args = ( ( TermCalc ) spec ) . getArgs ( ) ; return args . evaluate ( getRadEval ( ) ) ; } else { if ( unit == null ) return 0 ; switch ( unit ) { case deg : return ( nval * Math . PI ) / 180.0 ; case grad : return ( nval * Math . PI ) / 200.0 ; case rad : return nval ; case turn : return nval * 2 * Math . PI ; default : return 0 ; } } }
Converts an angle from a CSS angle to rad .
4,194
private String getFontName ( TermList list , CSSProperty . FontWeight weight , CSSProperty . FontStyle style ) { for ( Term < ? > term : list ) { Object value = term . getValue ( ) ; if ( value instanceof CSSProperty . FontFamily ) return ( ( CSSProperty . FontFamily ) value ) . getAWTValue ( ) ; else { String name = lookupFont ( value . toString ( ) , weight , style ) ; if ( name != null ) return name ; } } return java . awt . Font . SERIF ; }
Scans a list of font definitions and chooses the first one that is available
4,195
private String lookupFont ( String family , CSSProperty . FontWeight weight , CSSProperty . FontStyle style ) { final String systemFontNames [ ] = GraphicsEnvironment . getLocalGraphicsEnvironment ( ) . getAvailableFontFamilyNames ( ) ; String nameFound = null ; FontSpec spec = new FontSpec ( family , weight , style ) ; List < RuleFontFace . Source > srcs = findMatchingFontSources ( spec ) ; if ( srcs != null ) { for ( RuleFontFace . Source src : srcs ) { if ( src instanceof RuleFontFace . SourceLocal ) { String name = fontAvailable ( ( ( RuleFontFace . SourceLocal ) src ) . getName ( ) , systemFontNames ) ; if ( name != null ) { nameFound = name ; break ; } } else if ( src instanceof RuleFontFace . SourceURL && viewport . getConfig ( ) . isLoadFonts ( ) ) { try { TermURI urlstring = ( ( RuleFontFace . SourceURL ) src ) . getURI ( ) ; String format = ( ( RuleFontFace . SourceURL ) src ) . getFormat ( ) ; if ( format == null || FontDecoder . supportedFormats . contains ( format ) ) { URL url = DataURLHandler . createURL ( urlstring . getBase ( ) , urlstring . getValue ( ) ) ; String regName = FontDecoder . findRegisteredFont ( url ) ; if ( regName == null ) { DocumentSource imgsrc = viewport . getConfig ( ) . createDocumentSource ( url ) ; Font newFont = FontDecoder . decodeFont ( imgsrc , format ) ; if ( GraphicsEnvironment . getLocalGraphicsEnvironment ( ) . registerFont ( newFont ) ) log . debug ( "Registered font: {}" , newFont . getFontName ( ) ) ; else log . debug ( "Failed to register font: {} (not fatal, probably already existing)" , newFont . getFontName ( ) ) ; regName = newFont . getFontName ( ) ; FontDecoder . registerFont ( url , regName ) ; } nameFound = regName ; } } catch ( MalformedURLException e ) { log . error ( "Couldn't load font with URI {} ({})" , ( ( RuleFontFace . SourceURL ) src ) . getURI ( ) , e . getMessage ( ) ) ; } catch ( IOException e ) { log . error ( "Couldn't load font with URI {} ({})" , ( ( RuleFontFace . SourceURL ) src ) . getURI ( ) , e . getMessage ( ) ) ; } catch ( FontFormatException e ) { log . error ( "Couldn't decode font with URI {} ({})" , ( ( RuleFontFace . SourceURL ) src ) . getURI ( ) , e . getMessage ( ) ) ; } } } } if ( nameFound == null ) { nameFound = fontAvailable ( family , systemFontNames ) ; } return nameFound ; }
Check if the font family is available either among the CSS defined fonts or the system fonts . If found registers a system font with the given name .
4,196
private String fontAvailable ( String family , String [ ] avail ) { for ( int i = 0 ; i < avail . length ; i ++ ) if ( avail [ i ] . equalsIgnoreCase ( family ) ) return avail [ i ] ; return null ; }
Returns true if the font family is available .
4,197
public static double convertFontSize ( double parent , CSSProperty . FontSize value ) { double em = parent ; double ret = em ; if ( value == CSSProperty . FontSize . MEDIUM ) ret = medium_font ; else if ( value == CSSProperty . FontSize . SMALL ) ret = medium_font / font_step ; else if ( value == CSSProperty . FontSize . X_SMALL ) ret = medium_font / font_step / font_step ; else if ( value == CSSProperty . FontSize . XX_SMALL ) ret = medium_font / font_step / font_step / font_step ; else if ( value == CSSProperty . FontSize . LARGE ) ret = medium_font * font_step ; else if ( value == CSSProperty . FontSize . X_LARGE ) ret = medium_font * font_step * font_step ; else if ( value == CSSProperty . FontSize . XX_LARGE ) ret = medium_font * font_step * font_step * font_step ; else if ( value == CSSProperty . FontSize . SMALLER ) ret = em / font_step ; else if ( value == CSSProperty . FontSize . LARGER ) ret = em * font_step ; return ret ; }
Converts the font size given by an identifier to absolute length in pixels .
4,198
public static int convertBorderWidth ( CSSProperty . BorderWidth width ) { if ( width == CSSProperty . BorderWidth . THIN ) return THIN_BORDER ; else if ( width == CSSProperty . BorderWidth . MEDIUM ) return MEDIUM_BORDER ; else return THICK_BORDER ; }
Converts the border size given by an identifier to an absolute value .
4,199
public static java . awt . Color convertColor ( cz . vutbr . web . csskit . Color src ) { return new java . awt . Color ( src . getRGB ( ) , true ) ; }
Convetrs the CSS parser color representation to the AWT color used by CSSBox .