linuxdoc.kfigure module¶
scalable figure and image handling¶
Sphinx extension which implements scalable image handling. User documentation see Scalable figure and image handling
- class linuxdoc.kfigure.KernelFigure(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶
Bases:
FigureKernelImage directive
Earns everything from
.. figure::directive, except remote URI and glob pattern. The KernelFigure wraps a figure node into a kernel_figure node. Seevisit_kernel_figure.
- class linuxdoc.kfigure.KernelImage(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶
Bases:
ImageKernelImage directive
Earns everything from
.. image::directive, except remote URI and glob pattern. The KernelImage wraps a image node into a kernel_image node. Seevisit_kernel_image.
- class linuxdoc.kfigure.KernelRender(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]¶
Bases:
FigureKernelRender directive
Render content by external tool. Has all the options known from the figure directive, plus option
caption. Ifcaptionhas a value, a figure node with the caption is inserted. If not, a image node is inserted.The KernelRender directive wraps the text of the directive into a literal_block node and wraps it into a kernel_render node. See
visit_kernel_render.- final_argument_whitespace = False¶
May the final argument contain whitespace?
- has_content = True¶
May the directive have content?
- option_spec = {'align': <function Figure.align>, 'alt': <function unchanged>, 'caption': <function unchanged>, 'class': <function class_option>, 'figclass': <function class_option>, 'figwidth': <function Figure.figwidth_value>, 'height': <function length_or_unitless>, 'loading': <function Image.loading>, 'name': <function unchanged>, 'scale': <function percentage>, 'target': <function unchanged_required>, 'width': <function length_or_percentage_or_unitless>}¶
Mapping of option names to validator functions.
- optional_arguments = 0¶
Number of optional arguments after the required arguments.
- required_arguments = 1¶
Number of required directive arguments.
- linuxdoc.kfigure.add_kernel_figure_to_std_domain(app, doctree)[source]¶
Add kernel-figure anchors to ‘std’ domain.
The
StandardDomain.process_doc(..)method does not know how to resolve the caption (label) ofkernel-figuredirective (it only knows about standard nodes, e.g. table, figure etc.). Without any additional handling this will result in a ‘undefined label’ for kernel-figures.This handle adds labels of kernel-figure to the ‘std’ domain labels.
- linuxdoc.kfigure.convert_image(img_node, translator, src_fname=None)[source]¶
Convert a image node for the builder.
Different builder prefer different image formats, e.g. latex builder prefer PDF while html builder prefer SVG format for images.
This function handles output image formats in dependence of source the format (of the image) and the translator’s output format.
- linuxdoc.kfigure.dot2format(app, dot_fname, out_fname)[source]¶
Converts DOT file to
out_fnameusingdot(1).dot_fnamepathname of the input DOT file, including extension.dotout_fnamepathname of the output file, including format extension
The format extension depends on the
dotcommand (seeman dotoption-Txxx). Normally you will use one of the following extensions:.psfor PostScript,.svgorsvgzfor Structured Vector Graphics,.figfor XFIG graphics and.pngorgiffor common bitmap graphics.
- linuxdoc.kfigure.isNewer(path1, path2)[source]¶
Returns True if
path1is newer thanpath2If
path1exists and is newer thanpath2the function returnsTrueis returned otherwiseFalse
- class linuxdoc.kfigure.kernel_figure(rawsource='', *children, **attributes)[source]¶
Bases:
figureNode for
kernel-figuredirective.
- class linuxdoc.kfigure.kernel_image(rawsource='', *children, **attributes)[source]¶
Bases:
imageNode for
kernel-imagedirective.
- class linuxdoc.kfigure.kernel_render(rawsource='', *children, **attributes)[source]¶
Bases:
General,Inline,ElementNode for
kernel-renderdirective.
- linuxdoc.kfigure.setupTools(app)[source]¶
Check available build tools and log some verbose messages.
This function is called once, when the builder is initiated.
- linuxdoc.kfigure.svg2pdf(app, svg_fname, pdf_fname)[source]¶
Converts SVG to PDF with
convert(1)command.Uses
convert(1)from ImageMagick (https://www.imagemagick.org) for conversion. ReturnsTrueon success andFalseif an error occurred.svg_fnamepathname of the input SVG file with extension (.svg)pdf_namepathname of the output PDF file with extension (.pdf)
- linuxdoc.kfigure.visit_kernel_figure(self, node)[source]¶
Visitor of the
kernel_figureNode.Handles the
imagechild-node with theconvert_image(...).
- linuxdoc.kfigure.visit_kernel_image(self, node)[source]¶
Visitor of the
kernel_imageNode.Handles the
imagechild-node with theconvert_image(...).
- linuxdoc.kfigure.visit_kernel_render(self, node)[source]¶
Visitor of the
kernel_renderNode.If rendering tools available, save the markup of the
literal_blockchild node into a file and replace theliteral_blocknode with a new createdimagenode, pointing to the saved markup file. Afterwards, handle the image child-node with theconvert_image(...).