diff --git a/uppdev/ReportWithChineseCharacter/ReportWithChineseCharacter.upp b/uppdev/ReportWithChineseCharacter/ReportWithChineseCharacter.upp new file mode 100644 index 000000000..58c4317aa --- /dev/null +++ b/uppdev/ReportWithChineseCharacter/ReportWithChineseCharacter.upp @@ -0,0 +1,13 @@ +description "Report example\377"; + +uses + CtrlLib, + Report, + PdfDraw; + +file + main.cpp charset "UTF-8"; + +mainconfig + "" = "GUI"; + diff --git a/uppdev/ReportWithChineseCharacter/init b/uppdev/ReportWithChineseCharacter/init new file mode 100644 index 000000000..e42896dd7 --- /dev/null +++ b/uppdev/ReportWithChineseCharacter/init @@ -0,0 +1,6 @@ +#ifndef _ReportWithChineseCharacter_icpp_init_stub +#define _ReportWithChineseCharacter_icpp_init_stub +#include "CtrlLib/init" +#include "Report/init" +#include "PdfDraw/init" +#endif diff --git a/uppdev/ReportWithChineseCharacter/main.cpp b/uppdev/ReportWithChineseCharacter/main.cpp new file mode 100644 index 000000000..8d0e6a1e8 --- /dev/null +++ b/uppdev/ReportWithChineseCharacter/main.cpp @@ -0,0 +1,29 @@ +#include + +using namespace Upp; + +GUI_APP_MAIN +{ + Report r; + r.Header("[A2> Page $$P"); + r << "This is some [* QTF text"; + r << t_("顯示[* QTF 文字"); + r << "&&Let's report some table:"; + r << t_("輸出表格式報表:"); + String tab; + tab << "{{1:1:1:1:1:1:2 A:: B:: C:: D:: E:: F:: G (wider)"; + for(int row = 0; row < 20; row++) + for(int column = 0; column < 7; column++) + tab << ":: " << row << ":" << column << t_("測試"); + r << tab; + + r.NewPage(); + int y = r.GetY(); + r.DrawEllipse(300, y + 50, 3000, 2000, LtRed, 20); + r.DrawText(500, y + 50 + 950, "Some free drawing in this page!", Arial(100)); + r.DrawText(500, y + 50 + 1100, t_("在這頁隨便畫一些東西!"), Arial(100)); + r.SetY(y + 50 + 3000); + r << "More of [/ QTF] [C6* text"; + + Perform(r); +} diff --git a/uppdev/Reports/main.cpp b/uppdev/Reports/main.cpp index fa6fab4d4..49e681316 100644 --- a/uppdev/Reports/main.cpp +++ b/uppdev/Reports/main.cpp @@ -1,25 +1,34 @@ #include +using namespace Upp; + +struct TableRowTracer : RichTextLayoutTracer { + VectorMap pgr; + + virtual void TableRow(const Rect& page, PageY y, int, const RichTable&) { + pgr.GetAdd(y.page, 0)++; + } +}; + GUI_APP_MAIN { Report r; - r.Header("[A2> Page $$P"); - r << "This is some [* QTF text"; - r << "&&Let's report some table:"; - String tab; - tab << "{{1:1:1:1:1:1:2 A:: B:: C:: D:: E:: F:: G (wider)"; - for(int row = 0; row < 20; row++) - for(int column = 0; column < 7; column++) - tab << ":: " << row << ":" << column; - r << tab; - r.NewPage(); - int y = r.GetY(); - r.DrawEllipse(300, y + 50, 3000, 2000, LtRed, 20); - r.DrawText(500, y + 50 + 950, "Some free drawing in this page!", Arial(100)); - Vector poly; - poly << Point(200,200) << Point(700,200) << Point(700,500) << Point(200,500) << Point(200,200); - r.DrawPolygon(poly, Cyan, 2, Red, 0, Null); - r.SetY(y + 50 + 3000); - r << "More of [/ QTF] [C6* text"; - Perform(r); + r.Footer("[R1 "); + TableRowTracer t; + r.SetRichTextLayoutTracer(t); + String qtf = "&[R This is a demonstration of [* RichTextLayoutTracer]&&&{{1 Table"; + for(int i = 0; i < 100; i++) + qtf << ":: " << i; + qtf << "}}"; + r.Put(qtf); + + Report rr; + for(int i = 0; i < r.GetCount(); i++) { + if(i) + rr.NewPage(); + rr.Footer("[R1 There is " + AsString(t.pgr.Get(i, 0)) + " table rows on this page"); + rr.DrawDrawing(r.GetPageSize(), r[i]); + } + + Perform(rr); } diff --git a/uppdev/pthread_tls/init b/uppdev/pthread_tls/init new file mode 100644 index 000000000..2c8a7ead1 --- /dev/null +++ b/uppdev/pthread_tls/init @@ -0,0 +1,4 @@ +#ifndef _pthread_tls_icpp_init_stub +#define _pthread_tls_icpp_init_stub +#include "Core/init" +#endif diff --git a/uppdev/pthread_tls/pthread_tls.cpp b/uppdev/pthread_tls/pthread_tls.cpp new file mode 100644 index 000000000..1a5ae959b --- /dev/null +++ b/uppdev/pthread_tls/pthread_tls.cpp @@ -0,0 +1,96 @@ +#include +#include +#include +#include + +//#include + +#ifndef TLS_PRE_ALLOC +#define TLS_PRE_ALLOC false +#endif + +#ifndef NUM_THREADS +#define NUM_THREADS 10 +#endif + +#ifndef NUM_TESTS +#define NUM_TESTS 1<<28 +#endif + +pthread_key_t p_key; + +struct tls_ { + int id; + long check; +}; + +#if TLS_PRE_ALLOC +static tls_ tls[NUM_THREADS]; +#endif + +bool update_tls() { + tls_ *tmp = (tls_*)pthread_getspecific(p_key); + volatile long chk = tmp->check; + tmp->check += 1; + if (chk+1 == tmp->check) + return true; + else + return false; +} + +void* work(void* p_tls) { + pthread_setspecific(p_key, p_tls); + printf("Starting thread id: %d, v: %d\n", ((tls_*)pthread_getspecific(p_key))->id, ((tls_*)pthread_getspecific(p_key))->check); + int test_nr = 0; + do { + if (!update_tls()) + return NULL; + } while (NUM_TESTS < 0 || ++test_nr < NUM_TESTS); + tls_ *tmp = (tls_*)pthread_getspecific(p_key); + printf("Leaving thread %d value %d ...\n", tmp->id, tmp->check); +#if !TLS_PRE_ALLOC + free(tmp); + pthread_setspecific(p_key, NULL); +#endif + return (void*)-1; +} + +int main(int argc, const char *argv[]) +{ + clock_t clk = clock(); + pthread_key_create(&p_key, NULL); + pthread_t threads[NUM_THREADS]; + long ret; + void* ret_ptr = &ret; + int thread_id = 0; + while (thread_id < NUM_THREADS) { +#if TLS_PRE_ALLOC + printf("Thread specific data is pre allocated ...\n", thread_id); + tls[thread_id].id = thread_id; + tls[thread_id].check = thread_id; + if (pthread_create(&threads[thread_id], NULL, work, &tls[thread_id]) != 0) { + printf("Cannot create thread %d\n", thread_id); + break; + } +#else + printf("Allocating thread specific data for thread %d ...\n", thread_id); + tls_ *tls = new tls_; + tls->id = thread_id; + tls->check = thread_id; + if (pthread_create(&threads[thread_id], NULL, work, tls) != 0) { + printf("Cannot create thread %d\n", thread_id); + break; + } +#endif + thread_id++; + } + for (int i=0; i < thread_id; i++) { + pthread_join(threads[i], &ret_ptr); + if (!ret_ptr) + printf("thread %d TSS update has errors !!!\n", i); + } + pthread_key_delete(p_key); + printf("CPU time: %f\n", (float)(clock()-clk)/CLOCKS_PER_SEC); + return 0; +} + diff --git a/uppdev/pthread_tls/pthread_tls.upp b/uppdev/pthread_tls/pthread_tls.upp new file mode 100644 index 000000000..8801b70ca --- /dev/null +++ b/uppdev/pthread_tls/pthread_tls.upp @@ -0,0 +1,14 @@ +description "pthread thread local storage test\377"; + +uses + Core; + +library + pthread; + +file + pthread_tls.cpp; + +mainconfig + "" = ""; +