30#include <glib/gi18n.h>
60#define WRITEOUT_BUFFER(buff) fwrite((buff)->str, sizeof(char), (buff)->len, tex_file)
79 for (list = layer_infos; list != NULL; list = list->next) {
85 g_string_printf(buffer,
"\\pgfdeclarelayer{l%d}\n\\definecolor{c%d}{rgb}{%lf,%lf,%lf}\n",
91 g_string_printf(buffer,
"\\pgfsetlayers{");
94 for (list = layer_infos; list != NULL; list = list->next) {
100 g_string_printf(buffer,
"l%d,", lifo->
layer);
103 g_string_printf(buffer,
"main}\n");
138 for (temp = linfo; temp != NULL; temp = temp->next) {
145 g_string_printf(buffer,
146 "\\begin{pgfonlayer}{l%d}\n\\ifcreatepdflayers\n\\begin{scope}[ocg={ref=%d, status=visible,name={%s}}]\n\\fi\n",
166static void generate_graphics(FILE *tex_file, GList *graphics, GList *linfo, GString *buffer,
double scale)
173 static const char *
const line_caps[] = {
"butt",
"round",
"rect"};
175 for (temp = graphics; temp != NULL; temp = temp->next) {
181 g_string_printf(buffer,
182 "\\draw[line width=0.00001 pt, draw={c%d}, fill={c%d}, fill opacity={%lf}] ",
188 temp_vertex = temp_vertex->next) {
189 pt = (
struct gds_point *)temp_vertex->data;
190 g_string_printf(buffer,
"(%lf pt, %lf pt) -- ",
191 ((
double)pt->
x)/scale,
192 ((double)pt->
y)/scale);
195 g_string_printf(buffer,
"cycle;\n");
199 if (g_list_length(gfx->
vertices) < 2) {
200 printf(
"Cannot write path with less than 2 points\n");
205 printf(
"Path type unrecognized. Setting to 'flushed'\n");
209 g_string_printf(buffer,
"\\draw[line width=%lf pt, draw={c%d}, opacity={%lf}, cap=%s] ",
217 temp_vertex = temp_vertex->next) {
218 pt = (
struct gds_point *)temp_vertex->data;
219 g_string_printf(buffer,
"(%lf pt, %lf pt)%s",
220 ((
double)pt->
x)/scale,
221 ((double)pt->
y)/scale,
222 (temp_vertex->next ?
" -- " :
""));
225 g_string_printf(buffer,
";\n");
229 g_string_printf(buffer,
"\\ifcreatepdflayers\n\\end{scope}\n\\fi\n\\end{pgfonlayer}\n");
245static void render_cell(
struct gds_cell *cell, GList *layer_infos, FILE *tex_file, GString *buffer,
double scale,
246 GdsOutputRenderer *renderer)
252 status = g_string_new(NULL);
253 g_string_printf(status, _(
"Generating cell %s"), cell->
name);
255 g_string_free(status, TRUE);
261 for (list_child = cell->
child_cells; list_child != NULL; list_child = list_child->next) {
269 g_string_printf(buffer,
"\\begin{scope}[shift={(%lf pt,%lf pt)}]\n",
270 ((
double)inst->
origin.
x) / scale, ((
double)inst->
origin.
y) / scale);
273 g_string_printf(buffer,
"\\begin{scope}[rotate=%lf]\n", inst->
angle);
276 g_string_printf(buffer,
"\\begin{scope}[yscale=%lf, xscale=%lf]\n",
283 g_string_printf(buffer,
"\\end{scope}\n");
286 g_string_printf(buffer,
"\\end{scope}\n");
289 g_string_printf(buffer,
"\\end{scope}\n");
296 gboolean create_pdf_layers, gboolean standalone_document, GdsOutputRenderer *renderer)
298 GString *working_line;
301 if (!tex_file || !layer_infos || !cell)
308 g_string_printf(working_line,
"\\newif\\iftestmode\n\\testmode%s\n",
309 (standalone_document ?
"true" :
"false"));
311 g_string_printf(working_line,
"\\newif\\ifcreatepdflayers\n\\createpdflayers%s\n",
312 (create_pdf_layers ?
"true" :
"false"));
314 g_string_printf(working_line,
"\\iftestmode\n");
316 g_string_printf(working_line,
317 "\\documentclass[tikz]{standalone}\n\\usepackage{xcolor}\n\\usetikzlibrary{ocgx}\n\\begin{document}\n");
319 g_string_printf(working_line,
"\\fi\n");
326 g_string_printf(working_line,
"\\begin{tikzpicture}\n");
330 render_cell(cell, layer_infos, tex_file, working_line, scale, renderer);
333 g_string_printf(working_line,
"\\end{tikzpicture}\n");
336 g_string_printf(working_line,
"\\iftestmode\n");
338 g_string_printf(working_line,
"\\end{document}\n");
340 g_string_printf(working_line,
"\\fi\n");
344 g_string_free(working_line, TRUE);
353 LatexRenderer *l_renderer = GDS_RENDER_LATEX_RENDERER(renderer);
356 LayerSettings *settings;
357 GList *layer_infos = NULL;
358 const char *output_file;
367 tex_file = fopen(output_file,
"w");
370 l_renderer->pdf_layers, l_renderer->tex_standalone, renderer);
373 g_warning(_(
"Could not open LaTeX output file"));
377 g_object_unref(settings);
384 self->pdf_layers = FALSE;
385 self->tex_standalone = FALSE;
390 LatexRenderer *self = GDS_RENDER_LATEX_RENDERER(obj);
392 switch (property_id) {
394 g_value_set_boolean(value, self->tex_standalone);
397 g_value_set_boolean(value, self->pdf_layers);
400 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
407 LatexRenderer *self = GDS_RENDER_LATEX_RENDERER(obj);
409 switch (property_id) {
411 self->tex_standalone = g_value_get_boolean(value);
414 self->pdf_layers = g_value_get_boolean(value);
417 G_OBJECT_WARN_INVALID_PROPERTY_ID(obj, property_id, pspec);
426 GdsOutputRendererClass *render_class = GDS_RENDER_OUTPUT_RENDERER_CLASS(klass);
427 GObjectClass *oclass = G_OBJECT_CLASS(klass);
437 g_param_spec_boolean(
"standalone",
438 N_(
"Standalone TeX file"),
439 N_(
"Generate a standalone LaTeX file."),
443 g_param_spec_boolean(
"pdf-layers",
444 N_(
"PDF OCR layers"),
445 N_(
"Generate OCR layers"),
462 return GDS_RENDER_LATEX_RENDERER(obj);
@ GRAPHIC_POLYGON
An arbitrary polygon.
@ GRAPHIC_PATH
Path. Esentially a line.
@ GRAPHIC_BOX
A rectangle.
const char * gds_output_renderer_get_output_file(GdsOutputRenderer *renderer)
Convenience function for getting the "output-file" property.
void gds_output_renderer_update_async_progress(GdsOutputRenderer *renderer, const char *status)
This function emits the 'progress-changed' in the thread/context that triggered an asynchronous rende...
LayerSettings * gds_output_renderer_get_and_ref_layer_settings(GdsOutputRenderer *renderer)
Get layer settings.
#define GDS_RENDER_TYPE_OUTPUT_RENDERER
static void write_layer_definitions(FILE *tex_file, GList *layer_infos, GString *buffer)
Write the layer declarration to TeX file.
static int latex_render_cell_to_code(struct gds_cell *cell, GList *layer_infos, FILE *tex_file, double scale, gboolean create_pdf_layers, gboolean standalone_document, GdsOutputRenderer *renderer)
static void latex_renderer_get_property(GObject *obj, guint property_id, GValue *value, GParamSpec *pspec)
static GParamSpec * latex_renderer_properties[N_PROPERTIES]
static int latex_renderer_render_output(GdsOutputRenderer *renderer, struct gds_cell *cell, double scale)
static gboolean write_layer_env(FILE *tex_file, GdkRGBA *color, int layer, GList *linfo, GString *buffer)
Write layer Envirmonment.
LatexRenderer * latex_renderer_new_with_options(gboolean pdf_layers, gboolean standalone)
Create new LatexRenderer object.
#define LATEX_LINE_BUFFER_KB
Buffer for LaTeX Code line in KiB.
static void latex_renderer_set_property(GObject *obj, guint property_id, const GValue *value, GParamSpec *pspec)
#define WRITEOUT_BUFFER(buff)
Writes a GString buffer to the fixed file tex_file.
LatexRenderer * latex_renderer_new()
Create new LatexRenderer object.
static void render_cell(struct gds_cell *cell, GList *layer_infos, FILE *tex_file, GString *buffer, double scale, GdsOutputRenderer *renderer)
Render cell to file.
static void latex_renderer_class_init(LatexRendererClass *klass)
static void latex_renderer_init(LatexRenderer *self)
#define GDS_RENDER_TYPE_LATEX_RENDERER
static void generate_graphics(FILE *tex_file, GList *graphics, GList *linfo, GString *buffer, double scale)
Writes a graphics object to the specified tex_file.
GList * layer_settings_get_layer_info_list(LayerSettings *settings)
Get a GList with layer_info structs.
Struct representing the LaTeX-Renderer object.
This represents an instanc of a cell inside another cell.
int flipped
Mirrored on x-axis before rotation.
double angle
Angle of rotation (counter clockwise) in degrees.
double magnification
magnification
struct gds_cell * cell_ref
Referenced gds_cell structure.
struct gds_point origin
Origin.
A Cell inside a gds_library.
GList * child_cells
List of gds_cell_instance elements.
GList * graphic_objs
List of gds_graphics.
enum graphics_type gfx_type
Type of graphic.
enum path_type path_render_type
Line cap.
int width_absolute
Width. Not used for objects other than paths.
int16_t layer
Layer the graphic object is on.
GList * vertices
List of gds_point.
A point in the 2D plane. Sometimes referred to as vertex.
int render
true: Render to output
GdkRGBA color
RGBA color used to render this layer.