Commit 30df6ded authored by platypro's avatar platypro

Updated build to work where PDF support is not enabled.

parent 8790f7ef
find_package(Threads)
find_package(PkgConfig)
set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_FULL_LIBDIR} ${CMAKE_INSTALL_PREFIX}/lib)
......@@ -26,6 +25,7 @@ set(SRCS
)
IF(QUIZGRIND_BUILD_PDF)
find_package(PkgConfig)
pkg_search_module(CAIRO cairo)
pkg_search_module(RSVG librsvg-2.0)
pkg_search_module(PANGO pango)
......
......@@ -9,6 +9,7 @@
#ifndef INC_PDF_H
#define INC_PDF_H
#ifdef _QUIZGRIND_BUILD_PDF
#include <cairo/cairo.h>
#include <cairo/cairo-pdf.h>
#include <librsvg/rsvg.h>
......@@ -81,6 +82,10 @@ extern int pdf_draw_shortfield(struct WidgetDrawCtx* ctx,
extern void pdf_set_xy(struct WidgetDrawCtx* ctx, int x, int y);
extern bool gen_pdf(struct PG_State* state, struct ProblemSet* pset);
#else
typedef struct PG_Pdf {} PG_PDF;
typedef struct WidgetDrawCtx {} WIDGETDRAWCTX;
#endif
#endif /* INC_PDF_H */
......
......@@ -56,7 +56,8 @@ bool gen_json(PG_STATE* state, PROBLEMSET* pset)
{
FILE *sf = NULL, *f = fopen(state->gen_file, "w");
if(!f) return false;
WJWriter solwriter, writer = WJWOpenFILEDocument(true, f);
WJWriter writer = WJWOpenFILEDocument(true, f);
WJWriter solwriter = writer;
QUIZ* quiz = exercise_mkQuiz(state, pset, QTYPE_NORMAL, state->gen_num);
QUESTION* q = NULL;
......
......@@ -11,6 +11,7 @@
#include <stdarg.h>
#include <wjelement.h>
#include <pdf.h>
struct Question;
struct Widget;
......
#include "common.h"
#include "choiceInput/backend.h"
#include <widget.h>
#include <exercise.h>
#include <pdf.h>
#include <string.h>
#include "widget.h"
#include "exercise.h"
bool widget_choiceInput_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWERSTATE* ans)
{
WJElement array = WJEArray(wid->options, KEY_CHOICEINPUT_CHOICES, WJE_GET)->child;
char choiceAt[3] = "a)";
#ifdef _QUIZGRIND_BUILD_PDF
if(pdf)
{
// Print number of selections
......@@ -23,18 +25,21 @@ bool widget_choiceInput_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWER
pdf_pushy(pdf, titleHeight);
pango_layout_set_attributes(pdf->textLayout, NULL);
}
#endif
while(array)
{
char* choice = WJEString(array, NULL, WJE_GET, NULL);
PROCESSEDSTRING str = exercise_processString(q, choice);
#ifdef _QUIZGRIND_BUILD_PDF
int choiceHeight = 0;
if(pdf)
pdf_set_xy(pdf,
DEF_CHOICEINPUT_INDSIZE + PDF_WPADDING_X,
DEF_CHOICEINPUT_PADDING);
#endif
if(str.class == PSCLASS_NORMAL)
{
switch(str.type)
......@@ -53,25 +58,28 @@ bool widget_choiceInput_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWER
widget_pushSolution(ans, SOLTYPE_INPUT, "%s %s", choiceAt, choice);
}
#ifdef _QUIZGRIND_BUILD_PDF
if(pdf)
{
choiceHeight = pdf_set_text(pdf, choice, -1, pdf->w);
choiceHeight += DEF_CHOICEINPUT_PADDING * 2;
pango_cairo_show_layout(pdf->cairo, pdf->textLayout);
}
#endif
if(str.type == PSTYPE_TEMPLATE)
free(choice);
}
else if(str.class == PSCLASS_SVG)
{
RsvgDimensionData dimens;
if(strchr(wid->key, *choiceAt - 'a' + '0') && ans)
{
widget_pushSolution(ans, SOLTYPE_INPUT, "%s <Image>", choiceAt);
}
#ifdef _QUIZGRIND_BUILD_PDF
if(pdf)
{
RsvgDimensionData dimens;
RsvgHandle* svgHandle = pdf_loadSvg(&str);
if(svgHandle)
{
......@@ -86,8 +94,10 @@ bool widget_choiceInput_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWER
g_object_unref(svgHandle);
}
}
#endif
}
#ifdef _QUIZGRIND_BUILD_PDF
if(pdf)
{
pdf_set_text(pdf, choiceAt, -1, PDF_QNUM_PADDING);
......@@ -95,6 +105,7 @@ bool widget_choiceInput_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWER
pango_cairo_show_layout(pdf->cairo, pdf->textLayout);
pdf_pushy(pdf, choiceHeight);
}
#endif
array = array->next;
choiceAt[0] = ((choiceAt[0] - '`') % 25) + 'a';
......
......@@ -7,6 +7,7 @@
bool widget_imageView_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWERSTATE* ans)
{
#ifdef _QUIZGRIND_BUILD_PDF
PROCESSEDSTRING src =
exercise_processString(q, WJEString(wid->options, KEY_IMAGEVIEW_SRC, WJE_GET, NULL));
if(src.class == PSCLASS_SVG)
......@@ -26,5 +27,6 @@ bool widget_imageView_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWERST
pdf_pushy(pdf, dimens.height);
}
}
#endif
return true;
}
......@@ -9,5 +9,4 @@
#define widget_imageView_answer_check widget_no_answer_check
extern bool widget_imageView_pdf(struct Widget*, struct Question*, struct WidgetDrawCtx*, struct AnswerState*);
#endif /* INC_IMAGEVIEW_H */
......@@ -7,6 +7,7 @@
bool widget_lineInput_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWERSTATE* ans)
{
#ifdef _QUIZGRIND_BUILD_PDF
uint32_t length = WJEUInt32(wid->options, KEY_LINEINPUT_LENGTH, WJE_GET, 0);
while(length)
{
......@@ -19,5 +20,6 @@ bool widget_lineInput_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWERST
pdf_pushy( pdf, lineHeight);
length--;
}
#endif
return true;
}
......@@ -3,19 +3,19 @@
#include <math.h>
#include "pdf.h"
#include "exercise.h"
#include "widget.h"
bool widget_numberInput_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWERSTATE* ans)
{
char* hint = WJEString(wid->options, KEY_NUMBERINPUT_HINT, WJE_GET, NULL);
uint32_t mindp = WJEUInt32(wid->options, KEY_NUMBERINPUT_MINDP, WJE_GET, 0);
widget_pushSolution(ans, SOLTYPE_INPUT, "%s %s", hint ? hint : "", wid->key);
#ifdef _QUIZGRIND_BUILD_PDF
if(pdf)
{
char* key = alloca(60);
uint32_t mindp = WJEUInt32(wid->options, KEY_NUMBERINPUT_MINDP, WJE_GET, 0);
if(mindp)
snprintf(key, 60, "Answer the above to a minimum of %d decimal place%s", mindp, mindp>1?"s":"");
else key = NULL;
......@@ -25,6 +25,7 @@ bool widget_numberInput_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWER
pdf_pushy( pdf, pdf_draw_shortfield( pdf, pdf->w - 2*PDF_WPADDING_X, hint, -1, key, -1));
pango_layout_set_alignment( pdf->textLayout, PANGO_ALIGN_LEFT);
}
#endif
return true;
}
......
#include "common.h"
#include "textInput/backend.h"
#include <widget.h>
#include <exercise.h>
#include <pdf.h>
#include <ctype.h>
#include <string.h>
#include "widget.h"
#include "exercise.h"
bool widget_textInput_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWERSTATE* ans)
{
char* hint = WJEString(wid->options, KEY_TEXTINPUT_HINT, WJE_GET, NULL);
char* key = WJEBool(wid->options, KEY_TEXTINPUT_CAPS, WJE_GET, FALSE)
? "The above answer is case sensitive." : NULL;
if(ans)
widget_pushSolution(ans, SOLTYPE_INPUT, "%s %s", hint ? hint : "", wid->key);
#ifdef _QUIZGRIND_BUILD_PDF
if(pdf)
{
char* key = WJEBool(wid->options, KEY_TEXTINPUT_CAPS, WJE_GET, FALSE)
? "The above answer is case sensitive." : NULL;
pdf_set_xy( pdf, PDF_WPADDING_X, 0);
pango_layout_set_alignment( pdf->textLayout, PANGO_ALIGN_RIGHT);
pdf_pushy( pdf, pdf_draw_shortfield( pdf, pdf->w - 2*PDF_WPADDING_X, hint, -1, key, -1));
pango_layout_set_alignment( pdf->textLayout, PANGO_ALIGN_LEFT);
}
#endif
return true;
}
......
#include "common.h"
#include "textView/backend.h"
#include <widget.h>
#include <exercise.h>
#include <pdf.h>
#include "widget.h"
#include "exercise.h"
bool widget_textView_answer_show(WIDGET* wid, QUESTION* q, ANSWERSTATE* ans)
{
......@@ -18,6 +17,7 @@ bool widget_textView_answer_show(WIDGET* wid, QUESTION* q, ANSWERSTATE* ans)
bool widget_textView_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWERSTATE* ans)
{
#ifdef _QUIZGRIND_BUILD_PDF
char* src = WJEString(wid->options, KEY_TEXTVIEW_TEXT, WJE_GET, NULL);
PROCESSEDSTRING ps = exercise_processString(q, src);
......@@ -40,4 +40,7 @@ bool widget_textView_pdf(WIDGET* wid, QUESTION* q, WIDGETDRAWCTX* pdf, ANSWERSTA
pdf_pushy( pdf, pushy);
if(ps.type == PSTYPE_TEMPLATE) free(src);
return widget_textView_answer_show(wid, q, ans);
#else
return true;
#endif
}
......@@ -12,6 +12,7 @@ build:
${WEBPACK} --output-path=${BINDIR}
install:
make build
mkdir -p ${BINDIR}
mkdir -p ${INSTALLDIR}
cp -r ${SRCDIR}/media ${INSTALLDIR}
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -7,12 +7,13 @@
"build": "make build",
"install": "make install"
},
"repository": "https://gitlab.com/platypro/quizgrind",
"author": "Aeden McClain",
"license": "GPL-3.0-or-later",
"devDependencies": {
"awesome-typescript-loader": "^5.2.1",
"webpack": "^4.39.1",
"webpack-cli": "^3.3.6",
"webpack-cli": "^3.3.6"
},
"dependencies": {
"typescript": "^3.5.3"
......
var entry = require('webpack-glob-entry')
var path = require('path')
module.exports = {
mode: 'development',
mode: 'production',
entry: "./src/index.ts",
output: {
path: ".",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment