FPDFText_SetText change nothing - settext

I can change the text of an pdf text object and pdfium function says "all is ok". But when i save the changed pdf doc no changes are visible. Something is missing and i dont know what.
int co = FPDFPage_CountObjects(page);
for (int j = 0; j < co; ++j) {
FPDF_PAGEOBJECT pobj = FPDFPage_GetObject(page, j);
if (FPDFPageObj_GetType(pobj) == FPDF_PAGEOBJ_TEXT) {
...
if (FPDFText_SetText(pobj, (FPDF_WIDESTRING)L"New Text")) {
std::cout << "#VAL1 was changed\n";
//FPDFPage_GenerateContent(page);
}
}
}
...
FPDF_ClosePage(page);
...
FPDF_FILEWRITE_EX fw;
fw.pFile = fopen("C:\\work\\newpdf.pdf", "wb");
fw.version = 1;
fw.WriteBlock = MyDelegateSaveFunc;
FPDF_SaveAsCopy(doc, &fw, FPDF_NO_INCREMENTAL);
fclose(fw.pFile);
FPDF_CloseDocument(doc);
If i do call GenerateContent (not needed i think) then the whole saved page is empty. I do use the last pdfium binary version 3764.

You need to uncomment the line FPDFPage_GenerateContent(page), after changing the object you need to update the object or generate the whole page.
An empty page after FPDFPage_GenerateContent is a bug already fixed in last builds.

Related

ThinkOrSwim function equivalent in MQL

I have never heard of ThinkOrSwrim till yesterday when someone asked me to convert a ThinkOrSwim script to an MQL4 indicator.
A part of the code is as follows:
input length = 21;
input price = close;
input ATRs=1;
input trueRangeAverageType = AverageType.WILDERS;
def flag;
def EMA = ExpAverage(close, length);
def shift1 = ATRs * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
I want to ask you to kindly check and let me know if my understanding is correct.
input ATRs=1; // This should be a multiplier for ATR, then I think I should give it a double
//type for more flexible control.
input trueRangeAverageType = AverageType.WILDERS;
//As far as I understood, wilders is the same as SMMA in MQL.
.
def shift1 = ATRs * MovingAverage(trueRangeAverageType, TrueRange(high, close, low), length);
Here is the main piece of this code which I need your help with.
My understanding is as follows
ATRs ==>> Just a multiplier
I think the rest of this line is calculating the ATR, right?
If so, then I can see that I cannot simply convert this to iATR (in mql), because we are not able to choose MA Methode of ATR in mql4.
Then I think first I have to put the "True Range" of each bar in an array and then use this array as a price source to get the averages.
MQL4:
for(int i = 0; i < rates_total; i++)
{
data[i] = iATR(_Symbol, TF_1, 1, i);
}
for(int i = 0; i < limit; i++)
{
ExtBuffer[i] = iMAOnArray(data, 0, Inplenght, 0, InpMAMethod, i);
}
If I'm in the right way yet, Then I think the iATR period has to be 1, to have the TrueRange of each bar and not the average of the TrueRanges.
And then have the variable length (from thinkOrSwim inputs) as the period parameter for iMAOnArray.
I would appreciate any help with it.
Regards
Edit:
I forgot to ask you something,
why should the programmer who wrote this thinkscript code call this variable shift1?

dart: changing list[i] changes list[i-1] too

I have a List of the type Model. when I loop all its elements and loop the next one except for the last one, then change the last one manually, the one before changes.
here is a little code to reproduce the problem (also you can run it directly in dartpad from here)
void main() {
List<Model> s = [];
for (int i = 0; i < 5; i++) {
s.add(Model(i));
}
for (int i = 0; i < s.length - 1; i++) {
s[i] = s[i + 1];
}
print(s);
s[s.length-1].x = 100;
print(s);
}
class Model {
int x;
Model(this.x);
#override
String toString() => 'x: ' + this.x.toString();
}
notice that this problem does not happen when you comment out the for loop or the manual change, or instead of changing the last one's property, you reassign a new value to it, like s[s.length - 1] = Model(100);. seems like dart for some reason is re-running the loop.
When you run the second for loop, you assign the i + 1th Model to the ith position in the list:
// initialise list
for (int i = 0; i < s.length; i++) {
s[i] = s[i + 1]
}
If you unwrap the loop, it looks roughly like this:
s[0] = s[1];
s[1] = s[2];
s[2] = s[3];
s[3] = s[4];
Notice that this leaves s[4] unchanged, but also assigns it to s[3].
In Dart, variables contain references to objects. This means that when your list runs s[3] = s[4];, both s[3] and s[4] point to the same object.
Now, if you modify s[4] you, are actually modifying the objects that s[4] refers to, which happens to also be the object that s[3] refers to, so they both appear to change in your list.

DXL script producing syntax error with char c = str[i]

I'm currently trying to run Export to PDF script, however when I try running it in DOORS ver 9.6.1, I get a couple of errors.
Line 8: char c = str[i]; contains a syntax error
Any thoughts on how I can resolve this issue?
string makeCaption(Buffer& str)
{
setempty(tempBuf);
int i = 0;
{
for(i = 0; i < length(str); ++i)
char c = str[i];
if('\n' != c) && '\\' != c)
{
tempBuf += c;
}
}
escapeSpecialLaTeXCharacters(tempBuf);
return stringOf(tempBuf);
}
Seems to me like copy/paste problems. When you compare your code with the original you might notice that you moved line 6 with the sole { one line up. If you put it back where it belongs i.e. after the line "for(...)", the code works

how to Recreate boundary from array of junctions in imagej - fiji?

I am detecting and storing the boundary of a sandpile to an array and then save it as a text file for later use. the way i stored the boundary as text file is by using the wand tool, then getting the properties of the selection which gives me a table. Then converting table to array and finally storing it as text file.
after doing so i noticed that the above mentioned table only has the (X,Y) coordinates of the "junctions" on the boundary and not every pixel of the boundary.
Now when i say later use, i want to smooth out the boundary with various methods and redraw it but i am stuck at how to go from junctions to complete boundary. Below is my attempt to do it but i am seeing heavy ram usage just after the output is printed.
Thanks for any help and your time.
X=newArray(1,5,5,10);
Y=newArray(3,3,8,8);
c=newArray("c1","c2");
//answer should be g=(1,2,3,4,5,5,5,5,5,5,6,7,8,9,10, --x part
// 3,3,3,3,3,4,5,6,7,8,8,8,8,8,8) --y part
//f=slide(a,2,c);Array.print(f);
g=cmpltarray(X,Y);Array.print(g);
function cmpltarray(Tx,Ty){
for (i = 0; i < Tx.length-1; i++) {
if(Tx[i]==Tx[i+1] && Ty[i]!=Ty[i+1])
{
l=abs(Ty[i]-Ty[i+1])-1;tempy=newArray(l);tempx=newArray(l);
for (j = 0; j < l; j++) {
tempy[j]=Ty[i]+j+1;tempx[j]=Tx[i];
}
Tx=slide(Tx,(i+1),tempx);Ty=slide(Ty,(i+1),tempy);i=i+l;
}
if(Ty[i]==Ty[i+1] && Tx[i]!=Tx[i+1])
{
l=abs(Tx[i]-Tx[i+1])-1;tempy=newArray(l);tempx=newArray(l);
for (j = 0; j < l; j++) {
tempx[j]=Tx[i]+j+1;tempy[j]=Ty[i];
}
Tx=slide(Tx,(i+1),tempx);Ty=slide(Ty,(i+1),tempy);i=i+l;
}
}
return Array.concat(Tx,Ty);
}
function slide(array,n,data){
array=Array.concat(Array.slice(array,0,n),data,Array.slice(array,n,array.length));
return array;
}

Google script, manipulate the number value

I have one script behind one spreedsheet and I'm trying to export some cell values to document, and than email the pdv version of temp document..(trash it latter). I have problem with value I get or in the way I'm getting the value from spreedsheet to doc.. I can't manipulate the decimal point..
// fix the price currency display and alignment in GOOGLE DOCUMENT TABLE!
for (var i = 0; i < price.getNumRows(); i++){
for (var j = 0; j < price.getRow(i).getNumCells(); j++){
var temp = price.getCell(i, j);
temp.getChild(0).asParagraph().setSpacingAfter(0);
if((j == 6 || j == 7) && !temp.getText() == "" ) {
(i > 0) ? temp.replaceText(temp.getText(), temp.getText() + " kn") : void false; // skip the first line with header titles...
temp.getChild(0).asParagraph().setAlignment(DocumentApp.HorizontalAlignment.RIGHT);
}
}
}
after (i > 0) there is temp.getText() value.. that sometimes is like: 55,987654 and I would like that to round to two digits.. but can't :(
Thanks for help!
I have found solution..
it's very simple but did take me some time.. hope that can help someone else with similar situation
parseFloat(temp.getText()).toFixed(2) + " kn")
this did the trick and the output is something like: 55,99 kn!

Resources